changeset 4201:5ad23b53ce4c

iOS: updated gradle build (fat libs, webview-closed, ...)
author David Pulkrabek <david.pulkrabek@oracle.com>
date Tue, 09 Jul 2013 09:06:07 +0200
parents 228c5ed14f8f
children d46122695c20
files build.gradle buildSrc/ios.gradle buildSrc/src/main/groovy/com/sun/javafx/gradle/ExportedSymbolsTask.groovy buildSrc/src/main/groovy/com/sun/javafx/gradle/LipoTask.groovy
diffstat 4 files changed, 248 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/build.gradle	Mon Jul 08 14:23:43 2013 -0700
+++ b/build.gradle	Tue Jul 09 09:06:07 2013 +0200
@@ -688,6 +688,16 @@
                 linkTask.dependsOn rcTask;
             }
         }
+
+        def useLipo = targetProperties.containsKey('useLipo') ? targetProperties.useLipo : false
+        if (useLipo) {
+            def lipoTask = project.task("lipo${t.capital}$capitalName", type: LipoTask, dependsOn: javahTask, group: "Build") {
+                description = "Creates native fat library for $name for ${t.name}"
+                libDir = file("$libRootDir/${t.name}")
+                lib = file("$libRootDir/${t.name}/${library(properties.lib)}")
+            }
+            nativeTask.dependsOn(lipoTask)
+        }
     }
 }
 
@@ -1665,10 +1675,12 @@
              "modules/graphics/build/resources/jsl-prism");
         if (COMPILE_SWING) from ("modules/swing/build/classes/main", "modules/swing/build/resources/main")
         if (COMPILE_SWT) from ("modules/swt/build/classes/main", "modules/swt/build/resources/main")
