diff options
-rw-r--r-- | doc/qbs.qdoc | 1 | ||||
-rw-r--r-- | qbs.qbs | 1 | ||||
-rw-r--r-- | share/qbs/modules/java/JavaModule.qbs | 41 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/Artifact.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/Artifact.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/ArtifactListJsonWriter.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListJsonWriter.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/ArtifactListTextWriter.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListTextWriter.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/ArtifactListWriter.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListWriter.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/ArtifactListXmlWriter.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListXmlWriter.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/tools/JavaCompilerScannerTool.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/tools/JavaCompilerScannerTool.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerOptions.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerScanner.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerScanner.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/tools/utils/NullFileObject.java (renamed from src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/NullFileObject.java) | 0 | ||||
-rw-r--r-- | share/qbs/modules/java/utils.js | 117 | ||||
-rw-r--r-- | src/libexec/libexec.pro | 5 | ||||
-rw-r--r-- | src/libexec/libexec.qbs | 1 | ||||
-rw-r--r-- | src/libexec/qbs-javac-scan/qbs-javac-scan.pro | 82 | ||||
-rw-r--r-- | src/libexec/qbs-javac-scan/qbs-javac-scan.qbs | 19 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackbox.cpp | 4 |
18 files changed, 138 insertions, 133 deletions
diff --git a/doc/qbs.qdoc b/doc/qbs.qdoc index 4f88b8e5c..460833ec6 100644 --- a/doc/qbs.qdoc +++ b/doc/qbs.qdoc @@ -149,7 +149,6 @@ \table \header \li Option \li Notes - \row \li qbs_enable_java \li Enable support for compiling Java source code. \row \li qbs_enable_unit_tests \li Enable additional autotests. \row \li qbs_disable_rpath \li Disable the use of rpath. This can be used when packaging \QBS for distributions which do not permit the use of rpath, @@ -3,7 +3,6 @@ import qbs 1.0 Project { minimumQbsVersion: "1.4" qbsSearchPaths: ["qbs-resources"] - property bool enableJava: false property bool enableUnitTests: false property bool enableProjectFileUpdates: false property bool enableRPath: true diff --git a/share/qbs/modules/java/JavaModule.qbs b/share/qbs/modules/java/JavaModule.qbs index 27e707b6f..af7b6d609 100644 --- a/share/qbs/modules/java/JavaModule.qbs +++ b/share/qbs/modules/java/JavaModule.qbs @@ -92,7 +92,14 @@ Module { } // Internal properties - property path classFilesDir: FileInfo.joinPaths(product.buildDirectory, "classFiles") + property path classFilesDir: FileInfo.joinPaths(product.buildDirectory, "classes") + property path internalClassFilesDir: FileInfo.joinPaths(product.buildDirectory, ".classes") + + property path runtimeJarPath: { + if (qbs.hostOS.contains("osx") && compilerVersionMajor === 1 && compilerVersionMinor < 7) + return FileInfo.joinPaths(jdkPath, "bundle", "Classes", "classes.jar"); + return FileInfo.joinPaths(jdkPath, "jre", "lib", "rt.jar"); + } // private properties readonly property var rawCompilerVersion: { @@ -130,10 +137,42 @@ Module { fileTags: ["java.java"] } + Group { + name: "io.qt.qbs.internal.java-helper" + files: { + return JavaUtils.helperFullyQualifiedNames("java").map(function(name) { + return FileInfo.joinPaths(path, name + ".java"); + }); + } + + fileTags: ["java.java-internal"] + } + + Rule { + multiplex: true + inputs: ["java.java-internal"] + + outputFileTags: ["java.class-internal"] + outputArtifacts: { + return JavaUtils.helperOutputArtifacts(product); + } + + prepare: { + var cmd = new Command(ModUtils.moduleProperty(product, "compilerFilePath"), + JavaUtils.javacArguments(product, inputs, + JavaUtils.helperOverrideArgs(product, + "javac"))); + cmd.silent = true; + return [cmd]; + } + } + Rule { multiplex: true inputs: ["java.java"] inputsFromDependencies: ["java.jar"] + explicitlyDependsOn: ["java.class-internal"] + outputFileTags: ["java.class", "hpp"] // Annotations can produce additional java source files. Ignored for now. outputArtifacts: { return JavaUtils.outputArtifacts(product, inputs); diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/Artifact.java b/share/qbs/modules/java/io/qt/qbs/Artifact.java index 6d250043e..6d250043e 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/Artifact.java +++ b/share/qbs/modules/java/io/qt/qbs/Artifact.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListJsonWriter.java b/share/qbs/modules/java/io/qt/qbs/ArtifactListJsonWriter.java index 02198d0f4..02198d0f4 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListJsonWriter.java +++ b/share/qbs/modules/java/io/qt/qbs/ArtifactListJsonWriter.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListTextWriter.java b/share/qbs/modules/java/io/qt/qbs/ArtifactListTextWriter.java index 2b32bdd2a..2b32bdd2a 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListTextWriter.java +++ b/share/qbs/modules/java/io/qt/qbs/ArtifactListTextWriter.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListWriter.java b/share/qbs/modules/java/io/qt/qbs/ArtifactListWriter.java index 30a5b816f..30a5b816f 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListWriter.java +++ b/share/qbs/modules/java/io/qt/qbs/ArtifactListWriter.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListXmlWriter.java b/share/qbs/modules/java/io/qt/qbs/ArtifactListXmlWriter.java index 9fbf09ed1..9fbf09ed1 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/ArtifactListXmlWriter.java +++ b/share/qbs/modules/java/io/qt/qbs/ArtifactListXmlWriter.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/JavaCompilerScannerTool.java b/share/qbs/modules/java/io/qt/qbs/tools/JavaCompilerScannerTool.java index 5bef0c90f..5bef0c90f 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/JavaCompilerScannerTool.java +++ b/share/qbs/modules/java/io/qt/qbs/tools/JavaCompilerScannerTool.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerOptions.java b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java index 53cf71033..53cf71033 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerOptions.java +++ b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerScanner.java b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerScanner.java index db5653e5d..db5653e5d 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/JavaCompilerScanner.java +++ b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerScanner.java diff --git a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/NullFileObject.java b/share/qbs/modules/java/io/qt/qbs/tools/utils/NullFileObject.java index e5a4fc4a3..e5a4fc4a3 100644 --- a/src/libexec/qbs-javac-scan/io/qt/qbs/tools/utils/NullFileObject.java +++ b/share/qbs/modules/java/io/qt/qbs/tools/utils/NullFileObject.java diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js index f838dda5f..8e699297a 100644 --- a/share/qbs/modules/java/utils.js +++ b/share/qbs/modules/java/utils.js @@ -30,6 +30,7 @@ var File = loadExtension("qbs.File"); var FileInfo = loadExtension("qbs.FileInfo"); +var ModUtils = loadExtension("qbs.ModUtils"); var Process = loadExtension("qbs.Process"); function findJdkPath(hostOS, arch) { @@ -109,11 +110,23 @@ function supportsGeneratedNativeHeaderFiles(product) { return compilerVersionMajor > 1; } -function javacArguments(product, inputs) { +function javacArguments(product, inputs, overrides) { + function getModuleProperty(product, propertyName, overrides) { + if (overrides && overrides[propertyName]) + return overrides[propertyName]; + return ModUtils.moduleProperty(product, propertyName); + } + + function getModuleProperties(product, propertyName, overrides) { + if (overrides && overrides[propertyName]) + return overrides[propertyName]; + return ModUtils.moduleProperties(product, propertyName); + } + var i; - var outputDir = ModUtils.moduleProperty(product, "classFilesDir"); + var outputDir = getModuleProperty(product, "classFilesDir", overrides); var classPaths = [outputDir]; - var additionalClassPaths = ModUtils.moduleProperties(product, "additionalClassPaths"); + var additionalClassPaths = getModuleProperty(product, "additionalClassPaths", overrides); if (additionalClassPaths) classPaths = classPaths.concat(additionalClassPaths); for (i in inputs["java.jar"]) @@ -128,34 +141,95 @@ function javacArguments(product, inputs) { ]; if (supportsGeneratedNativeHeaderFiles(product)) args.push("-h", product.buildDirectory); - var runtimeVersion = ModUtils.moduleProperty(product, "runtimeVersion"); + var runtimeVersion = getModuleProperty(product, "runtimeVersion", overrides); if (runtimeVersion) args.push("-target", runtimeVersion); - var languageVersion = ModUtils.moduleProperty(product, "languageVersion"); + var languageVersion = getModuleProperty(product, "languageVersion", overrides); if (languageVersion) args.push("-source", languageVersion); - var bootClassPaths = ModUtils.moduleProperties(product, "bootClassPaths"); + var bootClassPaths = getModuleProperties(product, "bootClassPaths", overrides); if (bootClassPaths && bootClassPaths.length > 0) args.push("-bootclasspath", bootClassPaths.join(pathListSeparator)); - if (!ModUtils.moduleProperty(product, "enableWarnings")) + if (!getModuleProperty(product, "enableWarnings", overrides)) args.push("-nowarn"); - if (ModUtils.moduleProperty(product, "warningsAsErrors")) + if (getModuleProperty(product, "warningsAsErrors", overrides)) args.push("-Werror"); - var otherFlags = ModUtils.moduleProperty(product, "additionalCompilerFlags") + var otherFlags = getModuleProperty(product, "additionalCompilerFlags", overrides); if (otherFlags) args = args.concat(otherFlags); - for (i = 0; i < inputs["java.java"].length; ++i) + for (i in inputs["java.java"]) args.push(inputs["java.java"][i].filePath); + for (i in inputs["java.java-internal"]) + args.push(inputs["java.java-internal"][i].filePath); return args; } -function outputArtifacts(product, inputs) { - if (!File.exists(FileInfo.joinPaths(product.moduleProperty("qbs", "libexecPath"), - "qbs-javac-scan.jar"))) { - throw "Qbs was built without Java support. Rebuild Qbs with CONFIG+=qbs_enable_java " + - "(qmake) or project.enableJava:true (self hosted build)"; +/** + * Returns a list of fully qualified Java class names for the compiler helper tool. + * + * @param type @c java to return names of sources, @c to return names of compiled classes + */ +function helperFullyQualifiedNames(type) { + var names = [ + "io/qt/qbs/Artifact", + "io/qt/qbs/ArtifactListJsonWriter", + "io/qt/qbs/ArtifactListTextWriter", + "io/qt/qbs/ArtifactListWriter", + "io/qt/qbs/ArtifactListXmlWriter", + "io/qt/qbs/tools/JavaCompilerScannerTool", + "io/qt/qbs/tools/utils/JavaCompilerOptions", + "io/qt/qbs/tools/utils/JavaCompilerScanner", + "io/qt/qbs/tools/utils/JavaCompilerScanner$1", + "io/qt/qbs/tools/utils/NullFileObject", + "io/qt/qbs/tools/utils/NullFileObject$1", + "io/qt/qbs/tools/utils/NullFileObject$2", + "io/qt/qbs/tools/utils/NullFileObject$3", + "io/qt/qbs/tools/utils/NullFileObject$4" + ]; + if (type === "java") { + return names.filter(function (name) { + return !name.contains("$"); + }); + } else if (type === "class") { + return names; } +} +function helperOutputArtifacts(product) { + return helperFullyQualifiedNames("class").map(function (name) { + return { + filePath: FileInfo.joinPaths(ModUtils.moduleProperty(product, "internalClassFilesDir"), + name + ".class"), + fileTags: ["java.class-internal"] + }; + }); +} + +function helperOverrideArgs(product, tool) { + var overrides = {}; + if (tool === "javac") { + // Build the helper tool with the same source and target version as the JDK it's being + // compiled with. Both are irrelevant here since the resulting tool will only be run + // with the same JDK as it was built with, and we know in advance the source is + // compatible with all Java language versions from 1.6 and above. + var jdkVersion = [ModUtils.moduleProperty(product, "compilerVersionMajor"), + ModUtils.moduleProperty(product, "compilerVersionMinor")].join("."); + overrides["languageVersion"] = jdkVersion; + overrides["runtimeVersion"] = jdkVersion; + + // Build the helper tool's class files separately from the actual product's class files + overrides["classFilesDir"] = ModUtils.moduleProperty(product, "internalClassFilesDir"); + } + + // Inject the current JDK's runtime classes into the boot class path when building/running the + // dependency scanner. This is normally not necessary but is important for Android platforms + // where android.jar is the only JAR on the boot classpath and JSR 199 is unavailable. + overrides["bootClassPaths"] = [ModUtils.moduleProperty(product, "runtimeJarPath")].concat( + ModUtils.moduleProperties(product, "bootClassPaths")); + return overrides; +} + +function outputArtifacts(product, inputs) { // We need to ensure that the output directory is created first, because the Java compiler // internally checks that it is present before performing any actions File.makePath(ModUtils.moduleProperty(product, "classFilesDir")); @@ -163,13 +237,14 @@ function outputArtifacts(product, inputs) { var process; try { process = new Process(); - process.exec(product.moduleProperty("java", "interpreterFilePath"), ["-jar", - FileInfo.joinPaths(product.moduleProperty("qbs", "libexecPath"), - "qbs-javac-scan.jar"), - "--output-format", "json"] - .concat(javacArguments(product, inputs)), true); + process.setWorkingDirectory( + FileInfo.joinPaths(ModUtils.moduleProperty(product, "internalClassFilesDir"))); + process.exec(ModUtils.moduleProperty(product, "interpreterFilePath"), + ["io/qt/qbs/tools/JavaCompilerScannerTool", "--output-format", "json"] + .concat(javacArguments(product, inputs, helperOverrideArgs(product))), true); return JSON.parse(process.readStdOut()); } finally { - process.close(); + if (process) + process.close(); } } diff --git a/src/libexec/libexec.pro b/src/libexec/libexec.pro index f1044a609..967108504 100644 --- a/src/libexec/libexec.pro +++ b/src/libexec/libexec.pro @@ -1,6 +1 @@ TEMPLATE = subdirs - -qbs_enable_java { - SUBDIRS += \ - qbs-javac-scan -} diff --git a/src/libexec/libexec.qbs b/src/libexec/libexec.qbs index f132925e2..489864a26 100644 --- a/src/libexec/libexec.qbs +++ b/src/libexec/libexec.qbs @@ -2,6 +2,5 @@ import qbs Project { references: [ - "qbs-javac-scan/qbs-javac-scan.qbs" ] } diff --git a/src/libexec/qbs-javac-scan/qbs-javac-scan.pro b/src/libexec/qbs-javac-scan/qbs-javac-scan.pro deleted file mode 100644 index 7c9283776..000000000 --- a/src/libexec/qbs-javac-scan/qbs-javac-scan.pro +++ /dev/null @@ -1,82 +0,0 @@ -include(../libexec.pri) - -TARGET = qbs-javac-scan - -PATHPREFIX = $$PWD/io/qt/qbs/ - -JAVACLASSPATH += $$PWD -JAVASOURCES += \ - $$PATHPREFIX/Artifact.java \ - $$PATHPREFIX/ArtifactListJsonWriter.java \ - $$PATHPREFIX/ArtifactListTextWriter.java \ - $$PATHPREFIX/ArtifactListWriter.java \ - $$PATHPREFIX/ArtifactListXmlWriter.java \ - $$PATHPREFIX/tools/JavaCompilerScannerTool.java \ - $$PATHPREFIX/tools/utils/JavaCompilerOptions.java \ - $$PATHPREFIX/tools/utils/JavaCompilerScanner.java \ - $$PATHPREFIX/tools/utils/NullFileObject.java - -JAVAMAINCLASS = io.qt.qbs.tools.JavaCompilerScannerTool - -# from mkspecs/features/java.prf -TEMPLATE = lib - -CLASS_DIR = classes -CLASS_DIR_MARKER = classes.marker -CLASS_DIR_PREFIX = $$CLASS_DIR/io/qt/qbs - -CONFIG -= qt - -# Without these, qmake adds a name prefix and versioning postfixes (as well as file -# links) to the target. This is hardcoded in the qmake code, so for now we use -# the plugin configs to get what we want. -CONFIG += plugin no_plugin_name_prefix - -javac.input = JAVASOURCES -javac.output = $$CLASS_DIR_MARKER -javac.clean = \ - $$shell_path($$CLASS_DIR_PREFIX/Artifact.class) \ - $$shell_path($$CLASS_DIR_PREFIX/ArtifactListJsonWriter.class) \ - $$shell_path($$CLASS_DIR_PREFIX/ArtifactListWriter.class) \ - $$shell_path($$CLASS_DIR_PREFIX/ArtifactListTextWriter.class) \ - $$shell_path($$CLASS_DIR_PREFIX/ArtifactListXmlWriter.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/JavaCompilerScannerTool.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/JavaCompilerOptions.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/JavaCompilerScanner$1.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/JavaCompilerScanner.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/NullFileObject$1.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/NullFileObject$2.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/NullFileObject$3.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/NullFileObject$4.class) \ - $$shell_path($$CLASS_DIR_PREFIX/tools/utils/NullFileObject.class) -javac.CONFIG += combine -javac.commands = javac -source 1.6 -target 1.6 -Xlint:unchecked -cp $$shell_quote($$system_path($$join(JAVACLASSPATH, $$DIRLIST_SEPARATOR))) -d $$shell_quote($$CLASS_DIR) ${QMAKE_FILE_IN} $$escape_expand(\\n\\t) \ - @echo Nothing to see here. Move along. > $$CLASS_DIR_MARKER -QMAKE_EXTRA_COMPILERS += javac - -mkpath($$absolute_path($$CLASS_DIR, $$OUT_PWD)) | error("Aborting.") - -# Disable all linker flags since we are overriding the regular linker -QMAKE_LFLAGS = -QMAKE_CFLAGS = -QMAKE_LFLAGS_CONSOLE = -QMAKE_LFLAGS_WINDOWS = -QMAKE_LFLAGS_DLL = -QMAKE_LFLAGS_DEBUG = -QMAKE_LFLAGS_RELEASE = -QMAKE_LFLAGS_RPATH = -QMAKE_LFLAGS_PLUGIN = -QMAKE_LIBS = -QMAKE_LIBS_OPENGL_ES2 = -QMAKE_LIBDIR = -QMAKE_EXTENSION_SHLIB = jar - -# nmake -QMAKE_LINK = jar -QMAKE_LFLAGS = cfe $(DESTDIR_TARGET) $$JAVAMAINCLASS -C $$CLASS_DIR . && "echo " - -# Demonstrate an excellent reason why qbs exists -QMAKE_LINK_O_FLAG = && "echo " - -# make -QMAKE_LINK_SHLIB_CMD = jar cfe $(TARGET) $$JAVAMAINCLASS -C $$CLASS_DIR . diff --git a/src/libexec/qbs-javac-scan/qbs-javac-scan.qbs b/src/libexec/qbs-javac-scan/qbs-javac-scan.qbs deleted file mode 100644 index dc9aab8f4..000000000 --- a/src/libexec/qbs-javac-scan/qbs-javac-scan.qbs +++ /dev/null @@ -1,19 +0,0 @@ -import qbs - -JavaJarFile { - condition: project.enableJava - - property string entryPoint: "io.qt.qbs.tools.JavaCompilerScannerTool" - - destinationDirectory: project.libexecInstallDir - - Group { - fileTagsFilter: ["java.jar"] - qbs.install: true - qbs.installDir: project.libexecInstallDir - } - - files: [ - "io/qt/qbs/**/*.java" - ] -} diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp index 57a557dc8..e5ede4a5a 100644 --- a/tests/auto/blackbox/tst_blackbox.cpp +++ b/tests/auto/blackbox/tst_blackbox.cpp @@ -1507,13 +1507,13 @@ void TestBlackbox::java() QStringList classFiles1 = QStringList(classFiles) << "io/qt/qbs/HelloWorld" << "NoPackage"; for (int i = 0; i < classFiles1.count(); ++i) { QString &classFile = classFiles1[i]; - classFile = relativeProductBuildDir("class_collection") + "/classFiles/" + classFile = relativeProductBuildDir("class_collection") + "/classes/" + classFile + ".class"; QVERIFY2(regularFileExists(classFile), qPrintable(classFile)); } foreach (const QString &classFile, classFiles) { - const QString filePath = relativeProductBuildDir("jar_file") + "/classFiles/" + classFile + const QString filePath = relativeProductBuildDir("jar_file") + "/classes/" + classFile + ".class"; QVERIFY2(regularFileExists(filePath), qPrintable(filePath)); } |