scripts/build-system/rebuild.rkt

90 lines
3.3 KiB
Racket
Executable File

#!/usr/bin/env racket
#lang racket/base
(require "rebuild-pkgs.rkt")
(require racket/cmdline)
(require racket/format)
(require racket/system)
(require racket/port)
(define cwd current-directory)
(define (sys cmd)
(eprintf "(~v) ~v\n" (cwd) cmd)
(unless (system cmd)
(eprintf "error in rebuild, aborting\n")
(exit 1)))
(define (default-pkg-url pkg) (~a "https://aur.archlinux.org/" pkg ".git"))
(define (str-or-empty hash key str) (if (hash-ref hash key #f) str ""))
(define (higan-make args)
(sys (~a "make -j12 -C " args " uninstall"))
(sys (~a "make -j12 -C " args " clean"))
(sys (~a "make -j12 -C " args " all"))
(sys (~a "make -j12 -C " args " install")))
(define (get-latest-tag)
(define latest
(with-output-to-string (λ () (sys "git rev-list --tags --max-count=1"))))
(with-output-to-string (λ () (sys (~a "git describe --tags " latest)))))
(define (build-pkg pkg opts)
(parameterize ([cwd (string->path (getenv "_agw_dir_bin"))])
(let ([makepkg-args (~a "-isrLcCf --noconfirm"
(str-or-empty opts 'asdeps " --asdeps")
(str-or-empty opts 'force " -f")
(str-or-empty opts 'skipinteg " --skipinteg"))]
[clone-url (hash-ref opts 'url (default-pkg-url pkg))]
[special-handling (hash-ref opts 'handle 'none)]
[branch (hash-ref opts 'branch "master")]
[pkg-dir (build-path (cwd) (symbol->string pkg))])
(unless (directory-exists? pkg-dir)
(sys (~a "git clone -b " branch " " clone-url)))
(parameterize ([cwd pkg-dir])
(sys "git pull")
(case special-handling
['none
(sys (~a "makepkg " makepkg-args))]
['higan-shaders
(let ([loc "~/.local/share/higan"])
(sys (~a "mkdir -p " loc "/shaders"))
(sys (~a "cp -r ./* " loc "/shaders"))
; they forgot to change the directory!
(sys (~a "cp -r " loc "/Video\\ Shaders/* " loc "/shaders")))]
['higan
(sys "git fetch --tags")
(sys (~a "git checkout " (get-latest-tag)))
(higan-make "higan target=higan")
(higan-make "icarus")
(sys "make -j12 -C shaders install")]
[else (raise-argument-error 'build-pkg
"(or/c 'none 'higan 'higan-shaders)"
special-handling)])))))
(define (resume-from-pkg input-pkg [pkg-list all-packages])
(let ([package (car pkg-list)])
(if (equal? package input-pkg)
pkg-list
(resume-from-pkg input-pkg (cdr pkg-list)))))
(let* ([resume-from (make-parameter '())]
[cmdline-pkgs (command-line
#:once-each
["--resume-from" pkg
"Resume compiling from a package."
(resume-from pkg)]
#:args pkgs (map string->symbol pkgs))]
[pkgs (if (null? cmdline-pkgs)
(let ([input-package (resume-from)])
(if (null? input-package)
all-packages
(resume-from-pkg (string->symbol input-package))))
cmdline-pkgs)])
(for ([package pkgs])
(build-pkg package (hash-ref package-options package (hash)))))
;; EOF