diff options
author | Jake Petroules <jake.petroules@qt.io> | 2016-07-26 11:18:13 -0700 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2016-08-16 09:05:50 +0000 |
commit | f1cdcf709192b678935cf6a368aaddcce00e958b (patch) | |
tree | 155baf0c473e3401babac0a04ecf7ac0290c26e6 | |
parent | 0e123c1896b2601af4d2c097258a30706ca35f09 (diff) |
Automatically escape arguments in cpp.linkerFlags/platformLinkerFlags
[ChangeLog] Added automatic escaping of arguments passed to the
cpp.linkerFlags and cpp.platformLinkerFlags properties using the -Wl
or -Xlinker syntaxes. To revert to the old behavior,
Project.minimumQbsVersion can be set to a version lower than 1.6.
Change-Id: Ibe9d0fa3c9acf5062428ce1c3bc4d840e1cec4b3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | doc/reference/modules/cpp-module.qdoc | 4 | ||||
-rw-r--r-- | share/qbs/imports/qbs/ModUtils/utils.js | 12 | ||||
-rw-r--r-- | share/qbs/modules/Android/ndk/utils.js | 4 | ||||
-rw-r--r-- | share/qbs/modules/cpp/GenericGCC.qbs | 5 | ||||
-rw-r--r-- | share/qbs/modules/cpp/gcc.js | 28 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/android/teapot/teapot.qbs | 1 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata/properties-in-export-items/properties-in-export-items.qbs | 2 |
7 files changed, 46 insertions, 10 deletions
diff --git a/doc/reference/modules/cpp-module.qdoc b/doc/reference/modules/cpp-module.qdoc index fb7c15f47..a9c2464f3 100644 --- a/doc/reference/modules/cpp-module.qdoc +++ b/doc/reference/modules/cpp-module.qdoc @@ -267,7 +267,9 @@ \li \c{stringList} \li 1.0 \li undefined - \li Additional flags for the linker. + \li Additional flags for the linker. These flags should \e not be escaped using the -Wl or + -Xlinker syntaxes, as \QBS will do this automatically based on the linker being used. + See cpp.linkerMode for additional information. \row \li assemblerName \li \c{string} diff --git a/share/qbs/imports/qbs/ModUtils/utils.js b/share/qbs/imports/qbs/ModUtils/utils.js index 31321ac61..592365561 100644 --- a/share/qbs/imports/qbs/ModUtils/utils.js +++ b/share/qbs/imports/qbs/ModUtils/utils.js @@ -35,6 +35,18 @@ var Process = loadExtension("qbs.Process"); var TemporaryDir = loadExtension("qbs.TemporaryDir"); var Utilities = loadExtension("qbs.Utilities"); +function checkCompatibilityMode(project, minimumQbsVersion, message) { + if (Utilities.versionCompare(project.minimumQbsVersion || "1.3", minimumQbsVersion) < 0) { + console.warn([message || "", + "This message can be silenced by setting your Project's " + + "minimumQbsVersion to " + minimumQbsVersion + + " (and the new behavior will take effect)."].join(" ")); + return true; + } + + return false; +} + function artifactInstalledFilePath(artifact) { var relativeInstallDir = artifact.moduleProperty("qbs", "installDir"); var installPrefix = artifact.moduleProperty("qbs", "installPrefix"); diff --git a/share/qbs/modules/Android/ndk/utils.js b/share/qbs/modules/Android/ndk/utils.js index f5a4552d9..062730b9a 100644 --- a/share/qbs/modules/Android/ndk/utils.js +++ b/share/qbs/modules/Android/ndk/utils.js @@ -112,10 +112,10 @@ function commonCompilerFlags(buildVariant, abi, armMode) { } function commonLinkerFlags(abi) { - var flags = ["-Wl,-z,noexecstack", "-Wl,-z,relro", "-Wl,-z,now"]; + var flags = ["-z", "noexecstack", "-z", "relro", "-z", "now"]; if (abi === "armeabi-v7a") { - flags.push("-Wl,--fix-cortex-a8"); + flags.push("--fix-cortex-a8"); } return flags; diff --git a/share/qbs/modules/cpp/GenericGCC.qbs b/share/qbs/modules/cpp/GenericGCC.qbs index af079b3f5..82e3fec15 100644 --- a/share/qbs/modules/cpp/GenericGCC.qbs +++ b/share/qbs/modules/cpp/GenericGCC.qbs @@ -93,7 +93,10 @@ CppModule { + "which chooses either the C++ compiler, C compiler, or system linker specified by " + "the linkerName/linkerPath properties, depending on the type of object files " + "present on the linker command line. \"manual\" allows you to explicitly specify " - + "the linker using the linkerName/linkerPath properties." + + "the linker using the linkerName/linkerPath properties, and allows linker flags " + + "passed to the linkerFlags and platformLinkerFlags properties to be escaped " + + "manually (using -Wl or -Xlinker) instead of automatically based on the selected " + + "linker." } property string exportedSymbolsCheckMode: "ignore-undefined" diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index 3fb0d59e8..573b9c5ab 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -72,11 +72,14 @@ function useCompilerDriverLinker(product, inputs) { return linker === product.moduleProperty("cpp", "compilerPath"); } -function escapeLinkerFlags(product, inputs, linkerFlags) { +function escapeLinkerFlags(product, inputs, linkerFlags, allowEscape) { + if (allowEscape === undefined) + allowEscape = true; + if (!linkerFlags || linkerFlags.length === 0) return []; - if (useCompilerDriverLinker(product, inputs)) { + if (useCompilerDriverLinker(product, inputs) && allowEscape) { var sep = ","; var useXlinker = linkerFlags.some(function (f) { return f.contains(sep); }); if (useXlinker) { @@ -97,7 +100,7 @@ function escapeLinkerFlags(product, inputs, linkerFlags) { return linkerFlags; } -function linkerFlags(product, inputs, output) { +function linkerFlags(project, product, inputs, output) { var libraryPaths = ModUtils.moduleProperties(product, 'libraryPaths'); var dynamicLibraries = ModUtils.moduleProperties(product, "dynamicLibraries"); var staticLibraries = ModUtils.modulePropertiesFromArtifacts(product, inputs.staticlibrary, 'cpp', 'staticLibraries'); @@ -240,9 +243,22 @@ function linkerFlags(product, inputs, output) { if (isDarwin && ModUtils.moduleProperty(product, "warningLevel") === "none") args.push('-w'); + var allowEscape = !ModUtils.checkCompatibilityMode(project, "1.6", + "Enabling linker flags compatibility mode. cpp.linkerFlags and " + + "cpp.platformLinkerFlags escaping is handled automatically beginning in Qbs 1.6. " + + "When upgrading to Qbs 1.6, you should only pass raw linker flags to these " + + "properties; do not escape them using -Wl or -Xlinker. This allows Qbs to " + + "automatically supply the correct linker flags regardless of whether the " + + "linker chosen is the compiler driver or system linker (see the documentation for " + + "cpp.linkerMode for more information)."); + args = args.concat(configFlags(product, useCompilerDriverLinker(product, inputs))); - args = args.concat(ModUtils.moduleProperties(product, 'platformLinkerFlags')); - args = args.concat(ModUtils.moduleProperties(product, 'linkerFlags')); + args = args.concat(escapeLinkerFlags( + product, inputs, + ModUtils.moduleProperties(product, 'platformLinkerFlags'), allowEscape)); + args = args.concat(escapeLinkerFlags( + product, inputs, + ModUtils.moduleProperties(product, 'linkerFlags'), allowEscape)); args.push("-o", output.filePath); @@ -734,7 +750,7 @@ function prepareLinker(project, product, inputs, outputs, input, output) { } cmd = new Command(effectiveLinkerPath(product, inputs), - linkerFlags(product, inputs, primaryOutput)); + linkerFlags(project, product, inputs, primaryOutput)); cmd.description = 'linking ' + primaryOutput.fileName; cmd.highlight = 'linker'; cmd.responseFileUsagePrefix = '@'; diff --git a/tests/auto/blackbox/testdata/android/teapot/teapot.qbs b/tests/auto/blackbox/testdata/android/teapot/teapot.qbs index e9bc5b4a6..c1198b7e5 100644 --- a/tests/auto/blackbox/testdata/android/teapot/teapot.qbs +++ b/tests/auto/blackbox/testdata/android/teapot/teapot.qbs @@ -1,6 +1,7 @@ import qbs Project { + minimumQbsVersion: qbs.version property stringList architectures: ["arm64", "armv7a", "x86_64", "mips"] StaticLibrary { architectures: project.architectures diff --git a/tests/auto/blackbox/testdata/properties-in-export-items/properties-in-export-items.qbs b/tests/auto/blackbox/testdata/properties-in-export-items/properties-in-export-items.qbs index 25b075f65..efd840907 100644 --- a/tests/auto/blackbox/testdata/properties-in-export-items/properties-in-export-items.qbs +++ b/tests/auto/blackbox/testdata/properties-in-export-items/properties-in-export-items.qbs @@ -1,6 +1,8 @@ import qbs Project { + minimumQbsVersion: "1.6" + Product { name: "dep" Export { |