Toggle diff (326 lines)
diff --git a/gnu/packages/java.scm b/gnu/packages/java.scm
index 43f0f37b91..9d73d9a7e8 100644
--- a/gnu/packages/java.scm
+++ b/gnu/packages/java.scm
@@ -56,6 +56,7 @@
#:use-module (gnu packages gettext)
#:use-module (gnu packages gcc)
#:use-module (gnu packages gl)
+ #:use-module (gnu packages glib)
#:use-module (gnu packages ghostscript) ;lcms
#:use-module (gnu packages gnome)
#:use-module (gnu packages groovy)
@@ -2567,16 +2568,641 @@ distribution.")))
(arguments
`(#:jar-name "java-openjfx-graphics.jar"
#:source-dir "modules/graphics/src/main/java"
- #:tests? #f; require X
- #:test-dir "modules/graphics/src/test"))
+ #:tests? #f ; requires X
+ #:test-dir "modules/graphics/src/test"
+ #:test-include (list "**/*Test.*")
+ #:modules ((guix build ant-build-system)
+ (guix build utils)
+ (srfi srfi-1)
+ (srfi srfi-26)
+ (ice-9 regex)
+ (ice-9 match))
+ #:phases
+ (let* ((jdk (assoc-ref %build-inputs "jdk"))
+ (javac/h-flags
+ '(;; When javac is compiling code it doesn't link
+ ;; against rt.jar by default. Instead it uses special
+ ;; symbol file lib/ct.sym with class stubs.
+ ;; Surprisingly this file contains many but not *all*
+ ;; of internal classes.
+ "-XDignore.symbol.file"
+ ;; It’s an internal option for JDK 1.7+ that prevents
+ ;; the compiler from sharing a table that will never
+ ;; be reused. When shared, it can’t be garbage
+ ;; collected, continues to accumulate data, and
+ ;; therefore wastes memory.
+ "-XDuseUnsharedTable=true"))
+ (common-flags
+ '("-fno-strict-aliasing" "-fPIC" "-fno-omit-frame-pointer" ;; optimization flags
+ "-fstack-protector"
+ "-W" "-Wall" "-Wno-unused" "-Wno-parentheses" "-Werror=implicit-function-declaration"))
+ (cc-flags
+ `(,@common-flags "-c" "-ffunction-sections" "-fdata-sections"
+ "-I" ,(string-append jdk "/include")
+ "-I" ,(string-append jdk "/include/linux")))
+ (link-flags
+ `("-static-libgcc" "-static-libstdc++" "-shared" ,@common-flags
+ "-z" "relro"
+ "-Wl,--gc-sections"))
+ (java-aux-class?
+ (lambda (class)
+ (string-match "\\$[0-9]+\\.class" class)))
+ (java-list-classes
+ (lambda (path)
+ ;; For each .java file we need to figure out what
+ ;; class the .java file belongs in and convert it to a
+ ;; class name.
+ (filter-map
+ (lambda (class)
+ (let* ((rx (make-regexp (string-append path file-name-separator-string "?")))
+ (class (string-drop-right class (string-length ".class")))
+ (class (match:suffix (regexp-exec rx class))))
+ (if (java-aux-class? class)
+ #f
+ (string-join (string-split class #\/) "."))))
+ (find-files path "\\.class$")))))
+ (modify-phases %standard-phases
+
+ (replace 'build
+ (lambda _
+ ;; Do not mix different classes. There will be more stuff in build/classes
+ (invoke "ant" "compile" "-Dclasses.dir=modules/graphics/build/classes/java/main")
+ #t))
+
+ ;; XX: Description can be found in build.gradle:1429. Currently
+ ;; there is no sdk creation step.
+ ;;
+ ;; The Decora and Prism JSL files have to be generated in a very specific set of steps.
+ ;; 1) Compile the *Compile.java classes. These live in src/main/jsl-* and will be
+ ;; output to $buildDir/classes/jsl-compilers/* (where * == decora or prism).
+ ;; 2) Generate source files from the JSL files contained in src/main/jsl-*. These
+ ;; will be output to $buildDir/generated-src/jsl-*
+ ;; 3) Compile the JSL Java sources in $buildDir/generated-src/jsl-* and put the output
+ ;; into classes/jsl-*
+ ;; 4) Compile the native JSL sources in $buildDir/generated-src/jsl-* and put the obj
+ ;; files into native/jsl-* and the resulting library into libs/jsl-*.dll|so|dylib
+ ;; 5) Modify the jar step to include classes/jsl-*
+ ;; The native library must be copied over during SDK creation time in the "sdk" task. In
+ ;; addition to these steps, the clean task is created. Note that I didn't bother to create
+ ;; a new task for each of the decora files, preferring instead just to create a rule?? Also
+ ;; need "clean" tasks for each compile task.
+ (add-after 'build 'compile-prism-compilers
+ (lambda _
+ (let ((prism-compilers-classes "modules/graphics/build/classes/jsl-compilers/prism")
+ (prism-src "modules/graphics/src/main/jsl-prism/"))
+ (mkdir-p prism-compilers-classes)
+
+ (apply invoke "javac" "-d" prism-compilers-classes
+ (append javac/h-flags (find-files prism-src "\\.java"))))
+
+ #t))
+
+ (add-after 'compile-prism-compilers 'generate-prism-shaders
+ (lambda _
+ (let ((prism-compilers-classes "modules/graphics/build/classes/jsl-compilers/prism")
+ (prism-src "modules/graphics/src/main/jsl-prism/")
+ (prism-gen-src "modules/graphics/build/generated-src/jsl-prism"))
+ (mkdir-p prism-gen-src)
+ (for-each (lambda (file)
+ (apply invoke "java"
+ "-cp" (string-join (list
+ ;; For CompileJSL
+ prism-compilers-classes
+ ;; jsl files are there
+ prism-src
+ (getenv "CLASSPATH"))
+ ":")
+ "CompileJSL"
+ "-i" prism-src
+ "-o" prism-gen-src
+ "-t"
+ "-pkg" "com/sun/prism"
+ "-d3d"
+ "-es2"
+ "-name" (list file)))
+ (find-files prism-src "\\.jsl$")))
+ #t))
+
+ (add-after 'generate-prism-shaders 'compile-prism-shaders
+ (lambda _
+ (let* ((classes "modules/graphics/build/classes/java/main")
+ (prism-classes "modules/graphics/build/classes/jsl-prism")
+ (prism-gen-src "modules/graphics/build/generated-src/jsl-prism")
+ (prism-gen-shaders-src (string-append prism-gen-src "/com/sun/prism/shader")))
+ (mkdir-p prism-classes)
+ (apply invoke "javac"
+ "-d" prism-classes
+ "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+ (append javac/h-flags (find-files prism-gen-shaders-src))))
+ #t))
+
+ (add-after 'compile-prism-shaders 'compile-decora-compilers
+ (lambda _
+ (let ((classes "modules/graphics/build/classes/java/main")
+ (decora-compilers-classes "modules/graphics/build/classes/jsl-compilers/decora")
+ (decora-src "modules/graphics/src/main/jsl-decora/"))
+ (mkdir-p decora-compilers-classes)
+ (apply invoke "javac"
+ "-d" decora-compilers-classes
+ "-cp" (string-append classes ":" (getenv "CLASSPATH"))
+ (append javac/h-flags (find-files decora-src "\\.java"))))
+ #t))
+
+ (add-after 'compile-decora-compilers 'generate-decora-shaders
+ (lambda _
+ (let ((classes "modules/graphics/build/classes/java/main")
+ (decora-classes "modules/graphics/build/classes/jsl-decora/")
+ (decora-compilers-classes "modules/graphics/build/classes/jsl-compilers/decora")
+ (decora-gen-src "modules/graphics/build/generated-src/jsl-decora")
+ (decora-src "modules/graphics/src/main/jsl-decora/")
+ (decora-components '([(file-name . "ColorAdjust")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "Brightpass")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "SepiaTone")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "PerspectiveTransform")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "DisplacementMap")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "InvertMask")
+ (generator . "CompileJSL")
+ (outputs . "-all")]
+ [(file-name . "Blend")
+ (generator . "CompileBlend")
+ (outputs . "-all")]
+ [(file-name . "PhongLighting")
+ (generator . "CompilePhong")
+ (outputs . "-all")]
+ [(file-name . "LinearConvolve")
+ (generator . "CompileLinearConvolve")
+ (outputs . "-hw")]
+ [(file-name . "LinearConvolveShadow")
+ (generator . "CompileLinearConvolve")
+ (outputs . "-hw")])))
+ (mkdir-p decora-gen-src)
+ (for-each (match-lambda
+ ((('file-name . file-name)
+ ('generator . generator)
+ ('outputs . outputs))
+ (apply invoke "java"
+ "-cp" (string-join (cons* classes
+ decora-src
+ ;; CompileJSL
+ decora-compilers-classes
+ decora-classes
+ ;; We need resources from the build
+ "buildSrc/src/main/resources"
+ (list (getenv "CLASSPATH")))
+ ":")
+ generator
+ "-i" decora-src
+ "-o" decora-gen-src
+ "-t"
+ "-pkg" "com/sun/scenario/effect"
+ outputs
+ (list file-name))))
+ decora-components)
+ #t)))
+
+ (add-after 'generate-decora-shaders 'compile-decora-shaders
+ (lambda _
+ (let ((classes "modules/graphics/build/classes/java/main")
+ (decora-classes "modules/graphics/build/classes/jsl-decora/")
+ (decora-gen-src "modules/graphics/build/generated-src/jsl-decora"))
+ (mkdir-p decora-classes)
+ (apply invoke "javac"
+ "-d" decora-classes
+ "-cp" classes
+ (append javac/h-flags (find-files decora-gen-src "\\.java$"))))
+ #t))
+
+ (add-after 'compile-decora-shaders 'compile-decora-native-lib
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let* ((classes "modules/graphics/build/classes/java/main")
+ (decora-gen-headers "modules/graphics/build/generated-src/headers/jsl-decora")
+ (decora-gen-src "modules/graphics/build/generated-src/jsl-decora")
+ (decora-native-lib "modules/graphics/build/libs/jsl-decora/linux/libdecora_sse.so")
+ (decora-native-obj "modules/graphics/build/native/jsl-decora/linux")
+ (decora-native-src "modules/graphics/src/main/native-decora")
+ (decora-src "modules/graphics/src/main/jsl-decora/")
+ (decora-classes "modules/graphics/build/classes/jsl-decora/")
+ (decora-cc-flags `(,@cc-flags "-ffast-math")))
+ (mkdir-p decora-gen-headers)
+ (apply invoke "javah"
+ "-d" decora-gen-headers
+ "-cp" (string-join (list classes decora-classes) ":")
+ (append javac/h-flags
+ (filter (cut string-prefix? "com.sun.scenario.effect.impl.sw.sse" <>)
+ (append (java-list-classes classes)
+ (java-list-classes decora-classes)))))
+ (mkdir-p decora-native-obj)
+ (for-each (lambda (cc)
+ (apply invoke "gcc"
+ "-I" decora-gen-headers
+ "-I" decora-gen-src
+ "-I" decora-native-src
+ "-o" (string-append decora-native-obj "/" (basename cc ".cc") ".obj")
+ (append decora-cc-flags (list cc))))
+ (append (find-files decora-gen-src "\\.cc$")
+ (find-files decora-native-src "\\.cc$")))
+ (mkdir-p (dirname decora-native-lib))
+ (apply invoke "g++" "-o" decora-native-lib
+ (append link-flags (find-files decora-native-obj "\\.obj$"))))
+ #t))
+
+ (add-after 'compile-decora-native-lib 'compile-linux-font-native-lib
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let* ((classes "modules/graphics/build/classes/java/main")
+ (font-gen-headers "modules/graphics/build/generated-src/headers/font/linux")
+ (font-native-lib "modules/graphics/build/libs/font/linux/libjavafx_font.so")
+ (font-native-obj "modules/graphics/build/native/font/linux")
+ (font-native-src "modules/graphics/src/main/native-font")
+ ;;
+ (font-cc-flags `("-DJFXFONT_PLUS" ,@cc-flags)))
+ (mkdir-p font-gen-headers)
+ (apply invoke "javah"
+ "-d" font-gen-headers
+ "-cp" classes
+ (append javac/h-flags
+ (filter (lambda (class)
+ (or (string-prefix? "com.sun.javafx.font" class)
+ (string-prefix? "com.sun.javafx.text" class)))
+ (java-list-classes classes))))
+ (mkdir-p font-native-obj)
+ (for-each (lambda (cc)
+ (apply invoke "gcc"
+ "-I" font-gen-headers
+ "-I" font-native-src
+ "-o" (string-append font-native-obj "/"
+ (basename cc ".c") ".obj")
+ (append font-cc-flags (list cc))))
+ (find-files font-native-src "\\.c$"))
+ (mkdir-p (dirname font-native-lib))
+ (apply invoke "g++"
+ "-o" font-native-lib
+ (append link-flags
+ (find-files font-native-obj "\\.obj$"))))
+ #t))
+
+ (add-after 'compile-linux-font-native-lib 'compile-linux-font-freetype
+ (lambda* (#:key inputs #:allow-other-keys)
+ (let* ((classes "modules/graphics/build/classes/java/main")
+ ;;
+ (font-freetype-gen-headers "modules/graphics/build/generated-src/headers/fontFreetype/linux")
+ (font-freetype-native-lib "modules/graphics/build/libs/fontFreetype/linux/libjavafx_font_freetype.so")
+ (font-freetype-native-obj "modules/graphics/build/native/fontFreetype/linux")
+ (font-freetype-native-src "modules/graphics/src/main/native-font/freetype.c")
+ (font-freetype-cc-flags `("-DJFXFONT_PLUS" "-D_ENABLE_PANGO"
+ "$(pkg-config --cflags freetype2)" ,@cc-flags))
+ (font-freetype-link-flags `("$(pkg-config --libs freetype2)" ,@link-flags)))
+ (mkdir-p font-freetype-gen-headers)
+ (apply invoke "javah"
+ "-d" font-freetype-gen-headers
+ "-cp" classes
+ (append javac/h-flags
+ (filter (cut string-prefix? "com.sun.javafx.font.freetype.OSFreetype" <>)
+ (java-list-classes classes))))
+ (mkdir-p font-freetype-native-obj)
+ (invoke "bash" "-c"
+ (string-join `("gcc"
+ ,@font-freetype-cc-flags
+ "-I" ,font-freetype-gen-headers
+ "-I" ,(dirname font-freetype-native-src)
+ "-o" ,(string-append font-freetype-native-obj "/"
+