From cc50f438a3754a266b87eec820cbf0ebd9ef08e8 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Mon, 11 Oct 2021 21:51:40 -0500 Subject: [PATCH] Initial guix packaging With a bootstrap package that can be used to link the two dependencies and rld itself. --- guix.scm | 162 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 guix.scm diff --git a/guix.scm b/guix.scm new file mode 100644 index 0000000..862bc4a --- /dev/null +++ b/guix.scm @@ -0,0 +1,162 @@ +(use-modules + ((guix licenses) #:prefix license:) + (guix packages) + (guix download) + (guix git-download) + (guix build-system ruby) + (guix build-system trivial) + (guix utils) + (gnu packages bash) + (gnu packages ruby) + (ice-9 rdelim) + (ice-9 popen)) + +(define ruby-ast-2.4.2-bootstrap + (package + (inherit ruby-ast) + (version "2.4.2") + (source + (origin + (method url-fetch) + (uri (rubygems-uri "ast" version)) + (sha256 + (base32 "04nc8x27hlzlrr5c2gn7mar4vdr0apw5xg22wp6m8dx3wqr04a0y")))) + (arguments + `(#:tests? #f)))) + +(define ruby-ast-2.4.2 + (package + (inherit ruby-ast-2.4.2-bootstrap) + (arguments + `(#:tests? #f + ,@(substitute-keyword-arguments (package-arguments ruby-ast) + ((#:phases phases) + `(modify-phases ,phases + (add-after 'unpack 'rld + (lambda _ + (apply invoke "rld" "-ip." (find-files "." "\\.(rb|ru)$")))) + (delete 'remove-coveralls-requirement) + (delete 'remove-unnecessary-requirements)))))) + (native-inputs + `(("rld" ,rld-bootstrap) + ,@(package-native-inputs ruby-ast))))) + +(define ruby-parser-with-rld + ((package-input-rewriting `((,ruby-ast . ,ruby-ast-2.4.2))) + (package + (inherit ruby-parser) + (arguments + `(#:tests? #f + #:phases + (modify-phases %standard-phases + (add-after 'unpack 'rld + (lambda* (#:key inputs #:allow-other-keys) + (apply invoke ; We can't use the wrapped bootstrap rld or it sets a GEM_PATH for a different ast gem + (string-append (assoc-ref inputs "ruby2.7") "/bin/ruby") "-Ilib" + (string-append (assoc-ref inputs "rld") "/bin/.rld-real") "-ip." + ; gauntlet_parser can only be used if gauntlet is present, but we + ; don't want to require it, so do not link to it + (delete "./lib/gauntlet_parser.rb" (find-files "." "\\.(rb|ru)$")))))))) + (native-inputs + `(("rld" ,rld-bootstrap) + ("ruby2.7" ,ruby-2.7) + ,@(package-native-inputs ruby-parser)))))) + +;;;; + +(define %source-dir (dirname (current-filename))) +(define %git-dir (string-append %source-dir "/.git")) +(define %module (current-module)) + +; Bake a template by eval'ing the leaves +(define (bake tmpl) + (cons + (car tmpl) + (map + (lambda (x) (list (car x) (eval (cadr x) %module))) + (cdr tmpl)))) + +(define rld-template + '(package + (name "rld") + (version (read-line (open-pipe* OPEN_READ "git" "--git-dir" %git-dir "describe" "--always" "--dirty"))) + (source + `(origin + (method git-fetch) + (uri (git-reference + (recursive? #t) + (url "https://git.singpolyma.net/rld") + (commit ,(read-line (open-pipe* OPEN_READ "git" "--git-dir" %git-dir "rev-parse" "HEAD"))))) + (file-name (git-file-name name version)) + (sha256 + (base32 + ,(read-line (open-pipe* OPEN_READ "guix" "hash" "-rx" %source-dir)))))) + (build-system 'trivial-build-system) + (arguments + '`(#:modules ((guix build utils)) + #:builder + (let* ((bindir (string-append (assoc-ref %outputs "out") "/bin")) + (outbin (string-append bindir "/rld"))) + (use-modules (guix build utils)) + (mkdir-p bindir) + (set-path-environment-variable "PATH" '("bin") + (list + (assoc-ref %build-inputs "ruby")) + #:separator ":") + (set-path-environment-variable "GEM_PATH" '("lib/ruby/vendor_ruby") + (list + (assoc-ref %build-inputs "ruby-parser") + (assoc-ref %build-inputs "ruby-ast")) + #:separator ":") + (chdir (assoc-ref %build-inputs "source")) + (invoke "ruby" "bin/rld" "-p." "-o" outbin "bin/rld") + (patch-shebang outbin) + (chmod outbin #o755)))) + (inputs + '`(("ruby" ,ruby-2.7) + ("ruby-parser" ,ruby-parser-with-rld))) + (synopsis "Linker for Ruby") + (description "") + (home-page "https://git.singpolyma.net/rld") + (license 'license:agpl3))) + +(define rld-bootstrap + (package + (inherit (eval (bake rld-template) %module)) + (version "bootstrap-be3900") + (source + (origin + (method git-fetch) + (uri (git-reference + (recursive? #t) + (url "https://git.singpolyma.net/rld") + (commit "be390053302623e569164b2eaf5297fabd0bcd47"))) + (file-name (git-file-name "rld" "be3900")) + (sha256 + (base32 "06878bywadm57l5w2sni40gmrwv87d2i4fj5c2axp0vsqvsz3q38")))) + (inputs + `(("bash" ,bash-minimal) + ("ruby" ,ruby-2.7) + ("ruby-parser" ,((package-input-rewriting `((,ruby-ast . ,ruby-ast-2.4.2-bootstrap))) ruby-parser)))) + (arguments + '(#:modules ((guix build utils)) + #:builder + (let* ((bindir (string-append (assoc-ref %outputs "out") "/bin")) + (outbin (string-append bindir "/rld"))) + (use-modules (guix build utils)) + (set-path-environment-variable "PATH" '("bin") + (list + (assoc-ref %build-inputs "ruby") + (assoc-ref %build-inputs "bash")) + #:separator ":") + (set-path-environment-variable "GEM_PATH" '("lib/ruby/vendor_ruby") + (list + (assoc-ref %build-inputs "ruby-parser") + (assoc-ref %build-inputs "ruby-ast")) + #:separator ":") + (chdir (assoc-ref %build-inputs "source")) + (install-file "bin/rld" bindir) + (patch-shebang outbin) + (wrap-program outbin `("GEM_PATH" ":" prefix (,(getenv "GEM_PATH"))))))))) + +(eval (bake rld-template) %module) -- 2.34.2