scala.scm
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu> |
3 | ;;; |
4 | ;;; This file is part of GNU Guix. |
5 | ;;; |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
7 | ;;; under the terms of the GNU General Public License as published by |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at |
9 | ;;; your option) any later version. |
10 | ;;; |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | ;;; GNU General Public License for more details. |
15 | ;;; |
16 | ;;; You should have received a copy of the GNU General Public License |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
18 | |
19 | (define-module (more packages scala) |
20 | #:use-module ((guix licenses) #:prefix license:) |
21 | #:use-module (gnu packages) |
22 | #:use-module (guix packages) |
23 | #:use-module (guix download) |
24 | #:use-module (guix git-download) |
25 | #:use-module (guix utils) |
26 | #:use-module (guix build-system ant) |
27 | #:use-module (guix build-system copy) |
28 | #:use-module (guix build-system gnu) |
29 | #:use-module (gnu packages base) |
30 | #:use-module (gnu packages bash) |
31 | #:use-module (gnu packages compression) |
32 | #:use-module (gnu packages java) |
33 | #:use-module (gnu packages protobuf) |
34 | #:use-module (gnu packages web) |
35 | #:use-module (more packages java)) |
36 | |
37 | ;; This package downloads the so-called official version of scala, a pre-built |
38 | ;; binary by the scala developers. |
39 | ;; This binary should never be made part of Guix itself, because we have |
40 | ;; ways to bootstrap it properly. The bootstrap project of scala takes time, |
41 | ;; so in the meantime... here you are :( |
42 | |
43 | (define %binary-scala |
44 | (package |
45 | (name "scala") |
46 | (version "2.13.6") |
47 | (source (origin |
48 | (method url-fetch) |
49 | (uri (string-append "https://downloads.lightbend.com/scala/" |
50 | version "/scala-" version ".tgz")) |
51 | (sha256 |
52 | (base32 |
53 | "0hzd6pljc8z5fwins5a05rwpx2w7wmlb6gb8973c676i7i895ps9")))) |
54 | (build-system copy-build-system) |
55 | (arguments |
56 | `(#:install-plan |
57 | '(("." "")) |
58 | #:phases |
59 | (modify-phases %standard-phases |
60 | (add-before 'install 'set-java-home |
61 | (lambda* (#:key inputs #:allow-other-keys) |
62 | (substitute* (find-files "bin" ".") |
63 | (("^#!.*" shebang) |
64 | (string-append shebang "\nJAVA_HOME=" |
65 | (assoc-ref inputs "openjdk")))))) |
66 | (add-before 'set-java-home 'remove-unneeded |
67 | (lambda _ |
68 | (for-each delete-file (find-files "bin" "bat$"))))))) |
69 | (inputs |
70 | `(("openjdk" ,openjdk14))) |
71 | (home-page "https://scala-lang.org/") |
72 | (synopsis "Scala programming language") |
73 | (description "Scala combines object-oriented and functional programming in |
74 | one concise, high-level language. Scala's static types help avoid bugs in |
75 | complex applications, and its JVM and JavaScript runtimes let you build |
76 | high-performance systems with easy access to huge ecosystems of libraries.") |
77 | (license license:bsd-3))) |
78 | |
79 | (define scala-asm |
80 | (package |
81 | (inherit java-asm) |
82 | (version "9.1.0") |
83 | (source (origin |
84 | (method git-fetch) |
85 | (uri (git-reference |
86 | (url "https://github.com/scala/scala-asm") |
87 | (commit "s-9.1"))) |
88 | (file-name (git-file-name "scala-asm" version)) |
89 | (sha256 |
90 | (base32 |
91 | "1wsrlb6kb0fwxjdqanxqgmq4qcyq9gqn129w3l4bj7gvlspll33l")))) |
92 | (arguments |
93 | `(#:jar-name "java-asm.jar" |
94 | #:source-dir "src/main/java" |
95 | ;; no tests |
96 | #:tests? #f)))) |
97 | |
98 | (define-public scala |
99 | (package |
100 | (inherit %binary-scala) |
101 | (source (origin |
102 | (method git-fetch) |
103 | (uri (git-reference |
104 | (url "https://github.com/scala/scala") |
105 | (commit (string-append "v" (package-version %binary-scala))))) |
106 | (file-name (git-file-name "scala" (package-version %binary-scala))) |
107 | (sha256 |
108 | (base32 |
109 | "1gl156n6nd4xnq3cb6f1bbfbb9s4cp6bd9xczl99plpx6jwnpmhl")))) |
110 | (build-system ant-build-system) |
111 | (arguments |
112 | `(#:tests? #f |
113 | #:phases |
114 | (modify-phases %standard-phases |
115 | (replace 'build |
116 | (lambda* (#:key inputs #:allow-other-keys) |
117 | (define* (build-project directory jar-name name #:optional (jar? #t)) |
118 | (let* ((build-dir (string-append "build/class/" name)) |
119 | (java-files (find-files directory ".*.java$")) |
120 | (scala-files (find-files directory ".*.scala$"))) |
121 | (mkdir-p build-dir) |
122 | (format #t "Building project ~a...~%" name) |
123 | (with-output-to-file (string-append build-dir "/" name ".properties") |
124 | (lambda _ |
125 | (format #t "version.number=~a~%" ,(package-version this-package)) |
126 | (format #t "maven.version.number=~a~%" ,(package-version this-package)))) |
127 | (unless (eq? scala-files '()) |
128 | (apply invoke "scalac" "-classpath" |
129 | (string-append |
130 | ;; Add any top-level directory in build that may contain |
131 | ;; .class files, but don't actually add build/ iteself or |
132 | ;; any individual class file. |
133 | (string-join |
134 | (filter (lambda (s) (eq? (string-count s #\/) 2)) |
135 | (find-files "build/class" "." #:directories? #t)) |
136 | ":")) |
137 | "-d" build-dir "-nobootcp" |
138 | (append scala-files java-files))) |
139 | (unless (eq? java-files '()) |
140 | (apply invoke "javac" "-classpath" |
141 | (string-append |
142 | (getenv "CLASSPATH") ":" |
143 | (string-join |
144 | (filter (lambda (s) (eq? (string-count s #\/) 2)) |
145 | (find-files "build/class" "." #:directories? #t)) |
146 | ":")) |
147 | "-g" "-source" "1.8" "-target" "1.8" |
148 | "-d" build-dir java-files)) |
149 | (mkdir-p "build/jar") |
150 | (when jar? |
151 | (invoke "jar" "cf" (string-append "build/jar/" jar-name) |
152 | "-C" build-dir ".")))) |
153 | |
154 | (let ((scala-asm (assoc-ref inputs "scala-asm"))) |
155 | (setenv "CLASSPATH" (string-join (find-files scala-asm ".*.jar$") ":"))) |
156 | (setenv "JAVA_OPTS" "-Xmx1G") |
157 | (build-project "src/library" "scala-library.jar" "library") |
158 | (build-project "src/reflect" "scala-reflect.jar" "reflect") |
159 | (build-project "src/compiler" "scala-compiler.jar" "compiler" #f) |
160 | (build-project "src/interactive" "scala-compiler-interactive.jar" "interactive" #f) |
161 | (build-project "src/scaladoc" "scala-compiler-doc.jar" "scaladoc" #f) |
162 | (build-project "src/repl" "scala-repl.jar" "repl" #f) |
163 | (build-project "src/repl-frontend" "scala-repl-frontend.jar" "replFrontend" #f) |
164 | (build-project "src/scalap" "scalap.jar" "scalap") |
165 | |
166 | ;; create scala-compiler.jar as a union of some of those above |
167 | (mkdir-p "build/class/scala-compiler") |
168 | (with-directory-excursion "build/class/scala-compiler" |
169 | (let ((scala-asm (assoc-ref inputs "scala-asm"))) |
170 | (invoke "jar" "xf" (car (find-files scala-asm ".*.jar$")))) |
171 | (copy-recursively "../compiler" ".") |
172 | (copy-recursively "../interactive" ".") |
173 | (copy-recursively "../scaladoc" ".") |
174 | (copy-recursively "../repl" ".") |
175 | (copy-recursively "../replFrontend" ".")) |
176 | (invoke "jar" "cf" "build/jar/scala-compiler.jar" |
177 | "-C" "build/class/scala-compiler" "."))) |
178 | (replace 'install |
179 | (lambda* (#:key inputs outputs #:allow-other-keys) |
180 | (let* ((out (assoc-ref outputs "out")) |
181 | (lib (string-append out "/lib")) |
182 | (jna (assoc-ref inputs "java-native-access")) |
183 | (jline-terminal (assoc-ref inputs "java-jline3-terminal")) |
184 | (jline-reader (assoc-ref inputs "java-jline3-reader"))) |
185 | (mkdir-p lib) |
186 | (for-each |
187 | (lambda (jar) |
188 | (copy-file jar (string-append lib "/" (basename jar)))) |
189 | (find-files "build/jar" ".*.jar$")) |
190 | (symlink (car (find-files jna "linux-.*.jar$")) |
191 | (string-append lib "/jna-lib.jar")) |
192 | (symlink (car (find-files jna "jna.jar$")) |
193 | (string-append lib "/jna.jar")) |
194 | (symlink (car (find-files jline-reader ".*.jar$")) |
195 | (string-append lib "/jline-reader.jar")) |
196 | (symlink (car (find-files jline-terminal ".*.jar$")) |
197 | (string-append lib "/jline-terminal.jar"))))) |
198 | (add-after 'install 'install-bin |
199 | (lambda* (#:key outputs #:allow-other-keys) |
200 | (let* ((out (assoc-ref outputs "out")) |
201 | (bin (string-append out "/bin"))) |
202 | (define (install-script script class) |
203 | (let ((script (string-append bin "/" script))) |
204 | (copy-file "src/compiler/templates/tool-unix.tmpl" script) |
205 | ;; See project/ScalaTool and build.sbt |
206 | (substitute* script |
207 | (("@@") "@") |
208 | (("@class@") class) |
209 | (("@properties@") "-Dscala.home=\"$SCALA_HOME\"") |
210 | (("@javaflags@") "-Xmx256M -Xms32M") |
211 | (("@toolflags@") "") |
212 | (("@classpath@") "")) |
213 | (chmod script #o755))) |
214 | (mkdir-p bin) |
215 | (install-script "scala" "scala.tools.nsc.MainGenericRunner") |
216 | (install-script "scalac" "scala.tools.nsc.Main") |
217 | (install-script "fsc" "scala.tools.nsc.fsc.CompileClient") |
218 | (install-script "scaladoc" "scala.tools.nsc.ScalaDoc") |
219 | (install-script "scalap" "scala.tools.scalap.Main"))))))) |
220 | (inputs |
221 | `(("scala" ,%binary-scala) |
222 | ("scala-asm" ,scala-asm) |
223 | ("java-jline3-terminal" ,java-jline3-terminal) |
224 | ("java-jline3-reader" ,java-jline3-reader) |
225 | ("java-native-access" ,java-native-access))))) |
226 | |
227 | (define-public sbt-ivy |
228 | (package |
229 | (inherit java-apache-ivy) |
230 | (name "sbt-ivy") |
231 | (version "2.4.0-rc1") |
232 | (source (origin |
233 | (method git-fetch) |
234 | (uri (git-reference |
235 | (url "https://github.com/sbt/ivy") |
236 | (commit version))) |
237 | (file-name (git-file-name name version)) |
238 | (sha256 |
239 | (base32 |
240 | "1i13iqq8r4lqkxhg9gc192874hs3wyxykyg64m98vydf5zddb5zd")) |
241 | (modules '((guix build utils))) |
242 | (snippet |
243 | ; these jars are not build products, but they interfere with the |
244 | ; ant-build-system, and we don't run the tests anyway. |
245 | `(delete-file-recursively "test")) |
246 | (patches |
247 | (search-patches "sbt-ivy-fix-bouncycastle-api.patch")))) |
248 | (arguments |
249 | (substitute-keyword-arguments (package-arguments java-apache-ivy) |
250 | ((#:phases phases) |
251 | `(modify-phases ,phases |
252 | (add-after 'unpack 'make-writable |
253 | (lambda _ |
254 | (for-each make-file-writable (find-files ".")) |
255 | #t)))))))) |
256 | |
257 | (define %default-java-locations |
258 | '("shared/src/main/java" "jvm/src/main/java" "src/main/java")) |
259 | |
260 | (define %default-scala-locations |
261 | '("shared/src/main/scala" "jvm/src/main/scala" "src/main/scala")) |
262 | |
263 | (define %default-resources-locations |
264 | '("shared/src/main/resources" "jvm/src/main/resources" "src/main/resources")) |
265 | |
266 | ;; TODO: put it in guix/build/java-utils.scm |
267 | (define* (build-scala-phase spec |
268 | #:key (scala-arguments '()) |
269 | (java-locations %default-java-locations) |
270 | (scala-locations %default-scala-locations) |
271 | (resources-locations %default-resources-locations)) |
272 | `(lambda* (#:key inputs #:allow-other-keys) |
273 | (define (get-files directory expr) |
274 | (if (file-exists? directory) |
275 | (find-files directory expr) |
276 | '())) |
277 | |
278 | (define (build-scala directory name) |
279 | (let* ((build-directory (string-append (getcwd) "/build")) |
280 | (current-build-directory (string-append build-directory "/" name)) |
281 | (jar-name (string-append name ".jar")) |
282 | (manifest (string-append current-build-directory "/META-INF/MANIFEST.MF")) |
283 | (classpath |
284 | ;; Add any top-level directory in build that may contain |
285 | ;; .class files, but don't actually add build/ iteself or |
286 | ;; any individual class file. |
287 | (string-join |
288 | (map |
289 | (lambda (s) (string-append (getcwd) "/" s)) |
290 | (filter |
291 | (lambda (s) (eq? (string-count s #\/) 1)) |
292 | (find-files "build" "." #:directories? #t))) |
293 | ":"))) |
294 | (mkdir-p current-build-directory) |
295 | (with-directory-excursion directory |
296 | (let ((java-files |
297 | (apply append |
298 | (map (lambda (loc) (get-files loc "\\.java$")) |
299 | ',java-locations))) |
300 | (scala-files |
301 | (apply append |
302 | (map (lambda (loc) (get-files loc "\\.scala$")) |
303 | ',scala-locations)))) |
304 | (format #t "Building project ~a...~%" jar-name) |
305 | (unless (eq? scala-files '()) |
306 | (apply invoke "scalac" "-classpath" |
307 | (string-append |
308 | (getenv "CLASSPATH") ":" |
309 | classpath) |
310 | "-d" current-build-directory ,@scala-arguments |
311 | (append scala-files java-files))) |
312 | (unless (eq? java-files '()) |
313 | (apply invoke "javac" "-classpath" |
314 | (string-append |
315 | (getenv "CLASSPATH") ":" |
316 | classpath) |
317 | "-d" current-build-directory java-files))) |
318 | (for-each |
319 | (lambda (dir) |
320 | (when (file-exists? dir) |
321 | (copy-recursively dir current-build-directory))) |
322 | ',resources-locations)) |
323 | (if (file-exists? manifest) |
324 | (invoke "jar" "cfm" (string-append "build/jar/" jar-name) |
325 | manifest "-C" current-build-directory ".") |
326 | (invoke "jar" "cf" (string-append "build/jar/" jar-name) |
327 | "-C" current-build-directory ".")))) |
328 | |
329 | (mkdir-p "build/jar") |
330 | (for-each |
331 | (lambda (s) |
332 | (apply build-scala s)) |
333 | ',spec))) |
334 | |
335 | (define-public scala-data-class |
336 | (package |
337 | (name "scala-data-class") |
338 | (version "0.2.5") |
339 | (source (origin |
340 | (method git-fetch) |
341 | (uri (git-reference |
342 | (url "https://github.com/alexarchambault/data-class") |
343 | (commit (string-append "v" version)))) |
344 | (file-name (git-file-name name version)) |
345 | (sha256 |
346 | (base32 |
347 | "10csh0gc0snd8xpxmx8pad1rgci1i8xjhbfcx02njiy2vh4x5lh3")))) |
348 | (build-system ant-build-system) |
349 | (arguments |
350 | `(#:tests? #f |
351 | #:phases |
352 | (modify-phases %standard-phases |
353 | (replace 'build |
354 | ,(build-scala-phase '(("." "data-class")) |
355 | #:scala-arguments '("-Ymacro-annotations"))) |
356 | (replace 'install |
357 | (install-jars "build"))))) |
358 | (native-inputs |
359 | `(("scala" ,scala))) |
360 | (home-page "") |
361 | (synopsis "") |
362 | (description "") |
363 | (license license:asl2.0))) |
364 | |
365 | (define-public scala-xml |
366 | (package |
367 | (name "scala-xml") |
368 | (version "2.0.0") |
369 | (source (origin |
370 | (method git-fetch) |
371 | (uri (git-reference |
372 | (url "https://github.com/scala/scala-xml") |
373 | (commit (string-append "v" version)))) |
374 | (file-name (git-file-name name version)) |
375 | (sha256 |
376 | (base32 |
377 | "16nw209dwj82mn0jc3ax77jmg0jqvvbc8wdwc7kaq3102k1wdv73")))) |
378 | (build-system ant-build-system) |
379 | (arguments |
380 | `(#:tests? #f |
381 | #:phases |
382 | (modify-phases %standard-phases |
383 | (add-after 'unpack 'move-version-specific |
384 | (lambda _ |
385 | (copy-file "shared/src/main/scala-2.13+/scala/xml/ScalaVersionSpecific.scala" |
386 | "shared/src/main/scala/scala/xml/ScalaVersionSpecific.scala") |
387 | #t)) |
388 | (replace 'build |
389 | ,(build-scala-phase '(("." "scala-xml")))) |
390 | (replace 'install |
391 | (install-jars "build"))))) |
392 | (native-inputs |
393 | `(("scala" ,scala))) |
394 | (home-page "") |
395 | (synopsis "") |
396 | (description "") |
397 | (license license:asl2.0))) |
398 | |
399 | (define-public scala-simulacrum |
400 | (package |
401 | (name "scala-simulacrum") |
402 | (version "1.0.1") |
403 | (source (origin |
404 | (method git-fetch) |
405 | (uri (git-reference |
406 | (url "https://github.com/typelevel/simulacrum") |
407 | (commit (string-append "v" version)))) |
408 | (file-name (git-file-name name version)) |
409 | (sha256 |
410 | (base32 |
411 | "1a4yrv9x6vb989385m0rmb7y6lcd8b7lcq5ksp37k70dl3piam4z")))) |
412 | (build-system ant-build-system) |
413 | (arguments |
414 | `(#:tests? #f |
415 | #:phases |
416 | (modify-phases %standard-phases |
417 | (replace 'build |
418 | ,(build-scala-phase |
419 | '(("core" "simulacrum")) |
420 | #:scala-arguments |
421 | '("-Ymacro-annotations" "-deprecation" "-feature" |
422 | "-language:higherKinds" "-language:implicitConversions"))) |
423 | (replace 'install |
424 | (install-jars "build"))))) |
425 | (native-inputs |
426 | `(("scala" ,scala))) |
427 | (home-page "") |
428 | (synopsis "") |
429 | (description "") |
430 | (license license:asl2.0))) |
431 | |
432 | (define-public scala-geny |
433 | (package |
434 | (name "scala-geny") |
435 | (version "0.6.10") |
436 | (source (origin |
437 | (method git-fetch) |
438 | (uri (git-reference |
439 | (url "https://github.com/com-lihaoyi/geny") |
440 | (commit version))) |
441 | (file-name (git-file-name name version)) |
442 | (sha256 |
443 | (base32 |
444 | "1km1xpvyy14ipgv019axg31vd9csnsi54cp8sw9mzdjikh6i211f")))) |
445 | (build-system ant-build-system) |
446 | (arguments |
447 | `(#:tests? #f |
448 | #:phases |
449 | (modify-phases %standard-phases |
450 | (replace 'build |
451 | ,(build-scala-phase '(("geny" "scala-geny")) |
452 | #:scala-locations '("src") |
453 | #:java-locations '("src"))) |
454 | (replace 'install |
455 | (install-jars "build"))))) |
456 | (native-inputs |
457 | `(("scala" ,scala))) |
458 | (home-page "") |
459 | (synopsis "") |
460 | (description "") |
461 | (license license:asl2.0))) |
462 | |
463 | (define-public scala-sourcecode |
464 | (package |
465 | (name "scala-sourcecode") |
466 | (version "0.2.7") |
467 | (source (origin |
468 | (method git-fetch) |
469 | (uri (git-reference |
470 | (url "https://github.com/com-lihaoyi/sourcecode") |
471 | (commit version))) |
472 | (file-name (git-file-name name version)) |
473 | (sha256 |
474 | (base32 |
475 | "11xd0a0svm15hcknpsfzsyl9sy7dc692b93i39j3z8mgrnh5x4di")))) |
476 | (build-system ant-build-system) |
477 | (arguments |
478 | `(#:tests? #f |
479 | #:phases |
480 | (modify-phases %standard-phases |
481 | (replace 'build |
482 | ,(build-scala-phase '(("sourcecode" "scala-sourcecode")) |
483 | #:scala-locations '("src" "src-2") |
484 | #:java-locations '("src"))) |
485 | (replace 'install |
486 | (install-jars "build"))))) |
487 | (native-inputs |
488 | `(("scala" ,scala))) |
489 | (home-page "") |
490 | (synopsis "") |
491 | (description "") |
492 | (license license:asl2.0))) |
493 | |
494 | (define-public scala-fastparse |
495 | (package |
496 | (name "scala-fastparse") |
497 | (version "2.3.2") |
498 | (source (origin |
499 | (method git-fetch) |
500 | (uri (git-reference |
501 | (url "https://github.com/com-lihaoyi/fastparse") |
502 | (commit version))) |
503 | (file-name (git-file-name name version)) |
504 | (sha256 |
505 | (base32 |
506 | "04wqggkywfy3q733x18mi873wh23w1ix5kypradpz0njdyfznikh")))) |
507 | (build-system ant-build-system) |
508 | (arguments |
509 | `(#:tests? #f |
510 | #:phases |
511 | (modify-phases %standard-phases |
512 | (add-after 'unpack 'generate-source |
513 | (lambda _ |
514 | ;; this file would be generated by build.sc, but it requires |
515 | ;; more dependencies |
516 | (with-output-to-file "fastparse/src/fastparse/SequencerGen.scala" |
517 | (lambda _ |
518 | (display "package fastparse |
519 | trait SequencerGen[Sequencer[_, _, _]] extends LowestPriSequencer[Sequencer]{ |
520 | protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C] |
521 | ") |
522 | (display |
523 | (string-join |
524 | (map |
525 | (lambda (i) |
526 | (let* ((ts (map |
527 | (lambda (n) (string-append "T" (number->string n))) |
528 | (iota i 1))) |
529 | (chunks |
530 | (map |
531 | (lambda (n) (string-append "t._" (number->string n))) |
532 | (iota i 1))) |
533 | (tsD (string-join |
534 | (append ts (list "D")) |
535 | ",")) |
536 | (anys (string-join |
537 | (map (lambda (t) "Any") |
538 | ts) |
539 | ", "))) |
540 | (string-append |
541 | "val BaseSequencer" (number->string i) ": Sequencer[(" anys "), Any, (" anys ", Any)] = |
542 | Sequencer0((t, d) => (" (string-join chunks ", ") ", d)) |
543 | implicit def Sequencer" (number->string i) "[" tsD "]: Sequencer[(" (string-join ts ", ") "), D, (" tsD ")] = |
544 | BaseSequencer" (number->string i) ".asInstanceOf[Sequencer[(" (string-join ts ", ") "), D, (" tsD ")]] |
545 | "))) |
546 | (iota 20 2)) |
547 | "\n")) |
548 | (display "} |
549 | trait LowestPriSequencer[Sequencer[_, _, _]]{ |
550 | protected[this] def Sequencer0[A, B, C](f: (A, B) => C): Sequencer[A, B, C] |
551 | implicit def Sequencer1[T1, T2]: Sequencer[T1, T2, (T1, T2)] = Sequencer0{case (t1, t2) => (t1, t2)} |
552 | } |
553 | "))) |
554 | #t)) |
555 | (replace 'build |
556 | ,(build-scala-phase '(("fastparse" "scala-fastparse") |
557 | ("scalaparse" "scala-scalaparse")) |
558 | #:scala-locations '("src" "src-jvm") |
559 | #:java-locations '("src" "src-jvm"))) |
560 | (replace 'install |
561 | (install-jars "build"))))) |
562 | (native-inputs |
563 | `(("scala" ,scala))) |
564 | (propagated-inputs |
565 | `(("scala-geny" ,scala-geny) |
566 | ("scala-sourcecode" ,scala-sourcecode))) |
567 | (home-page "") |
568 | (synopsis "") |
569 | (description "") |
570 | (license license:asl2.0))) |
571 | |
572 | (define-public scala-dirs-dev-directories |
573 | (package |
574 | (name "scala-dirs-dev-directories") |
575 | (version "23") |
576 | (source (origin |
577 | (method git-fetch) |
578 | (uri (git-reference |
579 | (url "https://github.com/dirs-dev/directories-jvm") |
580 | ;; exact version used by coursier |
581 | (commit "7acadf2ab9a4ce306d840d652cdb77fade11b94b"))) |
582 | (file-name (git-file-name name version)) |
583 | (sha256 |
584 | (base32 |
585 | "09h2dxzbkhki65kkkm29w7id0m0hgswsbwrbb2ix50yj297n6nbm")))) |
586 | (build-system ant-build-system) |
587 | (arguments |
588 | `(#:tests? #f |
589 | #:phases |
590 | (modify-phases %standard-phases |
591 | (replace 'build |
592 | ,(build-scala-phase '(("." "scala-directories")))) |
593 | (replace 'install |
594 | (install-jars "build"))))) |
595 | (native-inputs |
596 | `(("scala" ,scala))) |
597 | (home-page "") |
598 | (synopsis "") |
599 | (description "") |
600 | (license license:asl2.0))) |
601 | |
602 | (define-public scala-windowsansi |
603 | (package |
604 | (name "scala-windowsansi") |
605 | (version "0.0.3") |
606 | (source (origin |
607 | (method git-fetch) |
608 | (uri (git-reference |
609 | (url "https://github.com/alexarchambault/windows-ansi") |
610 | (commit (string-append "v" version)))) |
611 | (file-name (git-file-name name version)) |
612 | (sha256 |
613 | (base32 |
614 | "0r21yhxmwi71qx7qqrpk0z7ykcd08xs7fl6yhzwlqjl0kar7wq0m")))) |
615 | (build-system ant-build-system) |
616 | (arguments |
617 | `(#:tests? #f |
618 | #:phases |
619 | (modify-phases %standard-phases |
620 | (replace 'build |
621 | ,(build-scala-phase '(("jni" "scala-windowsansi-jni") |
622 | ("ps" "scala-windowsansi-ps")))) |
623 | (add-after 'unpack 'remove-proprietary-interfaces |
624 | (lambda _ |
625 | (delete-file |
626 | "jni/src/main/java/io/github/alexarchambault/windowsansi/NativeImageFeature.java") |
627 | (delete-file |
628 | "jni/src/main/java/io/github/alexarchambault/windowsansi/WindowsAnsiSubstitutions.java"))) |
629 | (replace 'install |
630 | (install-jars "build"))))) |
631 | (native-inputs |
632 | `(("scala" ,scala))) |
633 | (propagated-inputs |
634 | `(("java-jansi" ,java-jansi))) |
635 | (home-page "") |
636 | (synopsis "") |
637 | (description "") |
638 | (license license:asl2.0))) |
639 | |
640 | (define-public scala-argonaut |
641 | (package |
642 | (name "scala-argonaut") |
643 | (version "6.3.3") |
644 | (source (origin |
645 | (method git-fetch) |
646 | (uri (git-reference |
647 | (url "https://github.com/argonaut-io/argonaut") |
648 | (commit (string-append "v" version)))) |
649 | (file-name (git-file-name name version)) |
650 | (sha256 |
651 | (base32 |
652 | "1pvc5jklaqqx957brkrwywvh5gsq08xd2k4c8bm4gnkd9b5n8wnl")))) |
653 | (build-system ant-build-system) |
654 | (arguments |
655 | `(#:tests? #f |
656 | #:phases |
657 | (modify-phases %standard-phases |
658 | (add-before 'build 'generate-sources |
659 | (lambda _ |
660 | ;; Converted from project/Boilerplate.scala |
661 | (define header "package argonaut\n\n") |
662 | (define arities (iota 22 1)) |
663 | (define aritiesExceptOne (iota 21 2)) |
664 | (define (arityChars n) |
665 | (string (integer->char (+ (char->integer #\A) (- n 1))))) |
666 | (define (functionTypeParameters arity) |
667 | (string-join (map arityChars (iota arity 1)) ", ")) |
668 | (define (tupleFields arity) |
669 | (string-join |
670 | (map |
671 | (lambda (n) |
672 | (string-append "x._" (number->string n))) |
673 | (iota arity 1)) |
674 | ", ")) |
675 | (define (listPatternMatch arity) |
676 | (string-append |
677 | (string-join |
678 | (map |
679 | (lambda (n) |
680 | (string-append "c" (string-downcase (arityChars n)))) |
681 | (iota arity 1)) |
682 | " :: ") |
683 | " :: Nil")) |
684 | (define (jsonStringParams arity) |
685 | (string-join |
686 | (map |
687 | (lambda (n) |
688 | (format #f "~an: JsonString" (string-downcase (arityChars n)))) |
689 | (iota arity 1)) |
690 | ", ")) |
691 | (define (jsonStringParamNames arity) |
692 | (string-join |
693 | (map |
694 | (lambda (n) |
695 | (format #f "~an" (string-downcase (arityChars n)))) |
696 | (iota arity 1)) |
697 | ", ")) |
698 | |
699 | (with-output-to-file "argonaut/shared/src/main/scala/argonaut/GeneratedDecodeJsons.scala" |
700 | (lambda _ |
701 | (define (decodeJsonContextArities n) |
702 | (string-join |
703 | (map (lambda (n) (format #f "~a: DecodeJson" (arityChars n))) |
704 | (iota n 1)) |
705 | ",")) |
706 | (define (decodeJsonParams n) |
707 | (string-join |
708 | (map |
709 | (lambda (n) |
710 | (define char (arityChars n)) |
711 | (format #f "decode~a: DecodeJson[~a]" |
712 | (string-downcase char) char)) |
713 | (iota n 1)) |
714 | ", ")) |
715 | (define tupleDecodes |
716 | (map |
717 | (lambda (arity) |
718 | (define forComprehensionLines |
719 | (string-join |
720 | (map |
721 | (lambda (n) |
722 | (define char (arityChars n)) |
723 | (format #f " x~a <- decode~a(c~a)" |
724 | (string-downcase char) (string-downcase char) |
725 | (string-downcase char))) |
726 | (iota arity 1)) |
727 | "\n")) |
728 | (define yieldResult |
729 | (string-join |
730 | (map |
731 | (lambda (n) |
732 | (string-append "x" (string-downcase (arityChars n)))) |
733 | (iota arity 1)) |
734 | ", ")) |
735 | (format #f " |
736 | implicit def Tuple~aDecodeJson[~a](implicit ~a): DecodeJson[(~a)] = |
737 | DecodeJson(c => |
738 | c.jdecode[List[HCursor]] flatMap { |
739 | case ~a => for { |
740 | ~a |
741 | } yield (~a) |
742 | case _ => DecodeResult.fail(\"[~a]Tuple~a[~a]\", c.history) |
743 | }) |
744 | " |
745 | arity |
746 | (functionTypeParameters arity) |
747 | (decodeJsonParams arity) |
748 | (functionTypeParameters arity) |
749 | (listPatternMatch arity) |
750 | forComprehensionLines |
751 | yieldResult |
752 | (functionTypeParameters arity) |
753 | arity |
754 | (functionTypeParameters arity))) |
755 | aritiesExceptOne)) |
756 | (define jdecode1 " |
757 | def jdecode1[A, X](f: A => X)(implicit decodea: DecodeJson[A]): DecodeJson[X] = |
758 | decodea.map(f) |
759 | ") |
760 | (define jdecodes |
761 | (map |
762 | (lambda (arity) |
763 | (format #f " |
764 | def jdecode~a[~a, X](f: (~a) => X)(implicit dx: DecodeJson[(~a)]): DecodeJson[X] = |
765 | dx.map(x => f(~a))" |
766 | arity |
767 | (functionTypeParameters arity) |
768 | (functionTypeParameters arity) |
769 | (functionTypeParameters arity) |
770 | (tupleFields arity))) |
771 | aritiesExceptOne)) |
772 | |
773 | (define jdecode1L " |
774 | def jdecode1L[A: DecodeJson, X](f: A => X)(an: JsonString): DecodeJson[X] = |
775 | DecodeJson(x => for { |
776 | aa <- x.get[A](an) |
777 | } yield f(aa))") |
778 | |
779 | (define jdecodeLs |
780 | (map |
781 | (lambda (arity) |
782 | (define forComprehensionLines |
783 | (string-join |
784 | (map |
785 | (lambda (n) |
786 | (define upperChar (arityChars n)) |
787 | (define lowerChar (string-downcase upperChar)) |
788 | (format #f " ~a~a <- x.get[~a](~an)" |
789 | lowerChar lowerChar upperChar lowerChar)) |
790 | (iota arity 1)) |
791 | "\n")) |
792 | (define yieldExpression |
793 | (string-join |
794 | (map |
795 | (lambda (n) |
796 | (define lowerChar (string-downcase (arityChars n))) |
797 | (format #f "~a~a" lowerChar lowerChar)) |
798 | (iota arity 1)) |
799 | ", ")) |
800 | |
801 | (format #f " |
802 | def jdecode~aL[~a, X](f: (~a) => X)(~a): DecodeJson[X] = |
803 | DecodeJson(x => for { |
804 | ~a |
805 | } yield f(~a))" |
806 | arity |
807 | (decodeJsonContextArities arity) |
808 | (functionTypeParameters arity) |
809 | (jsonStringParams arity) |
810 | forComprehensionLines |
811 | yieldExpression)) |
812 | aritiesExceptOne)) |
813 | (display header) |
814 | (display "trait GeneratedDecodeJsons { |
815 | this: DecodeJsons => |
816 | import Json._ |
817 | ") |
818 | (display |
819 | (string-join |
820 | (append tupleDecodes (cons jdecode1 jdecodes) |
821 | (cons jdecode1L jdecodeLs)) |
822 | "")) |
823 | (display "\n}\n"))) |
824 | |
825 | (with-output-to-file "argonaut/shared/src/main/scala/argonaut/GeneratedEncodeJsons.scala" |
826 | (lambda _ |
827 | (define (encodeJsonContextArities n) |
828 | (string-join |
829 | (map |
830 | (lambda (n) |
831 | (format #f "~a: EncodeJson" (arityChars n))) |
832 | (iota n 1)) |
833 | ", ")) |
834 | (define (encodeJsonParams n) |
835 | (string-join |
836 | (map |
837 | (lambda (n) |
838 | (define char (arityChars n)) |
839 | (format #f "encode~a: EncodeJson[~a]" |
840 | (string-downcase char) char)) |
841 | (iota n 1)) |
842 | ", ")) |
843 | (define (invokeEncodeJsonParams n) |
844 | (string-join |
845 | (map |
846 | (lambda (n) |
847 | (define char (string-downcase (arityChars n))) |
848 | (format #f "encode~a(~a)" char char)) |
849 | (iota n 1)) |
850 | ", ")) |
851 | |
852 | (define tupleEncodes |
853 | (map |
854 | (lambda (arity) |
855 | (format #f " |
856 | implicit def Tuple~aEncodeJson[~a](implicit ~a): EncodeJson[(~a)] = |
857 | EncodeJson({ |
858 | case (~a) => jArray(List(~a)) |
859 | }) |
860 | " |
861 | arity |
862 | (functionTypeParameters arity) |
863 | (encodeJsonParams arity) |
864 | (functionTypeParameters arity) |
865 | (string-downcase (functionTypeParameters arity)) |
866 | (invokeEncodeJsonParams arity))) |
867 | aritiesExceptOne)) |
868 | |
869 | (define jencode1 " |
870 | def jencode1[X, A](f: X => A)(implicit encodea: EncodeJson[A]): EncodeJson[X] = |
871 | encodea.contramap(f) |
872 | ") |
873 | |
874 | (define jencodes |
875 | (map |
876 | (lambda (arity) |
877 | (format #f " |
878 | def jencode~a[X, ~a](f: X => (~a))(implicit encodex: EncodeJson[(~a)]): EncodeJson[X] = |
879 | encodex.contramap(f) |
880 | " |
881 | arity |
882 | (functionTypeParameters arity) |
883 | (functionTypeParameters arity) |
884 | (functionTypeParameters arity))) |
885 | aritiesExceptOne)) |
886 | |
887 | (define jencode1L " |
888 | def jencode1L[X, A](f: X => A)(an: JsonString)(implicit encodea: EncodeJson[A]): EncodeJson[X] = |
889 | EncodeJson(x => jSingleObject(an, encodea.apply(f(x)))) |
890 | ") |
891 | (define jencodeLs |
892 | (map |
893 | (lambda (arity) |
894 | (define encodePairs |
895 | (string-join |
896 | (map |
897 | (lambda (n) |
898 | (define upperChar (arityChars n)) |
899 | (define lowerChar (string-downcase upperChar)) |
900 | (format #f "(~an, encode~a.apply(~a))" |
901 | lowerChar lowerChar lowerChar)) |
902 | (iota arity 1)) |
903 | ", ")) |
904 | |
905 | (format #f " |
906 | def jencode~aL[X, ~a](fxn: X => (~a))(~a)(implicit ~a): EncodeJson[X] = |
907 | EncodeJson(x => jObjectAssocList({ |
908 | val (~a) = fxn(x) |
909 | List(~a) |
910 | })) |
911 | " |
912 | arity |
913 | (functionTypeParameters arity) |
914 | (functionTypeParameters arity) |
915 | (jsonStringParams arity) |
916 | (encodeJsonParams arity) |
917 | (string-downcase (functionTypeParameters arity)) |
918 | encodePairs) |
919 | ) |
920 | aritiesExceptOne)) |
921 | |
922 | (define content |
923 | (string-join |
924 | (append |
925 | tupleEncodes (cons jencode1 jencodes) (cons jencode1L jencodeLs)) |
926 | "")) |
927 | |
928 | (display header) |
929 | (format #t " |
930 | trait GeneratedEncodeJsons { |
931 | this: EncodeJsons => |
932 | import Json._ |
933 | ~a |
934 | } |
935 | " |
936 | content))) |
937 | |
938 | (with-output-to-file "argonaut/shared/src/main/scala/argonaut/GeneratedCodecJsons.scala" |
939 | (lambda _ |
940 | (define (codecJsonContextArities n) |
941 | (string-join |
942 | (map |
943 | (lambda (n) |
944 | (format #f "~a: EncodeJson: DecodeJson" (arityChars n))) |
945 | (iota n 1)) |
946 | ", ")) |
947 | |
948 | (define codec1 " |
949 | def codec1[A: EncodeJson: DecodeJson, X](f: A => X, g: X => A)(an: JsonString): CodecJson[X] = |
950 | CodecJson(jencode1L(g)(an).encode, jdecode1L(f)(an).decode) |
951 | ") |
952 | (define codecs |
953 | (map |
954 | (lambda (arity) |
955 | (format #f " |
956 | def codec~a[~a, X](f: (~a) => X, g: X => (~a))(~a): CodecJson[X] = |
957 | CodecJson(jencode~aL(g)(~a).encode, jdecode~aL(f)(~a).decode) |
958 | " |
959 | arity |
960 | (codecJsonContextArities arity) |
961 | (functionTypeParameters arity) |
962 | (functionTypeParameters arity) |
963 | (jsonStringParams arity) |
964 | arity |
965 | (jsonStringParamNames arity) |
966 | arity |
967 | (jsonStringParamNames arity))) |
968 | aritiesExceptOne)) |
969 | |
970 | (define casecodec1 " |
971 | def casecodec1[A: EncodeJson: DecodeJson, X](f: A => X, g: X => Option[A])(an: JsonString): CodecJson[X] = |
972 | CodecJson(jencode1L(g)(an).encode, jdecode1L(f)(an).decode) |
973 | ") |
974 | (define casecodecs |
975 | (map |
976 | (lambda (arity) |
977 | (format #f " |
978 | def casecodec~a[~a, X](f: (~a) => X, g: X => Option[(~a)])(~a): CodecJson[X] = |
979 | CodecJson(jencode~aL(g andThen (_.get))(~a).encode, jdecode~aL(f)(~a).decode) |
980 | " |
981 | arity |
982 | (codecJsonContextArities arity) |
983 | (functionTypeParameters arity) |
984 | (functionTypeParameters arity) |
985 | (jsonStringParams arity) |
986 | arity |
987 | (jsonStringParamNames arity) |
988 | arity |
989 | (jsonStringParamNames arity))) |
990 | aritiesExceptOne)) |
991 | (define content |
992 | (string-join |
993 | (append |
994 | (cons codec1 codecs) (cons casecodec1 casecodecs)) |
995 | "")) |
996 | |
997 | (display header) |
998 | (format #t " |
999 | trait GeneratedCodecJsons { |
1000 | import Json._ |
1001 | import DecodeJson._ |
1002 | import EncodeJson._ |
1003 | ~a |
1004 | } |
1005 | " |
1006 | content))) |
1007 | #t)) |
1008 | (replace 'build |
1009 | ,(build-scala-phase '(("argonaut" "scala-argonaut")) |
1010 | #:scala-locations '("shared/src/main/scala" |
1011 | "shared/src/main/scala2") |
1012 | #:java-locations '("shared/src/main/java"))) |
1013 | (replace 'install |
1014 | (install-jars "build"))))) |
1015 | (native-inputs |
1016 | `(("scala" ,scala))) |
1017 | (home-page "") |
1018 | (synopsis "") |
1019 | (description "") |
1020 | (license license:bsd-3))) |
1021 | |
1022 | (define-public scala-shapeless |
1023 | (package |
1024 | (name "scala-shapeless") |
1025 | (version "2.3.7") |
1026 | (source (origin |
1027 | (method git-fetch) |
1028 | (uri (git-reference |
1029 | (url "https://github.com/milessabin/shapeless") |
1030 | (commit (string-append "v" version)))) |
1031 | (file-name (git-file-name name version)) |
1032 | (sha256 |
1033 | (base32 |
1034 | "1ajni5f5gi76bghv5ajxlnfpz7163za5zv5w02fyfc0rq9p0lxai")))) |
1035 | (build-system ant-build-system) |
1036 | (arguments |
1037 | `(#:tests? #f |
1038 | #:phases |
1039 | (modify-phases %standard-phases |
1040 | (add-before 'build 'generate-sources |
1041 | (lambda _ |
1042 | ;; Converted from project/Boilerplate.scala |
1043 | (define header "package shapeless\n\n") |
1044 | (define scalaBinaryVersion ,(version-major+minor (package-version scala))) |
1045 | (define (templateVals arity) |
1046 | (let* ((synTypes (map |
1047 | (lambda (n) |
1048 | (string (integer->char (+ (char->integer #\A) n)))) |
1049 | (iota arity))) |
1050 | (synVals (map |
1051 | (lambda (n) |
1052 | (string (integer->char (+ (char->integer #\a) n)))) |
1053 | (iota arity))) |
1054 | (synTypedVals (map |
1055 | (lambda (v t) |
1056 | (string-append v ":" t)) |
1057 | synVals synTypes))) |
1058 | `((arity . ,(number->string arity)) |
1059 | (synTypes . ,synTypes) |
1060 | (synVals . ,synVals) |
1061 | (synTypedVals . ,synTypedVals) |
1062 | (A--N . ,(string-join synTypes ", ")) |
1063 | (A--N,Res . ,(string-join (append synTypes (list "Res")) ", ")) |
1064 | (a--n . ,(string-join synVals ", ")) |
1065 | (A::N . ,(string-join (append synTypes (list "HNil")) "::")) |
1066 | (a::n . ,(string-join (append synVals (list "HNil")) "::")) |
1067 | (_--_ . ,(string-join (map (const "_") synVals) ", ")) |
1068 | (tupleA--N . ,(if (equal? arity 1) |
1069 | "Tuple1[A]" |
1070 | (string-append |
1071 | "(" |
1072 | (string-join synTypes ", ") |
1073 | ")"))) |
1074 | (tuple_--_ . ,(if (equal? arity 1) |
1075 | "Tuple1[_]" |
1076 | (string-append |
1077 | "(" |
1078 | (string-join (map (const "_") synTypes) ", ") |
1079 | ")"))) |
1080 | (tuplea--n . ,(if (equal? arity 1) |
1081 | "Tuple1(a)" |
1082 | (string-append |
1083 | "(" |
1084 | (string-join synVals ", ") |
1085 | ")"))) |
1086 | (a:A--n:N . ,(string-join synTypedVals ", "))))) |
1087 | |
1088 | (define* (generate-file filename content #:key |
1089 | (range (iota 22 1))) |
1090 | (with-output-to-file (string-append "core/src/main/scala/shapeless/" |
1091 | filename) |
1092 | (lambda _ |
1093 | (define rawContents |
1094 | (map |
1095 | (lambda (n) |
1096 | (filter |
1097 | (lambda (s) (not (equal? s ""))) |
1098 | (string-split (content n (templateVals n)) #\newline))) |
1099 | range)) |
1100 | (define preBody |
1101 | (let loop ((strs (car rawContents)) (ans '())) |
1102 | (cond |
1103 | ((null? strs) (reverse ans)) |
1104 | ((string-prefix? "|" (car strs)) |
1105 | (loop (cdr strs) (cons (car strs) ans))) |
1106 | (else (reverse ans))))) |
1107 | (define instances |
1108 | (apply append |
1109 | (map |
1110 | (lambda (content) |
1111 | (filter |
1112 | (lambda (s) |
1113 | (string-prefix? "-" s)) |
1114 | content)) |
1115 | rawContents))) |
1116 | (define postBody |
1117 | (let loop ((strs (reverse (car rawContents))) (ans '())) |
1118 | (cond |
1119 | ((null? strs) (reverse ans)) |
1120 | ((string-prefix? "|" (car strs)) |
1121 | (loop (cdr strs) (cons (car strs) ans))) |
1122 | (else (reverse ans))))) |
1123 | (display |
1124 | (string-append |
1125 | header |
1126 | (string-join |
1127 | (map |
1128 | (lambda (s) |
1129 | (substring s 1)) |
1130 | (append preBody instances postBody)) |
1131 | "\n")))))) |
1132 | (generate-file |
1133 | "tupler.scala" |
1134 | (lambda (arity template) |
1135 | (string-append " |
1136 | |package ops |
1137 | | |
1138 | |import hlist.Tupler |
1139 | | |
1140 | |trait TuplerInstances { |
1141 | | type Aux[L <: HList, T] = Tupler[L] { type Out = T } |
1142 | - |
1143 | - implicit def hlistTupler" (assoc-ref template 'arity) "[ |
1144 | - " (assoc-ref template 'A--N) " |
1145 | - ]: Aux[ |
1146 | - " (assoc-ref template 'A::N) ", |
1147 | - " (assoc-ref template 'tupleA--N) " |
1148 | - ] = Tupler.instance { case " (assoc-ref template 'a::n) " => |
1149 | - " (assoc-ref template 'tuplea--n) " |
1150 | - } |
1151 | |} |
1152 | "))) |
1153 | (generate-file |
1154 | "fntoproduct.scala" |
1155 | (lambda (arity template) |
1156 | (define fnType (string-append "(" (assoc-ref template 'A--N) ") => Res")) |
1157 | (define hlistFnType |
1158 | (string-append "(" (assoc-ref template 'A::N) ") => Res")) |
1159 | (define fnBody |
1160 | (if (equal? arity 0) |
1161 | "_ => fn()" |
1162 | (string-append "{ case " (assoc-ref template 'a::n) |
1163 | " => fn(" (assoc-ref template 'a--n) ") }"))) |
1164 | (string-append " |
1165 | |package ops |
1166 | | |
1167 | |import function.FnToProduct |
1168 | | |
1169 | |trait FnToProductInstances { |
1170 | | type Aux[F, P] = FnToProduct[F] { type Out = P } |
1171 | - |
1172 | - implicit def fnToProduct" (assoc-ref template 'arity) "[ |
1173 | - " (assoc-ref template 'A--N,Res) " |
1174 | - ]: Aux[ |
1175 | - (" fnType "), |
1176 | - "hlistFnType" |
1177 | - ] = FnToProduct.instance(fn => " fnBody ") |
1178 | |} |
1179 | "))) |
1180 | (generate-file |
1181 | "fnfromproduct.scala" |
1182 | (lambda (arity template) |
1183 | (define fnType (string-append "(" (assoc-ref template 'A--N) ") => Res")) |
1184 | (define hlistFnType |
1185 | (string-append "(" (assoc-ref template 'A::N) ") => Res")) |
1186 | (string-append " |
1187 | |package ops |
1188 | | |
1189 | |import function.FnFromProduct |
1190 | | |
1191 | |trait FnFromProductInstances { |
1192 | | type Aux[F, O] = FnFromProduct[F] { type Out = O } |
1193 | - |
1194 | - implicit def fnFromProduct" (assoc-ref template 'arity) "[ |
1195 | - "(assoc-ref template 'A--N,Res)" |
1196 | - ]: Aux[ |
1197 | - " hlistFnType ", |
1198 | - " fnType " |
1199 | - ] = FnFromProduct.instance { hf => |
1200 | - (" (assoc-ref template 'a:A--n:N) ") => |
1201 | - hf(" (assoc-ref template 'a::n) ") |
1202 | - } |
1203 | |} |
1204 | ")) |
1205 | #:range (iota 23)) |
1206 | (generate-file |
1207 | "caseinst.scala" |
1208 | (lambda (arity template) |
1209 | (string-append |
1210 | " |
1211 | | |
1212 | |trait CaseInst { |
1213 | | import poly._ |
1214 | | |
1215 | - implicit def inst" (assoc-ref template 'arity) " |
1216 | - [Fn <: Poly, " (assoc-ref template 'A--N) ", Res] |
1217 | - (cse : Case[Fn, " (assoc-ref template 'A::N) "] { type Result = Res }) |
1218 | - : (" (assoc-ref template 'A--N) ") => Res = |
1219 | - (" (assoc-ref template 'a:A--n:N) ") |
1220 | - => cse.value(" (assoc-ref template 'a::n) ") |
1221 | - |
1222 | |} |
1223 | "))) |
1224 | (generate-file |
1225 | "polyapply.scala" |
1226 | (lambda (arity template) |
1227 | (string-append " |
1228 | | |
1229 | |trait PolyApply { |
1230 | | import poly._ |
1231 | - def apply |
1232 | - [" (assoc-ref template 'A--N) "] |
1233 | - (" (assoc-ref template 'a:A--n:N) ") |
1234 | - (implicit cse : Case[this.type, " (assoc-ref template 'A::N) "]) |
1235 | - : cse.Result = |
1236 | - cse(" (assoc-ref template 'a::n) ") |
1237 | - |
1238 | |} |
1239 | "))) |
1240 | (generate-file |
1241 | "polyinst.scala" |
1242 | (lambda (arity template) |
1243 | (string-append " |
1244 | | |
1245 | |trait PolyInst { |
1246 | | |
1247 | - implicit def inst" (assoc-ref template 'arity) " |
1248 | - [" (assoc-ref template 'A--N) "] |
1249 | - (fn : Poly)(implicit cse : fn.ProductCase[" (assoc-ref template 'A::N) "]) |
1250 | - : (" (assoc-ref template 'A--N) ") => cse.Result = |
1251 | - (" (assoc-ref template 'a:A--n:N) ") |
1252 | - => cse(" (assoc-ref template 'a::n) ") |
1253 | - |
1254 | |} |
1255 | "))) |
1256 | (generate-file |
1257 | "cases.scala" |
1258 | (lambda (arity template) |
1259 | (string-append " |
1260 | | |
1261 | |trait Cases { |
1262 | | import poly._ |
1263 | | |
1264 | - type Case" (assoc-ref template 'arity) "[Fn, " (assoc-ref template 'A--N) "] = |
1265 | - Case[Fn, " (assoc-ref template 'A::N) "] |
1266 | - |
1267 | - object Case" (assoc-ref template 'arity) " { |
1268 | - type Aux[Fn, " (assoc-ref template 'A--N) ", Result0] = |
1269 | - Case[Fn, " (assoc-ref template 'A::N) "] { type Result = Result0 } |
1270 | - |
1271 | - def apply[ |
1272 | - Fn, " (assoc-ref template 'A--N) ", Result0 |
1273 | - ]( |
1274 | - fn: (" (assoc-ref template 'A--N) ") => Result0 |
1275 | - ): Aux[Fn, " (assoc-ref template 'A--N) ", Result0] = |
1276 | - Case { case " (assoc-ref template 'a::n) " => |
1277 | - fn(" (assoc-ref template 'a--n) ") |
1278 | - } |
1279 | - } |
1280 | - |
1281 | |} |
1282 | "))) |
1283 | (generate-file |
1284 | "polyntraits.scala" |
1285 | (lambda (arity template) |
1286 | (define fnBody |
1287 | (if (equal? arity 0) |
1288 | "_ => fn()" |
1289 | (string-append |
1290 | "{ case " (assoc-ref template 'a::n) " => fn(" |
1291 | (assoc-ref template 'a--n) ") }"))) |
1292 | (string-append " |
1293 | | |
1294 | - |
1295 | -trait Poly" (assoc-ref template 'arity) " extends Poly { outer => |
1296 | - type Case[" (assoc-ref template 'A--N) "] = |
1297 | - poly.Case[this.type, " (assoc-ref template 'A::N) "] |
1298 | - |
1299 | - object Case { |
1300 | - type Aux[" (assoc-ref template 'A--N) ", Result0] = |
1301 | - poly.Case[outer.type, " (assoc-ref template 'A::N) "] { type Result = Result0 } |
1302 | - } |
1303 | - |
1304 | - class CaseBuilder[" (assoc-ref template 'A--N) "] { |
1305 | - def apply[Res]( |
1306 | - fn: (" (assoc-ref template 'A--N) ") => Res |
1307 | - ): Case.Aux[" (assoc-ref template 'A--N) ", Res] = |
1308 | - poly.Case(" fnBody ") |
1309 | - } |
1310 | - |
1311 | - def at[" (assoc-ref template 'A--N) "] = |
1312 | - new CaseBuilder[" (assoc-ref template 'A--N) "] |
1313 | -} |
1314 | - |
1315 | -object Poly" (assoc-ref template 'arity) " extends PolyNBuilders.Poly" (assoc-ref template 'arity) "Builder[HNil] { |
1316 | - val functions = HNil |
1317 | -} |
1318 | | |
1319 | "))) |
1320 | (generate-file |
1321 | "polynbuilders.scala" |
1322 | (lambda (arity template) |
1323 | (string-append " |
1324 | | |
1325 | | |
1326 | |/** |
1327 | | * Provides elegant syntax for creating polys from functions |
1328 | | * |
1329 | | * @author Aristotelis Dossas |
1330 | | */ |
1331 | |object PolyNBuilders { |
1332 | - |
1333 | - trait Poly" (assoc-ref template 'arity) "Builder[HL <: HList] { self => |
1334 | - |
1335 | - val functions: HL |
1336 | - class AtAux[" (assoc-ref template 'A--N) "] { |
1337 | - def apply[Out](λ: (" (assoc-ref template 'A--N) ") => Out) = { |
1338 | - new Poly" (assoc-ref template 'arity) "Builder[((" (assoc-ref template 'A--N) ") => Out) :: HL] { |
1339 | - val functions = λ :: self.functions |
1340 | - } |
1341 | - } |
1342 | - } |
1343 | - def at[" (assoc-ref template 'A--N) "] = new AtAux[" (assoc-ref template 'A--N) "] |
1344 | - |
1345 | - def build = new Poly" (assoc-ref template 'arity) " { |
1346 | - val functions = self.functions |
1347 | - |
1348 | - implicit def allCases[" (assoc-ref template 'A--N) ", Out](implicit tL: Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, HL]) = { |
1349 | - val func: (" (assoc-ref template 'A--N) ") => Out = tL(functions) |
1350 | - at(func) |
1351 | - } |
1352 | - } |
1353 | - } |
1354 | - |
1355 | - /* For internal use of Poly" (assoc-ref template 'arity) "Builder */ |
1356 | - trait Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, HL <: HList] { |
1357 | - def apply(l: HL): (" (assoc-ref template 'A--N) ") => Out |
1358 | - } |
1359 | - |
1360 | - object Function" (assoc-ref template 'arity) "TypeAt { |
1361 | - private def instance[" (assoc-ref template 'A--N) ", Out, HL <: HList]( |
1362 | - f: HL => (" (assoc-ref template 'A--N) ") => Out |
1363 | - ): Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, HL] = |
1364 | - new Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, HL] { |
1365 | - def apply(l: HL) = f(l) |
1366 | - } |
1367 | - |
1368 | - implicit def at0[ |
1369 | - " (assoc-ref template 'A--N) ", Out, Tail <: HList |
1370 | - ]: Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, ((" (assoc-ref template 'A--N) ") => Out) :: Tail] = |
1371 | - instance(_.head) |
1372 | - |
1373 | - implicit def atOther[ |
1374 | - " (assoc-ref template 'A--N) ", Out, Tail <: HList, Head |
1375 | - ]( |
1376 | - implicit tprev: Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, Tail] |
1377 | - ): Function" (assoc-ref template 'arity) "TypeAt[" (assoc-ref template 'A--N) ", Out, Head :: Tail] = |
1378 | - instance(l => tprev(l.tail)) |
1379 | - } |
1380 | |} |
1381 | "))) |
1382 | (generate-file |
1383 | "nats.scala" |
1384 | (lambda (arity template) |
1385 | (define n (number->string arity)) |
1386 | (string-append " |
1387 | | |
1388 | |trait Nats { |
1389 | - |
1390 | - type _" n " = Succ[_" (number->string (- arity 1)) "] |
1391 | - val _" n ": _" n " = new _" n " |
1392 | |} |
1393 | "))) |
1394 | (generate-file |
1395 | "tupletypeables.scala" |
1396 | (lambda (arity template) |
1397 | (define implicitArgs |
1398 | (string-join |
1399 | (map |
1400 | (lambda (a) |
1401 | (string-append "cast" a ":Typeable[" a "]")) |
1402 | (assoc-ref template 'synTypes)) |
1403 | ", ")) |
1404 | (define enumerators |
1405 | (let ((synTypes (assoc-ref template 'synTypes))) |
1406 | (string-join |
1407 | (map |
1408 | (lambda (a i) |
1409 | (string-append "_ <- p._" (number->string i) ".cast[" a "]")) |
1410 | synTypes |
1411 | (iota (length synTypes) 1)) |
1412 | "; "))) |
1413 | (define castVals |
1414 | (string-join |
1415 | (map |
1416 | (lambda (a) |
1417 | (string-append "${cast" a ".describe}")) |
1418 | (assoc-ref template 'synTypes)) |
1419 | ", ")) |
1420 | (string-append " |
1421 | | |
1422 | |trait TupleTypeableInstances { |
1423 | | import syntax.typeable._ |
1424 | - |
1425 | - implicit def tuple" (assoc-ref template 'arity) "Typeable[ |
1426 | - " (assoc-ref template 'A--N) " |
1427 | - ]( |
1428 | - implicit " implicitArgs " |
1429 | - ): Typeable[" (assoc-ref template 'tupleA--N) "] = |
1430 | - Typeable.instance(s\"(" castVals ")\") { |
1431 | - case p: " (assoc-ref template 'tuple_--_) " => |
1432 | - for (" enumerators ") |
1433 | - yield p.asInstanceOf[" (assoc-ref template 'tupleA--N) "] |
1434 | - case _ => |
1435 | - None |
1436 | - } |
1437 | |} |
1438 | "))) |
1439 | (generate-file |
1440 | "sizedbuilder.scala" |
1441 | (lambda (arity template) |
1442 | (define synVals (assoc-ref template 'synVals)) |
1443 | (define a:T--n:T |
1444 | (string-join |
1445 | (map |
1446 | (lambda (v) (string-append v ":T")) |
1447 | synVals) |
1448 | ", ")) |
1449 | (define commonImplicits |
1450 | "factory: Factory[T, CC[T]], ev: AdditiveCollection[CC[T]]") |
1451 | (define implicits |
1452 | (case scalaBinaryVersion |
1453 | (("2.11" "2.12") commonImplicits) |
1454 | (else (string-append "dis: DefaultToIndexedSeq[CC], " commonImplicits)))) |
1455 | (string-append " |
1456 | | |
1457 | |class SizedBuilder[CC[_]] { |
1458 | | import scala.collection._ |
1459 | | import nat._ |
1460 | | import Sized.wrap |
1461 | | |
1462 | - def apply[T](" a:T--n:T ") |
1463 | - (implicit " implicits ") = |
1464 | - wrap[CC[T], _" (assoc-ref template 'arity) "]((factory.newBuilder ++= Seq(" (assoc-ref template 'a--n) ")).result()) |
1465 | - |
1466 | |} |
1467 | "))) |
1468 | (generate-file |
1469 | "hmapbuilder.scala" |
1470 | (lambda (arity template) |
1471 | (define typeArgs |
1472 | (string-join |
1473 | (map |
1474 | (lambda (n) |
1475 | (let ((n (number->string n))) |
1476 | (string-append "K" n ", V" n))) |
1477 | (iota arity)) |
1478 | ", ")) |
1479 | (define args |
1480 | (string-join |
1481 | (map |
1482 | (lambda (n) |
1483 | (let ((n (number->string n))) |
1484 | (string-append "e" n ": (K" n ", V" n ")"))) |
1485 | (iota arity)) |
1486 | ", ")) |
1487 | (define witnesses |
1488 | (string-join |
1489 | (map |
1490 | (lambda (n) |
1491 | (let ((n (number->string n))) |
1492 | (string-append "ev" n ": R[K" n ", V" n "]"))) |
1493 | (iota arity)) |
1494 | ", ")) |
1495 | (define mapArgs |
1496 | (string-join |
1497 | (map |
1498 | (lambda (n) |
1499 | (let ((n (number->string n))) |
1500 | (string-append "e" n))) |
1501 | (iota arity)) |
1502 | ", ")) |
1503 | (string-append " |
1504 | | |
1505 | |class HMapBuilder[R[_, _]] { |
1506 | - |
1507 | - def apply |
1508 | - [" typeArgs "] |
1509 | - (" args ") |
1510 | - (implicit " witnesses ") |
1511 | - = new HMap[R](Map(" mapArgs ")) |
1512 | |} |
1513 | "))) |
1514 | (generate-file |
1515 | "unpack.scala" |
1516 | (lambda (arity template) |
1517 | (define typeblock |
1518 | (string-append "FF[" (assoc-ref template 'A--N) "], FF, " |
1519 | (assoc-ref template 'A--N))) |
1520 | (define hktypeblock |
1521 | (string-append "FF[" (assoc-ref template '_--_) "], " |
1522 | (assoc-ref template 'A--N))) |
1523 | (define traitname (string-append "Unpack" (number->string arity))) |
1524 | (string-append " |
1525 | | |
1526 | - |
1527 | -/** |
1528 | - * Type class witnessing that type `PP` is equal to `FF[" (assoc-ref template 'A--N) "]` for some higher kinded type `FF[" (assoc-ref template '_--_) "]` and type(s) `" (assoc-ref template 'A--N) "`. |
1529 | - * |
1530 | - * @author Miles Sabin |
1531 | - */ |
1532 | -trait " traitname "[-PP, " hktypeblock "] |
1533 | - |
1534 | -object " traitname " { |
1535 | - implicit def unpack[" hktypeblock "]: " traitname "[" typeblock "] = new " traitname "[" typeblock "] {} |
1536 | -} |
1537 | | |
1538 | "))) |
1539 | #t)) |
1540 | (replace 'build |
1541 | ,(build-scala-phase '(("core" "scala-shapeless")) |
1542 | #:scala-locations '("src/main/scala" |
1543 | "src/main/scala_2.13+"))) |
1544 | (replace 'install |
1545 | (install-jars "build"))))) |
1546 | (native-inputs |
1547 | `(("scala" ,scala))) |
1548 | (home-page "") |
1549 | (synopsis "") |
1550 | (description "") |
1551 | (license license:asl2.0))) |
1552 | |
1553 | (define-public scala-argonaut-shapeless |
1554 | (package |
1555 | (name "scala-argonaut-shapeless") |
1556 | (version "1.3.0") |
1557 | (source (origin |
1558 | (method git-fetch) |
1559 | (uri (git-reference |
1560 | (url "https://github.com/alexarchambault/argonaut-shapeless") |
1561 | (commit (string-append "v" version)))) |
1562 | (file-name (git-file-name name version)) |
1563 | (sha256 |
1564 | (base32 |
1565 | "0afa81fjhrjhb97iapkhv4jax9ply6mk9chmr0kwps12drjmwn03")))) |
1566 | (build-system ant-build-system) |
1567 | (arguments |
1568 | `(#:tests? #f |
1569 | #:phases |
1570 | (modify-phases %standard-phases |
1571 | (replace 'build |
1572 | ,(build-scala-phase '(("core" "scala-argonaut-shapeless")) |
1573 | #:scala-locations '("shared/src/main/scala"))) |
1574 | (replace 'install |
1575 | (install-jars "build"))))) |
1576 | (native-inputs |
1577 | `(("scala" ,scala))) |
1578 | (propagated-inputs |
1579 | `(("scala-argonaut" ,scala-argonaut) |
1580 | ("scala-shapeless" ,scala-shapeless))) |
1581 | (home-page "") |
1582 | (synopsis "") |
1583 | (description "") |
1584 | (license license:asl2.0))) |
1585 | |
1586 | (define-public scala-coursier |
1587 | (package |
1588 | (name "scala-coursier") |
1589 | (version "2.0.16") |
1590 | (source (origin |
1591 | (method git-fetch) |
1592 | (uri (git-reference |
1593 | (url "https://github.com/coursier/coursier") |
1594 | (commit (string-append "v" version)))) |
1595 | (file-name (git-file-name name version)) |
1596 | (sha256 |
1597 | (base32 |
1598 | "0cvy7bnqg8s2s4xljnw0p9r970yjqzg56f5nwgg0z2g18pafa3im")))) |
1599 | (build-system ant-build-system) |
1600 | (arguments |
1601 | `(#:tests? #f |
1602 | #:phases |
1603 | (modify-phases %standard-phases |
1604 | (add-after 'unpack 'remove-proprietary-interfaces |
1605 | (lambda _ |
1606 | (delete-file |
1607 | "modules/cache/jvm/src/main/java/coursier/cache/internal/SigWinchNativeWindows.java"))) |
1608 | (replace 'build |
1609 | ,(build-scala-phase |
1610 | '(("modules/util" "scala-coursier-util") |
1611 | ("modules/core" "scala-coursier-core") |
1612 | ("modules/paths" "scala-coursier-paths") |
1613 | ("modules/cache" "scala-coursier-cache") |
1614 | ("modules/coursier" "scala-coursier")) |
1615 | #:scala-arguments '("-Ymacro-annotations"))) |
1616 | (add-after 'unpack 'remove-compat |
1617 | (lambda _ |
1618 | (substitute* (find-files "." "\\.scala$") |
1619 | (("import scala.collection.compat.*") "")) |
1620 | #t)) |
1621 | (replace 'install |
1622 | (install-jars "build"))))) |
1623 | (native-inputs |
1624 | `(("scala" ,scala))) |
1625 | ;; XXX: dirs-dev is normally shaded, so should we really propagate it? |
1626 | (propagated-inputs |
1627 | `(("java-jsoup" ,java-jsoup) |
1628 | ("java-concurrent-reference-hash-map" ,java-concurrent-reference-hash-map) |
1629 | ("scala-argonaut-shapeless" ,scala-argonaut-shapeless) |
1630 | ("scala-data-class" ,scala-data-class) |
1631 | ("scala-dirs-dev-directories" ,scala-dirs-dev-directories) |
1632 | ("scala-fastparse" ,scala-fastparse) |
1633 | ("scala-simulacrum" ,scala-simulacrum) |
1634 | ("scala-windowsansi" ,scala-windowsansi) |
1635 | ("scala-xml" ,scala-xml))) |
1636 | (home-page "") |
1637 | (synopsis "") |
1638 | (description "") |
1639 | (license license:asl2.0))) |
1640 | |
1641 | (define-public sbt-launcher |
1642 | (package |
1643 | (name "sbt-launcher") |
1644 | (version "1.3.2") |
1645 | (source (origin |
1646 | (method git-fetch) |
1647 | (uri (git-reference |
1648 | (url "https://github.com/sbt/launcher") |
1649 | (commit (string-append "v" version)))) |
1650 | (file-name (git-file-name name version)) |
1651 | (sha256 |
1652 | (base32 |
1653 | "0xff9w9arj91vgh5mbzb52r2l1ij42cby3kbbmkly1nf3j4xhrx2")))) |
1654 | (build-system ant-build-system) |
1655 | (arguments |
1656 | `(#:tests? #f |
1657 | #:phases |
1658 | (modify-phases %standard-phases |
1659 | (add-before 'build 'generate-manifest |
1660 | (lambda* (#:key outputs #:allow-other-keys) |
1661 | (define (split n str) |
1662 | (if (<= (string-length str) n) |
1663 | (list str) |
1664 | (cons (substring str 0 n) (split n (substring str n))))) |
1665 | (let ((dir "launcher-implementation/src/main/resources/META-INF")) |
1666 | (mkdir-p dir) |
1667 | (with-output-to-file (string-append dir "/MANIFEST.MF") |
1668 | (lambda _ |
1669 | (format #t "Manifest-Version: 1.0\n") |
1670 | ;(format #t "Class-Path: ~a\n" |
1671 | ; (string-join |
1672 | ; (split |
1673 | ; 58 |
1674 | ; (string-join |
1675 | ; (map |
1676 | ; (lambda (jar) |
1677 | ; ;; We can't use absolute paths with java 8 :/ |
1678 | ; (string-append "../../../../../../../../.." jar)) |
1679 | ; (cons |
1680 | ; (string-append |
1681 | ; (assoc-ref outputs "out") |
1682 | ; "/share/java/sbt-launcher-interface.jar") |
1683 | ; (string-split (getenv "CLASSPATH") #\:))) |
1684 | ; " ")) |
1685 | ; "\n ")) |
1686 | (format #t "Main-Class: xsbt.boot.Boot\n\n")))))) |
1687 | (add-after 'unpack 'fill-template |
1688 | (lambda _ |
1689 | (substitute* "launcher-implementation/src/main/input_sources/CrossVersionUtil.scala" |
1690 | (("\\$\\{\\{cross.package0\\}\\}") "xsbt") |
1691 | (("\\$\\{\\{cross.package1\\}\\}") "boot")) |
1692 | (copy-file "launcher-implementation/src/main/input_sources/CrossVersionUtil.scala" |
1693 | "launcher-implementation/src/main/scala/CrossVersionUtil.scala") |
1694 | #t)) |
1695 | (replace 'build |
1696 | ,(build-scala-phase |
1697 | '(("launcher-interface" "sbt-launcher-interface") |
1698 | ("launcher-implementation" "sbt-launcher-implementation")))) |
1699 | (replace 'install |
1700 | (install-jars "build"))))) |
1701 | (inputs |
1702 | `(("sbt-ivy" ,sbt-ivy) |
1703 | ("scala-coursier" ,scala-coursier))) |
1704 | (native-inputs |
1705 | `(("scala" ,scala))) |
1706 | (home-page "") |
1707 | (synopsis "") |
1708 | (description "") |
1709 | (license license:bsd-3))) |
1710 | |
1711 | ;; This subproject is the one that is provides the binary "sbt". Its role is |
1712 | ;; is to download and execute the full sbt, so it is not very usable for package |
1713 | ;; building right now. |
1714 | (define-public sbt-launch |
1715 | (package |
1716 | (name "sbt") |
1717 | (version "1.5.4") |
1718 | (source (origin |
1719 | (method git-fetch) |
1720 | (uri (git-reference |
1721 | (url "https://github.com/sbt/sbt") |
1722 | (commit (string-append "v" version)))) |
1723 | (file-name (git-file-name name version)) |
1724 | (sha256 |
1725 | (base32 |
1726 | "0k3ywjmahlhnr9rg29pac6n64x8pgaz5q7p4gn548mc3nm1fwzdj")))) |
1727 | (build-system ant-build-system) |
1728 | (arguments |
1729 | `(#:tests? #f |
1730 | #:phases |
1731 | (modify-phases %standard-phases |
1732 | (replace 'build |
1733 | (lambda* (#:key inputs #:allow-other-keys) |
1734 | (let ((launcher (assoc-ref inputs "sbt-launcher")) |
1735 | (scala (assoc-ref inputs "scala"))) |
1736 | (mkdir-p "build/sbt") |
1737 | (with-directory-excursion "build" |
1738 | (copy-file "../launch/src/main/input_resources/sbt/sbt.boot.properties" |
1739 | "sbt/sbt.boot.properties") |
1740 | (substitute* "sbt/sbt.boot.properties" |
1741 | (("\\$\\{\\{sbt.version\\}\\}") ,version) |
1742 | (("\\$\\{\\{org\\}\\}") "org.scala-sbt")) |
1743 | (copy-recursively "../launch/src/main/resources" ".") |
1744 | ;; Create a standalon jar file, with all its dependencies |
1745 | (for-each |
1746 | (lambda (package) |
1747 | (for-each |
1748 | (lambda (jar) |
1749 | (invoke "jar" "xf" jar)) |
1750 | (find-files (assoc-ref inputs package) ".*.jar$"))) |
1751 | '("java-concurrent-reference-hash-map" "java-jansi" |
1752 | "sbt-ivy" "scala-coursier" "scala-dirs-dev-directories" |
1753 | "scala-fastparse" "scala-xml")) |
1754 | (invoke |
1755 | "jar" "xf" |
1756 | (string-append scala "/lib/scala-library.jar")) |
1757 | (invoke |
1758 | "jar" "xf" |
1759 | (string-append launcher "/share/java/sbt-launcher-interface.jar")) |
1760 | ;; Make it last so it can override META-INF/MANIFEST.MF |
1761 | (invoke |
1762 | "jar" "xf" |
1763 | (string-append launcher "/share/java/sbt-launcher-implementation.jar")) |
1764 | (invoke "jar" "cfm" "../sbt-launch.jar" "META-INF/MANIFEST.MF" |
1765 | ".") |
1766 | ;; We need to shade some of the dependencies, or they will conflict |
1767 | ;; with what SBT downloads later, leading to errors such as |
1768 | ;; NoSuchMethodError, etc. |
1769 | ;; We use jarjar for that task. |
1770 | (let ((jarjar |
1771 | (car (find-files (assoc-ref inputs "java-jarjar") ".*.jar$"))) |
1772 | (injar "../sbt-launch.jar") |
1773 | (outjar "../sbt-launch-shaded.jar")) |
1774 | (with-output-to-file "rules" |
1775 | (lambda _ |
1776 | (format #t (string-append |
1777 | "rule " |
1778 | "coursier.** " |
1779 | "xsbt.boot.internal.shaded." |
1780 | "coursier.@1~%")) |
1781 | (format #t (string-append |
1782 | "rule " |
1783 | "fastparse.** " |
1784 | "coursier.core.shaded." |
1785 | "fastparse.@1~%")) |
1786 | (format #t (string-append |
1787 | "rule " |
1788 | "dev.dirs.** " |
1789 | "coursier.chache.shaded.dirs." |
1790 | "dev.dirs.@1~%")) |
1791 | (format #t (string-append |
1792 | "rule " |
1793 | "concurrentrefhashmap.** " |
1794 | "xsbt.boot.internal.shaded.concurrentrefhashmap." |
1795 | "concurrentrefhashmap.@1~%")))) |
1796 | (invoke "java" "-jar" jarjar "process" "rules" injar outjar) |
1797 | (delete-file injar) |
1798 | (rename-file outjar injar)) |
1799 | )))) |
1800 | (replace 'install |
1801 | (lambda* (#:key outputs inputs #:allow-other-keys) |
1802 | (substitute* "sbt" |
1803 | (("_to_be_replaced") ,(package-version this-package))) |
1804 | (let* ((out (assoc-ref outputs "out")) |
1805 | (bin (string-append out "/bin"))) |
1806 | (chmod "sbt" #o755) |
1807 | (install-file "sbt" bin) |
1808 | (install-file "sbt-launch.jar" bin))))))) |
1809 | (inputs |
1810 | `(("java-concurrent-reference-hash-map" ,java-concurrent-reference-hash-map) |
1811 | ("java-jansi" ,java-jansi) |
1812 | ("java-jarjar" ,java-jarjar) |
1813 | ("sbt-launcher" ,sbt-launcher) |
1814 | ("sbt-ivy" ,sbt-ivy) |
1815 | ("scala" ,scala) |
1816 | ("scala-coursier" ,scala-coursier) |
1817 | ("scala-dirs-dev-directories" ,scala-dirs-dev-directories) |
1818 | ("scala-fastparse" ,scala-fastparse) |
1819 | ("scala-xml" ,scala-xml))) |
1820 | (home-page "") |
1821 | (synopsis "") |
1822 | (description "") |
1823 | (license license:asl2.0))) |
1824 |