diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2021-03-31 16:33:32 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2021-04-05 15:04:55 +0000 |
commit | af7d67396edadebd3a1f38623453f1af5cae440c (patch) | |
tree | d1a6d0817078e1e0c4627994d505375ceb427deb | |
parent | e0266ffc85058d371e18b0ae8ea49585697ceb59 (diff) |
baremetal: Pass externalStaticLibraries() test for KEIL C51/C251/C166
Toolchains C51, C251, C166 do not support configuring library
search paths to link. They support linking with libraries
specified with full absolute paths to them.
To work around this we supplement the absolute library paths
using the cpp.libraryPaths property, if the library is specified
without an absolute or relative path.
Change-Id: Ic11fd8b87356b3a07ba5fd5c9763c8df39d0d4ac
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r-- | share/qbs/modules/cpp/keil.js | 29 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata-baremetal/external-static-libraries/external-static-libraries.qbs | 14 |
2 files changed, 20 insertions, 23 deletions
diff --git a/share/qbs/modules/cpp/keil.js b/share/qbs/modules/cpp/keil.js index 567b0ddd3..372b08e4b 100644 --- a/share/qbs/modules/cpp/keil.js +++ b/share/qbs/modules/cpp/keil.js @@ -970,24 +970,37 @@ function disassemblerFlags(project, product, input, outputs, explicitlyDependsOn function linkerFlags(project, product, inputs, outputs) { var args = []; + // Library paths. + var libraryPaths = product.cpp.libraryPaths; + var architecture = product.qbs.architecture; if (isMcsArchitecture(architecture) || isC166Architecture(architecture)) { - // Note: The C51/256/166 linker does not distinguish an object files and + // Note: The C51, C251, or C166 linker does not distinguish an object files and // a libraries, it interpret all this stuff as an input objects, // so, we need to pass it together in one string. - var allObjectPaths = []; - function addObjectPath(obj) { - allObjectPaths.push(obj.filePath); - } // Inputs. if (inputs.obj) - inputs.obj.map(function(obj) { addObjectPath(obj) }); + inputs.obj.map(function(obj) { allObjectPaths.push(obj.filePath) }); // Library dependencies. var libraryObjects = collectLibraryDependencies(product); - libraryObjects.forEach(function(dep) { addObjectPath(dep); }) + allObjectPaths = allObjectPaths.concat(libraryObjects.map(function(lib) { + // Semi-intelligent handling the library paths. + // We need to add the full path prefix to the library file if this + // file is not absolute or not relative. Reason is that the C51, C251, + // and C166 linkers does not support the library paths. + var filePath = lib.filePath; + if (FileInfo.isAbsolutePath(filePath)) + return filePath; + for (var i = 0; i < libraryPaths.length; ++i) { + var fullPath = FileInfo.joinPaths(libraryPaths[i], filePath); + if (File.exists(fullPath)) + return fullPath; + } + return filePath; + })); // Add all input objects as arguments (application and library object files). if (allObjectPaths.length > 0) @@ -1009,8 +1022,6 @@ function linkerFlags(project, product, inputs, outputs) { // Output. args.push("--output", outputs.application[0].filePath); - // Library paths. - var libraryPaths = product.cpp.libraryPaths; if (libraryPaths) args.push("--userlibpath=" + libraryPaths.join(",")); diff --git a/tests/auto/blackbox/testdata-baremetal/external-static-libraries/external-static-libraries.qbs b/tests/auto/blackbox/testdata-baremetal/external-static-libraries/external-static-libraries.qbs index 6fbbb8647..fffb6a03d 100644 --- a/tests/auto/blackbox/testdata-baremetal/external-static-libraries/external-static-libraries.qbs +++ b/tests/auto/blackbox/testdata-baremetal/external-static-libraries/external-static-libraries.qbs @@ -2,20 +2,6 @@ import "../BareMetalApplication.qbs" as BareMetalApplication import "../BareMetalStaticLibrary.qbs" as BareMetalStaticLibrary Project { - condition: { - // The KEIL C51/C251/C166 toolchains support only a - // full paths to the external libraries. - if (qbs.toolchainType === "keil") { - if (qbs.architecture === "mcs51" - || qbs.architecture === "mcs251" - || qbs.architecture === "c166") { - console.info("unsupported toolset: %%" - + qbs.toolchainType + "%%, %%" + qbs.architecture + "%%"); - return false; - } - } - return true; - } property string outputLibrariesDirectory: sourceDirectory + "/libs" BareMetalStaticLibrary { name: "lib-a" |