diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-08-02 18:19:20 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-08-10 10:38:12 +0000 |
commit | 6464a075c5edfafb3a88bfc4097b3d5d9b9cdb28 (patch) | |
tree | f69681c5317c1b96de01d37077c0eee087dcbb3c /share/qbs | |
parent | d7715770c02d10593921ee5c3d3fd4c03a4f85d1 (diff) |
Enable the Application item to create Android apps
The formerly required AndroidApk item is no longer needed: We just tag
the APK file as an application and let the Application item pull in the
Android.sdk module for Android targets.
It is also possible to have native code directly in the Application
product; in that case, the multiplexed variants become dynamic libraries
and the APK file is built for the aggregate.
[ChangeLog] The AndroidApk item was deprecated, a normal Application
item can be used instead.
Change-Id: I04f5f3892f354ca9eb4f2da8055abcd8d072aba0
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'share/qbs')
-rw-r--r-- | share/qbs/imports/qbs/base/AndroidApk.qbs | 46 | ||||
-rw-r--r-- | share/qbs/imports/qbs/base/Application.qbs | 28 | ||||
-rw-r--r-- | share/qbs/imports/qbs/base/CppApplication.qbs | 1 | ||||
-rw-r--r-- | share/qbs/modules/Android/ndk/ndk.qbs | 3 | ||||
-rw-r--r-- | share/qbs/modules/Android/sdk/sdk.qbs | 67 | ||||
-rw-r--r-- | share/qbs/modules/Android/sdk/utils.js | 6 | ||||
-rw-r--r-- | share/qbs/modules/cpp/CppModule.qbs | 2 | ||||
-rw-r--r-- | share/qbs/modules/cpp/android-gcc.qbs | 8 |
8 files changed, 99 insertions, 62 deletions
diff --git a/share/qbs/imports/qbs/base/AndroidApk.qbs b/share/qbs/imports/qbs/base/AndroidApk.qbs index 1f123827d..5f86d8457 100644 --- a/share/qbs/imports/qbs/base/AndroidApk.qbs +++ b/share/qbs/imports/qbs/base/AndroidApk.qbs @@ -35,50 +35,4 @@ Product { type: ["android.apk"] qbs.targetPlatform: "android" Depends { name: "Android.sdk" } - - property string packageName: name - property bool automaticSources: true - property bool legacyLayout: false - - property path sourceSetDir: legacyLayout ? undefined - : FileInfo.joinPaths(sourceDirectory, "src/main") - property path resourcesDir: FileInfo.joinPaths(sourceSetDir, "res") - property path assetsDir: FileInfo.joinPaths(sourceSetDir, "assets") - property path sourcesDir: FileInfo.joinPaths(sourceSetDir, legacyLayout ? "src" : "java") - property path manifestFile: defaultManifestFile - - readonly property path defaultManifestFile: FileInfo.joinPaths(sourceSetDir, - "AndroidManifest.xml") - - Group { - name: "java sources" - condition: product.automaticSources - prefix: product.sourcesDir + '/' - files: "**/*.java" - } - - Group { - name: "android resources" - condition: product.automaticSources - fileTags: ["android.resources"] - prefix: product.resourcesDir + '/' - files: "**/*" - } - - Group { - name: "android assets" - condition: product.automaticSources - fileTags: ["android.assets"] - prefix: product.assetsDir + '/' - files: "**/*" - } - - Group { - name: "manifest" - condition: product.automaticSources - fileTags: ["android.manifest"] - files: manifestFile && manifestFile !== defaultManifestFile - ? [manifestFile] - : (File.exists(defaultManifestFile) ? [defaultManifestFile] : []) - } } diff --git a/share/qbs/imports/qbs/base/Application.qbs b/share/qbs/imports/qbs/base/Application.qbs index ddc824756..04d5d3feb 100644 --- a/share/qbs/imports/qbs/base/Application.qbs +++ b/share/qbs/imports/qbs/base/Application.qbs @@ -29,11 +29,31 @@ ****************************************************************************/ NativeBinary { - type: { - if (isForAndroid && !consoleApplication) - return ["dynamiclibrary", "android.nativelibrary"]; - return ["application"]; + type: ["application"] + + property bool usesNativeCode + + Depends { + // Note: If we are multiplexing, then this dependency is technically only needed in + // the aggregate. However, the user should not have to write the respective + // condition when assigning to properties of this module, so we load it + // regardless and turn off its rules for the native part of the build. + name: "Android.sdk" + condition: isForAndroid && !consoleApplication + } + Properties { + condition: isForAndroid && !consoleApplication && !usesNativeCode + multiplexByQbsProperties: [] + aggregate: false + } + Properties { + condition: isForAndroid && !consoleApplication && usesNativeCode + aggregate: true + multiplexedType: "android.nativelibrary" } + aggregate: base + multiplexByQbsProperties: base + multiplexedType: base installDir: isBundle ? "Applications" : "bin" diff --git a/share/qbs/imports/qbs/base/CppApplication.qbs b/share/qbs/imports/qbs/base/CppApplication.qbs index bc7ba50e6..86d2fc74a 100644 --- a/share/qbs/imports/qbs/base/CppApplication.qbs +++ b/share/qbs/imports/qbs/base/CppApplication.qbs @@ -30,5 +30,6 @@ Application { Depends { name: "cpp" } + usesNativeCode: true } diff --git a/share/qbs/modules/Android/ndk/ndk.qbs b/share/qbs/modules/Android/ndk/ndk.qbs index 5d4322731..a664a62bb 100644 --- a/share/qbs/modules/Android/ndk/ndk.qbs +++ b/share/qbs/modules/Android/ndk/ndk.qbs @@ -167,7 +167,8 @@ Module { + "ANDROID_NDK_ROOT environment variable to a valid " + "Android NDK location."); } - + if (product.aggregate && !product.multiplexConfigurationId) + return; var validator = new ModUtils.PropertyValidator("Android.ndk"); validator.setRequiredProperty("abi", abi); validator.setRequiredProperty("appStl", appStl); diff --git a/share/qbs/modules/Android/sdk/sdk.qbs b/share/qbs/modules/Android/sdk/sdk.qbs index 480e4f518..cb26b2ee0 100644 --- a/share/qbs/modules/Android/sdk/sdk.qbs +++ b/share/qbs/modules/Android/sdk/sdk.qbs @@ -59,6 +59,58 @@ Module { property int buildToolsVersionPatch: buildToolsVersionParts[2] property string platform: sdkProbe.platform + // Product-specific properties and files + property string packageName: product.name + property string apkBaseName: packageName + property bool automaticSources: true + property bool legacyLayout: false + property string sourceSetDir: legacyLayout + ? product.sourceDirectory + : FileInfo.joinPaths(product.sourceDirectory, "src/main") + property string resourcesDir: FileInfo.joinPaths(sourceSetDir, "res") + property string assetsDir: FileInfo.joinPaths(sourceSetDir, "assets") + property string sourcesDir: FileInfo.joinPaths(sourceSetDir, legacyLayout ? "src" : "java") + property string manifestFile: defaultManifestFile + readonly property string defaultManifestFile: FileInfo.joinPaths(sourceSetDir, + "AndroidManifest.xml") + + property bool _enableRules: !product.multiplexConfigurationId && !!packageName + + Group { + name: "java sources" + condition: Android.sdk.automaticSources + prefix: Android.sdk.sourcesDir + '/' + files: "**/*.java" + } + + Group { + name: "android resources" + condition: Android.sdk.automaticSources + fileTags: ["android.resources"] + prefix: Android.sdk.resourcesDir + '/' + files: "**/*" + } + + Group { + name: "android assets" + condition: Android.sdk.automaticSources + fileTags: ["android.assets"] + prefix: Android.sdk.assetsDir + '/' + files: "**/*" + } + + Group { + name: "manifest" + condition: Android.sdk.automaticSources + fileTags: ["android.manifest"] + files: Android.sdk.manifestFile + && Android.sdk.manifestFile !== Android.sdk.defaultManifestFile + ? [Android.sdk.manifestFile] + : (File.exists(Android.sdk.defaultManifestFile) + ? [Android.sdk.defaultManifestFile] : []) + } + + // Internal properties. property int platformVersion: { if (platform) { @@ -85,7 +137,7 @@ Module { "android.jar") property path generatedJavaFilesBaseDir: FileInfo.joinPaths(product.buildDirectory, "gen") property path generatedJavaFilesDir: FileInfo.joinPaths(generatedJavaFilesBaseDir, - (product.packageName || "").split('.').join('/')) + (packageName || "").split('.').join('/')) property string apkContentsDir: FileInfo.joinPaths(product.buildDirectory, "bin") property string debugKeyStorePath: FileInfo.joinPaths( Environment.getEnv(qbs.hostOS.contains("windows") @@ -155,6 +207,7 @@ Module { } Rule { + condition: _enableRules inputs: ["android.aidl"] Artifact { filePath: FileInfo.joinPaths(Utilities.getHash(input.filePath), @@ -171,6 +224,7 @@ Module { } Rule { + condition: _enableRules multiplex: true inputs: ["android.resources", "android.assets", "android.manifest"] @@ -194,8 +248,8 @@ Module { } Rule { + condition: _enableRules multiplex: true - condition: !!product.packageName Artifact { filePath: FileInfo.joinPaths(ModUtils.moduleProperty(product, "generatedJavaFilesDir"), @@ -210,7 +264,7 @@ Module { var debugValue = product.moduleProperty("qbs", "buildVariant") === "debug" ? "true" : "false"; var ofile = new TextFile(output.filePath, TextFile.WriteOnly); - ofile.writeLine("package " + product.packageName + ";") + ofile.writeLine("package " + product.Android.sdk.packageName + ";") ofile.writeLine("public final class BuildConfig {"); ofile.writeLine(" public final static boolean DEBUG = " + debugValue + ";"); ofile.writeLine("}"); @@ -221,6 +275,7 @@ Module { } Rule { + condition: _enableRules multiplex: true inputs: ["java.class"] inputsFromDependencies: ["java.jar"] @@ -232,6 +287,7 @@ Module { } Rule { + condition: _enableRules multiplex: true inputsFromDependencies: [ "android.gdbserver-info", "android.stl-info", "android.nativelibrary" @@ -288,6 +344,7 @@ Module { } Rule { + condition: _enableRules multiplex: true inputs: [ "android.resources", "android.assets", "android.manifest", @@ -295,8 +352,8 @@ Module { "android.nativelibrary-deployed", "android.keystore" ] Artifact { - filePath: product.targetName + ".apk" - fileTags: ["android.apk"] + filePath: product.Android.sdk.apkBaseName + ".apk" + fileTags: ["android.apk", "application"] } prepare: SdkUtils.prepareAaptPackage.apply(SdkUtils, arguments) } diff --git a/share/qbs/modules/Android/sdk/utils.js b/share/qbs/modules/Android/sdk/utils.js index 6d9fff65c..49b0ea786 100644 --- a/share/qbs/modules/Android/sdk/utils.js +++ b/share/qbs/modules/Android/sdk/utils.js @@ -137,11 +137,11 @@ function commonAaptPackageArgs(project, product, inputs, outputs, input, output, "-I", product.Android.sdk.androidJarFilePath]; var resources = inputs["android.resources"]; if (resources && resources.length) - args.push("-S", product.resourcesDir); + args.push("-S", product.Android.sdk.resourcesDir); if (product.qbs.buildVariant === "debug") args.push("--debug-mode"); - if (File.exists(product.assetsDir)) - args.push("-A", product.assetsDir); + if (File.exists(product.Android.sdk.assetsDir)) + args.push("-A", product.Android.sdk.assetsDir); return args; } diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index 27d03ad55..01b0f8af9 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -354,7 +354,7 @@ Module { property stringList targetDriverFlags property stringList targetLinkerFlags - property bool _skipAllChecks: false // Internal, for testing only. + property bool _skipAllChecks: false // Internal property bool validateTargetTriple: true diff --git a/share/qbs/modules/cpp/android-gcc.qbs b/share/qbs/modules/cpp/android-gcc.qbs index c546488d6..749fef37d 100644 --- a/share/qbs/modules/cpp/android-gcc.qbs +++ b/share/qbs/modules/cpp/android-gcc.qbs @@ -87,7 +87,7 @@ LinuxGCC { Group { name: "Android STL" - condition: product.cpp.sharedStlFilePath + condition: product.cpp.sharedStlFilePath && product.cpp.shouldLink files: product.cpp.sharedStlFilePath ? [product.cpp.sharedStlFilePath] : [] fileTags: ["android.unstripped-stl"] } @@ -210,6 +210,7 @@ LinuxGCC { endianness: "little" Rule { + condition: shouldLink inputs: ["android.unstripped-stl"] Artifact { filePath: FileInfo.joinPaths("stripped-libs", input.fileName); @@ -224,6 +225,7 @@ LinuxGCC { } Rule { + condition: shouldLink inputs: ["dynamiclibrary"] explicitlyDependsOn: ["android.stripped-stl"]; outputFileTags: ["android.nativelibrary", "android.gdbserver-info", "android.stl-info"] @@ -284,8 +286,10 @@ LinuxGCC { } } + _skipAllChecks: !shouldLink + validate: { - if (!_skipAllChecks) + if (_skipAllChecks) return; var baseValidator = new ModUtils.PropertyValidator("qbs"); baseValidator.addCustomValidator("architecture", targetArch, function (value) { |