-        if (t.name != 'android') {
+        if (t.name == 'android') {
+            from ("modules/web/build/classes/android", "modules/web/build/resources/android")
+        } else if (t.name == 'ios') {
+            from ("modules/web/build/classes/ios", "modules/web/build/resources/ios")
+        } else {
             from ("modules/web/build/classes/main", "modules/web/build/resources/main")
-        } else {
-            from ("modules/web/build/classes/android", "modules/web/build/resources/android")
         }
         exclude("js/**/*", // er...
                 "PrismLoaderBackend*", // More decora stuff
@@ -1691,9 +1703,10 @@
             // TODO instead of using copy everywhere, I probably want to use "sync" instead?
             // Copy all of the .dll / .so / .dylib native libraries into build/sdk/rt/lib/
             copy {
+                def useLipo = targetProperties.containsKey('useLipo') ? targetProperties.useLipo : false
                 from("modules/graphics/build/libs/jsl-decora/${t.name}/${library(targetProperties.decora.lib)}")
                 ['font', 'prism', 'prismSW', 'prismES2', 'glass', 'iio'].each { lib ->
-                    def variants = targetProperties[lib].containsKey('variants') ? targetProperties[lib].variants : [null]
+                    def variants = targetProperties[lib].containsKey('variants') && !useLipo ? targetProperties[lib].variants : [null]
                     variants.each { variant ->
                         def variantProperties = variant ? targetProperties[lib][variant] : targetProperties[lib]
                         println "modules/graphics/build/libs/$lib/$t.name/${library(variantProperties.lib)}"
@@ -1709,7 +1722,7 @@
                         from ("modules/web/src/main/native/WebKitLibraries/import/runtime")
                     }
                 } else {
-                    if (IS_MAC) from ("$LIBRARY_STUB/libjfxwebkit.dylib")
+                    if (IS_MAC && COMPILE_TARGETS != "ios") from ("$LIBRARY_STUB/libjfxwebkit.dylib")
                     else if (IS_WINDOWS) {
                         from ("$LIBRARY_STUB/jfxwebkit.dll")
                         from ("$LIBRARY_STUB/libxml2.dll")
@@ -1772,6 +1785,18 @@
         dependsOn(jfxrtTask)
         dependsOn(javadoc)
     }
+
+    def generateSymbols = targetProperties.containsKey('generateSymbols') ? targetProperties.generateSymbols : false
+    if (generateSymbols) {
+        def exportedSymbolsTask = project.task("exportedSymbols${t.capital}", type: ExportedSymbolsTask, dependsOn: sdkTask, group: "Build") {
+            description = "Generates exported symbols file for iOS build (from .a libraries)"
+            def libDirName = "build/${t.name}-sdk/rt/$targetProperties.libDest"
+            libDir = file("$libDirName")
+            outputFile = file("$libDirName/exported.symbols")
+        }
+        sdk.dependsOn(exportedSymbolsTask)
+    }
+
     sdk.dependsOn(sdkTask)
 }
 
--- a/buildSrc/ios.gradle	Mon Jul 08 14:23:43 2013 -0700
+++ b/buildSrc/ios.gradle	Tue Jul 09 09:06:07 2013 +0200
@@ -29,11 +29,20 @@
 IOS.canBuild = IS_MAC
 if (!IOS.canBuild) return;
 
+IOS.artifactsName = "ios"
+
 IOS.compileSwing = false;
 IOS.compileSWT = false;
 IOS.compileFXPackager = false;
 IOS.compileDesignTime = false;
 
+defineProperty("USE_LIPO", "false")
+defineProperty("GENERATE_SYMBOLS", "false")
+if (USE_LIPO instanceof String) IOS.useLipo = Boolean.parseBoolean(USE_LIPO)
+if (GENERATE_SYMBOLS instanceof String) IOS.generateSymbols = Boolean.parseBoolean(GENERATE_SYMBOLS)
+
+defineProperty("IOS_VERSION", "6.1")
+
 // Lambda for naming the generated libs
 IOS.library = { name -> return "lib${name}.a" as String }
 
@@ -73,7 +82,7 @@
 def iPhoneSim = "iPhoneSimulator"
 
 String sdkPath(String platform) {
-    return "/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}6.1.sdk";
+    return "/Applications/Xcode.app/Contents/Developer/Platforms/${platform}.platform/Developer/SDKs/${platform}${IOS_VERSION}.sdk";
 }
 
 def linkFlags = [
@@ -86,7 +95,7 @@
     "-framework", "OpenGLES"].flatten()
 
 def ccFlags = [
-    "-miphoneos-version-min=6.1", "-fmessage-length=0", "-std=c99", "-fno-common",
+    "-miphoneos-version-min=6.0", "-fmessage-length=0", "-std=c99", "-fno-common",
     "-Wall", "-fno-strict-aliasing", "-fwrapv", "-fpascal-strings", "-fobjc-abi-version=2", "-fobjc-legacy-dispatch",
     "-I$JDK_HOME/include", "-I$JDK_HOME/include/darwin", "-c",
     IS_DEBUG ? "-DDEBUG" : ["-O3", "-DNDEBUG"]].flatten()
@@ -126,6 +135,7 @@
 IOS.decora.lib = "decora-sse-${archArm}"
 
 IOS.prism = [:]
+IOS.prism.lib = "prism-common"
 IOS.prism.javahInclude = ["com/sun/prism/impl/**/*", "com/sun/prism/PresentableState*"]
 IOS.prism.variants = ["arm", "x86"];
 
@@ -146,6 +156,7 @@
 IOS.prism.x86.lib = "prism-common-${archX86}"
 
 IOS.prismSW = [:]
+IOS.prismSW.lib = "prism-sw"
 IOS.prismSW.javahInclude = ["com/sun/pisces/**/*"]
 IOS.prismSW.variants = ["arm", "x86"];
 
@@ -166,6 +177,7 @@
 IOS.prismSW.x86.lib = "prism-sw-${archX86}"
 
 IOS.iio = [:]
+IOS.iio.lib = "javafx-iio"
 IOS.iio.javahInclude = ["com/sun/javafx/iio/**/*"]
 IOS.iio.variants = ["arm", "x86"];
 
@@ -189,6 +201,7 @@
 IOS.iio.x86.lib = "javafx-iio-${archX86}"
 
 IOS.prismES2 = [:]
+IOS.prismES2.lib = "prism-es2"
 IOS.prismES2.javahInclude = ["com/sun/prism/es2/**/*"]
 IOS.prismES2.variants = ["arm", "x86"];
 
@@ -214,6 +227,7 @@
 
 def closedDir = file("$projectDir/../rt-closed")
 IOS.font = [:]
+IOS.font.lib = "javafx-font"
 IOS.font.javahInclude = [
         "com/sun/javafx/font/**/*",
         "com/sun/javafx/text/**/*"]
@@ -236,6 +250,7 @@
 IOS.font.x86.lib = "javafx-font-${archX86}"
 
 IOS.fontT2K = [:]
+IOS.fontT2K.lib = "javafx-font-t2k"
 IOS.fontT2K.javahInclude = ["com/sun/javafx/font/t2k/**/*"]
 IOS.fontT2K.variants = ["arm", "x86"];
 
@@ -257,3 +272,79 @@
 IOS.fontT2K.x86.linker = linker
 IOS.fontT2K.x86.linkFlags = ["-arch_only", archX86, "-syslibroot", sdkPath(iPhoneSim), linkFlags].flatten()
 IOS.fontT2K.x86.lib = "javafx-font-t2k-${archX86}"
+
+IOS.webview = [:]
+IOS.webview.lib = "javafx-ios-webnode"
+IOS.webview.javahInclude = ["javafx/scene/web/*"]
+IOS.webview.variants = ["arm", "x86"];
+
+IOS.webview.arm = [:]
+IOS.webview.arm.nativeSource = file("$closedDir/javafx-ios-webnode/native")
+IOS.webview.arm.compiler = compiler
+IOS.webview.arm.ccFlags = [ccFlags, "-arch", archArm, "-isysroot", sdkPath(iPhoneOS)].flatten()
+IOS.webview.arm.linker = linker
+IOS.webview.arm.linkFlags = ["-arch_only", archArm, "-syslibroot", sdkPath(iPhoneOS), linkFlags].flatten()
+IOS.webview.arm.lib = "javafx-ios-webnode-${archArm}"
+
+IOS.webview.x86 = [:]
+IOS.webview.x86.nativeSource = [IOS.webview.arm.nativeSource].flatten()
+IOS.webview.x86.compiler = compiler
+IOS.webview.x86.ccFlags = [ccFlags, "-arch", archX86, "-isysroot", sdkPath(iPhoneSim)].flatten()
+IOS.webview.x86.linker = linker
+IOS.webview.x86.linkFlags = ["-arch_only", archX86, "-syslibroot", sdkPath(iPhoneSim), linkFlags].flatten()
+IOS.webview.x86.lib = "javafx-ios-webnode-${archX86}"
+
+project(":web") {
+    if (BUILD_CLOSED) {
+        apply plugin: 'java'
+
+        compileJava {
+            enabled = false
+        }
+
+        afterEvaluate {
+            def compileWebJavaIos = task("compileWebJavaIos",
+                type: JavaCompile, group: "Build") {
+
+                dependsOn(project(":graphics").classes, project(":base").classes)
+                description = "Task compiles web component for iOS."
+                classpath = files(
+                    project(":controls").sourceSets.main.output.classesDir,
+                    project(":graphics").sourceSets.main.output.classesDir,
+                    project(":base").sourceSets.main.output.classesDir
+                )
+                destinationDir = file("modules/web/build/classes/ios")
+                dependencyCacheDir = file("modules/web/build/dependency-cache")
+                source file("$closedDir/javafx-ios-webnode/src")
+            }
+
+            def jarWebJavaIos = task("jarWebJavaIos",
+                type: Jar, group: "Build") {
+                description = "Creates web.jar for iOS."
+                dependsOn(compileWebJavaIos)
+                archiveName = "web.jar"
+                includeEmptyDirs = false
+                destinationDir = project.file("build/libs/ios")
+                from("build/classes/ios")
+            }
+
+            addNative(project, "webview")
+            javahIosWebview.dependsOn(compileWebJavaIos)
+
+            jfxrtIos {
+                from "modules/web/build/classes/ios"
+            }
+
+            sdkIos  {
+                dependsOn(jarWebJavaIos)
+                doLast {
+                    def props = project.ext["IOS"]
+                    copy {
+                        from ("modules/web/build/libs/webview/ios/${props.library(props.webview.lib)}")
+                        into ("build/ios-sdk/rt/${props.libDest}")
+                    }
+                }
+            }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buildSrc/src/main/groovy/com/sun/javafx/gradle/ExportedSymbolsTask.groovy	Tue Jul 09 09:06:07 2013 +0200
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.InputDirectory
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.TaskAction
+
+class ExportedSymbolsTask extends DefaultTask {
+    @OutputFile File outputFile;
+    @InputDirectory File libDir;
+
+
+    @TaskAction void generateExportedSymbols() {
+        // Get symbols only from .a libraries
+        List<String> libNames = [];
+        List<File> files = libDir.listFiles();
+        files.each { file ->
+            if (!file.isDirectory() && file.getName().endsWith(".a")) {
+                libNames.add(file.getAbsolutePath())
+            }
+        }
+
+        def baos = new ByteArrayOutputStream();
+
+        // Execute nm on .a libraries
+        project.exec({
+            commandLine("nm", "-jg");
+            args(libNames);
+            setStandardOutput(baos);
+        });
+
+        def bais = new ByteArrayInputStream(baos.toByteArray());
+
+        outputFile.withWriter { out ->
+            bais.eachLine { line ->
+                // Remove unnecessary lines
+                line = (line =~ /^(?!(_Java|_JNI_)).*$/).replaceFirst("");
+                line = (line =~ /^(_Java|_JNI_).*(.eh)$/).replaceFirst("");
+
+                if (!line.isEmpty()) {
+                    out.writeLine(line);
+                }
+            }
+        }
+
+        baos.close();
+        bais.close();
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/buildSrc/src/main/groovy/com/sun/javafx/gradle/LipoTask.groovy	Tue Jul 09 09:06:07 2013 +0200
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import org.gradle.api.DefaultTask
+import org.gradle.api.tasks.InputDirectory
+import org.gradle.api.tasks.OutputFile
+import org.gradle.api.tasks.TaskAction
+
+
+class LipoTask extends DefaultTask {
+    @InputDirectory File libDir;
+    @OutputFile File lib;
+    @TaskAction void compile() {
+        List<String> libNames = [];
+        List<File> files = libDir.listFiles();
+        files.each { file ->
+            String fileName = file.getName();
+            // process only thin libraries
+            if (!file.isDirectory() && (fileName.indexOf("armv7") != -1 || fileName.indexOf("i386") != -1)) {
+                libNames.add(file.getAbsolutePath())
+            }
+        }
+        // Create a fat library (.a)
+        project.exec({
+            commandLine("lipo", "-create", "-output", "$lib");
+            args(libNames);
+        });
+    }
+}
+