#!/usr/bin/env racket #lang racket/base (require racket/cmdline) (require racket/file) (require racket/format) (require racket/list) (require racket/port) (require racket/system) (require "rebuild-pkginfo.rkt") (define-values (dependency-packages normal-packages) (let ([all (file->lines (build-path (getenv "_agw_dir_local") "rebuild-pkgs") #:mode 'text)]) (split-at all (index-of all "")))) (define all-packages (append dependency-packages (cdr normal-packages))) (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 (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) 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))] [else (raise-argument-error 'build-pkg "(or/c 'none)" special-handling)]))))) (define (resume-from-pkg input-pkg pkg-list) (let ([package (car pkg-list)]) (if (equal? package input-pkg) pkg-list (resume-from-pkg input-pkg (cdr pkg-list))))) (define (get-package-options package) (let ([temp-hash (hash-ref package-options package (hash))]) (if (member package dependency-packages) (hash-set temp-hash 'asdeps #t) temp-hash))) (let* ([resume-from (make-parameter '())] [cmdline-pkgs (command-line #:once-each ["--resume-from" pkg "Resume compiling from a package." (resume-from pkg)] #:args pkgs pkgs)] [pkgs (if (null? cmdline-pkgs) (let ([input-package (resume-from)]) (if (null? input-package) all-packages (resume-from-pkg input-package all-packages))) cmdline-pkgs)]) (for ([package pkgs]) (build-pkg package (get-package-options package)))) ;; EOF