~singpolyma/rld

rld/guix.scm -rw-r--r-- 6.1 KiB
cc50f438Stephen Paul Weber Initial guix packaging 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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)