From c7a1ec06313f85a9cf45b44f5940a952348d66d2 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Fri, 14 May 2021 16:01:41 +0300 Subject: baremetal: Move cpp-specific JS functions to cpp.js file Previous commit 79b9b02 added these functions to the ModUtils module, but seems a best place for these functions is cpp.js file. Change-Id: Id89b88e1865d003c1c7811220ed01f6d6becfba3 Reviewed-by: Christian Kandeler Reviewed-by: Ivan Komissarov --- share/qbs/imports/qbs/ModUtils/utils.js | 138 ------------------------------- share/qbs/modules/cpp/cpp.js | 142 ++++++++++++++++++++++++++++++++ share/qbs/modules/cpp/gcc.js | 2 +- share/qbs/modules/cpp/iar.js | 4 +- share/qbs/modules/cpp/iar.qbs | 18 ++-- share/qbs/modules/cpp/keil.js | 8 +- share/qbs/modules/cpp/keil.qbs | 18 ++-- share/qbs/modules/cpp/sdcc.js | 4 +- share/qbs/modules/cpp/sdcc.qbs | 18 ++-- 9 files changed, 178 insertions(+), 174 deletions(-) diff --git a/share/qbs/imports/qbs/ModUtils/utils.js b/share/qbs/imports/qbs/ModUtils/utils.js index 6e5a68178..33360a175 100644 --- a/share/qbs/imports/qbs/ModUtils/utils.js +++ b/share/qbs/imports/qbs/ModUtils/utils.js @@ -31,7 +31,6 @@ var Environment = require("qbs.Environment"); var File = require("qbs.File"); var FileInfo = require("qbs.FileInfo"); -var PathTools = require("qbs.PathTools"); var Process = require("qbs.Process"); var TemporaryDir = require("qbs.TemporaryDir"); var TextFile = require("qbs.TextFile"); @@ -637,140 +636,3 @@ function toJSLiteral(v) { return "undefined"; return JSON.stringify(v); } - -function extractMacros(output) { - var m = {}; - output.trim().split(/\r?\n/g).map(function (line) { - var prefix = "#define "; - if (!line.startsWith(prefix)) - return; - var index = line.indexOf(" ", prefix.length); - if (index !== -1) - m[line.substr(prefix.length, index - prefix.length)] = line.substr(index + 1); - }); - return m; -} - -function compilerOutputTags(needsListingFiles) { - var tags = ["obj"]; - if (needsListingFiles) - tags.push("lst"); - return tags; -} - -function applicationLinkerOutputTags(needsLinkerMapFile) { - var tags = ["application"]; - if (needsLinkerMapFile) - tags.push("mem_map"); - return tags; -} - -function staticLibraryLinkerOutputTags() { - return ["staticlibrary"]; -} - -function compilerOutputArtifacts(input, isCompilerArtifacts) { - var artifacts = []; - artifacts.push({ - fileTags: ["obj"], - filePath: Utilities.getHash(input.baseDir) + "/" - + input.fileName + input.cpp.objectSuffix - }); - if (isCompilerArtifacts && input.cpp.generateCompilerListingFiles) { - artifacts.push({ - fileTags: ["lst"], - filePath: Utilities.getHash(input.baseDir) + "/" - + input.fileName + input.cpp.compilerListingSuffix - }); - } else if (!isCompilerArtifacts && input.cpp.generateAssemblerListingFiles) { - artifacts.push({ - fileTags: ["lst"], - filePath: Utilities.getHash(input.baseDir) + "/" - + input.fileName + input.cpp.assemblerListingSuffix - }); - } - return artifacts; -} - -function applicationLinkerOutputArtifacts(product) { - var artifacts = [{ - fileTags: ["application"], - filePath: FileInfo.joinPaths( - product.destinationDirectory, - PathTools.applicationFilePath(product)) - }]; - if (product.cpp.generateLinkerMapFile) { - artifacts.push({ - fileTags: ["mem_map"], - filePath: FileInfo.joinPaths( - product.destinationDirectory, - product.targetName + product.cpp.linkerMapSuffix) - }); - } - return artifacts; -} - -function staticLibraryLinkerOutputArtifacts(product) { - var staticLib = { - fileTags: ["staticlibrary"], - filePath: FileInfo.joinPaths( - product.destinationDirectory, - PathTools.staticLibraryFilePath(product)) - }; - return [staticLib] -} - -function collectLibraryDependencies(product) { - var seen = {}; - var result = []; - - function addFilePath(filePath) { - result.push({ filePath: filePath }); - } - - function addArtifactFilePaths(dep, artifacts) { - if (!artifacts) - return; - var artifactFilePaths = artifacts.map(function(a) { return a.filePath; }); - artifactFilePaths.forEach(addFilePath); - } - - function addExternalStaticLibs(obj) { - if (!obj.cpp) - return; - function ensureArray(a) { - return (a instanceof Array) ? a : []; - } - function sanitizedModuleListProperty(obj, moduleName, propertyName) { - return ensureArray(ModUtils.sanitizedModuleProperty(obj, moduleName, propertyName)); - } - var externalLibs = [].concat( - sanitizedModuleListProperty(obj, "cpp", "staticLibraries")); - var staticLibrarySuffix = obj.moduleProperty("cpp", "staticLibrarySuffix"); - externalLibs.forEach(function(staticLibraryName) { - if (!staticLibraryName.endsWith(staticLibrarySuffix)) - staticLibraryName += staticLibrarySuffix; - addFilePath(staticLibraryName); - }); - } - - function traverse(dep) { - if (seen.hasOwnProperty(dep.name)) - return; - seen[dep.name] = true; - - if (dep.parameters.cpp && dep.parameters.cpp.link === false) - return; - - var staticLibraryArtifacts = dep.artifacts["staticlibrary"]; - if (staticLibraryArtifacts) { - dep.dependencies.forEach(traverse); - addArtifactFilePaths(dep, staticLibraryArtifacts); - addExternalStaticLibs(dep); - } - } - - product.dependencies.forEach(traverse); - addExternalStaticLibs(product); - return result; -} diff --git a/share/qbs/modules/cpp/cpp.js b/share/qbs/modules/cpp/cpp.js index 0e440bdb0..30b097d03 100644 --- a/share/qbs/modules/cpp/cpp.js +++ b/share/qbs/modules/cpp/cpp.js @@ -28,6 +28,11 @@ ** ****************************************************************************/ +var FileInfo = require("qbs.FileInfo"); +var ModUtils = require("qbs.ModUtils"); +var PathTools = require("qbs.PathTools"); +var Utilities = require("qbs.Utilities"); + function languageVersion(versionArray, knownValues, lang) { if (!versionArray) return undefined; @@ -44,3 +49,140 @@ function languageVersion(versionArray, knownValues, lang) { + "' from list of unknown " + lang + " version strings (" + versions + ")"); return version; } + +function extractMacros(output) { + var m = {}; + output.trim().split(/\r?\n/g).map(function (line) { + var prefix = "#define "; + if (!line.startsWith(prefix)) + return; + var index = line.indexOf(" ", prefix.length); + if (index !== -1) + m[line.substr(prefix.length, index - prefix.length)] = line.substr(index + 1); + }); + return m; +} + +function compilerOutputTags(needsListingFiles) { + var tags = ["obj"]; + if (needsListingFiles) + tags.push("lst"); + return tags; +} + +function applicationLinkerOutputTags(needsLinkerMapFile) { + var tags = ["application"]; + if (needsLinkerMapFile) + tags.push("mem_map"); + return tags; +} + +function staticLibraryLinkerOutputTags() { + return ["staticlibrary"]; +} + +function compilerOutputArtifacts(input, isCompilerArtifacts) { + var artifacts = []; + artifacts.push({ + fileTags: ["obj"], + filePath: Utilities.getHash(input.baseDir) + "/" + + input.fileName + input.cpp.objectSuffix + }); + if (isCompilerArtifacts && input.cpp.generateCompilerListingFiles) { + artifacts.push({ + fileTags: ["lst"], + filePath: Utilities.getHash(input.baseDir) + "/" + + input.fileName + input.cpp.compilerListingSuffix + }); + } else if (!isCompilerArtifacts && input.cpp.generateAssemblerListingFiles) { + artifacts.push({ + fileTags: ["lst"], + filePath: Utilities.getHash(input.baseDir) + "/" + + input.fileName + input.cpp.assemblerListingSuffix + }); + } + return artifacts; +} + +function applicationLinkerOutputArtifacts(product) { + var artifacts = [{ + fileTags: ["application"], + filePath: FileInfo.joinPaths( + product.destinationDirectory, + PathTools.applicationFilePath(product)) + }]; + if (product.cpp.generateLinkerMapFile) { + artifacts.push({ + fileTags: ["mem_map"], + filePath: FileInfo.joinPaths( + product.destinationDirectory, + product.targetName + product.cpp.linkerMapSuffix) + }); + } + return artifacts; +} + +function staticLibraryLinkerOutputArtifacts(product) { + var staticLib = { + fileTags: ["staticlibrary"], + filePath: FileInfo.joinPaths( + product.destinationDirectory, + PathTools.staticLibraryFilePath(product)) + }; + return [staticLib] +} + +function collectLibraryDependencies(product) { + var seen = {}; + var result = []; + + function addFilePath(filePath) { + result.push({ filePath: filePath }); + } + + function addArtifactFilePaths(dep, artifacts) { + if (!artifacts) + return; + var artifactFilePaths = artifacts.map(function(a) { return a.filePath; }); + artifactFilePaths.forEach(addFilePath); + } + + function addExternalStaticLibs(obj) { + if (!obj.cpp) + return; + function ensureArray(a) { + return (a instanceof Array) ? a : []; + } + function sanitizedModuleListProperty(obj, moduleName, propertyName) { + return ensureArray(ModUtils.sanitizedModuleProperty(obj, moduleName, propertyName)); + } + var externalLibs = [].concat( + sanitizedModuleListProperty(obj, "cpp", "staticLibraries")); + var staticLibrarySuffix = obj.moduleProperty("cpp", "staticLibrarySuffix"); + externalLibs.forEach(function(staticLibraryName) { + if (!staticLibraryName.endsWith(staticLibrarySuffix)) + staticLibraryName += staticLibrarySuffix; + addFilePath(staticLibraryName); + }); + } + + function traverse(dep) { + if (seen.hasOwnProperty(dep.name)) + return; + seen[dep.name] = true; + + if (dep.parameters.cpp && dep.parameters.cpp.link === false) + return; + + var staticLibraryArtifacts = dep.artifacts["staticlibrary"]; + if (staticLibraryArtifacts) { + dep.dependencies.forEach(traverse); + addArtifactFilePaths(dep, staticLibraryArtifacts); + addExternalStaticLibs(dep); + } + } + + product.dependencies.forEach(traverse); + addExternalStaticLibs(product); + return result; +} diff --git a/share/qbs/modules/cpp/gcc.js b/share/qbs/modules/cpp/gcc.js index 775c06a31..51a8ee64a 100644 --- a/share/qbs/modules/cpp/gcc.js +++ b/share/qbs/modules/cpp/gcc.js @@ -1446,7 +1446,7 @@ function dumpMacros(env, compilerFilePath, args, nullDevice, tag) { p.exec(compilerFilePath, (args || []).concat(["-Wp,-dM", "-E", "-x", languageName(tag || "c") , nullDevice]), true); - return ModUtils.extractMacros(p.readStdOut()); + return Cpp.extractMacros(p.readStdOut()); } finally { p.close(); } diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js index ad971ed6c..2d6c36db1 100644 --- a/share/qbs/modules/cpp/iar.js +++ b/share/qbs/modules/cpp/iar.js @@ -507,7 +507,7 @@ function dumpMacros(compilerFilePath, tag) { var p = new Process(); p.exec(compilerFilePath, args, true); var outFile = new TextFile(outFilePath, TextFile.ReadOnly); - return ModUtils.extractMacros(outFile.readAll()); + return Cpp.extractMacros(outFile.readAll()); } function dumpCompilerIncludePaths(compilerFilePath, tag) { @@ -774,7 +774,7 @@ function linkerFlags(project, product, inputs, outputs) { allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths); // Library dependencies. - var libraryDependencies = ModUtils.collectLibraryDependencies(product); + var libraryDependencies = Cpp.collectLibraryDependencies(product); if (libraryDependencies) args = args.concat(libraryDependencies.map(function(dep) { return dep.filePath })); diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs index e2241cc55..787ffa2cf 100644 --- a/share/qbs/modules/cpp/iar.qbs +++ b/share/qbs/modules/cpp/iar.qbs @@ -31,10 +31,10 @@ import qbs 1.0 import qbs.File import qbs.FileInfo -import qbs.ModUtils import qbs.PathTools import qbs.Probes import qbs.Utilities +import "cpp.js" as Cpp import "iar.js" as IAR CppModule { @@ -98,8 +98,8 @@ CppModule { Rule { id: assembler inputs: ["asm"] - outputFileTags: ModUtils.compilerOutputTags(generateAssemblerListingFiles) - outputArtifacts: ModUtils.compilerOutputArtifacts(input, false) + outputFileTags: Cpp.compilerOutputTags(generateAssemblerListingFiles) + outputArtifacts: Cpp.compilerOutputArtifacts(input, false) prepare: IAR.prepareAssembler.apply(IAR, arguments) } @@ -112,8 +112,8 @@ CppModule { id: compiler inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] - outputFileTags: ModUtils.compilerOutputTags(generateCompilerListingFiles) - outputArtifacts: ModUtils.compilerOutputArtifacts(input, true) + outputFileTags: Cpp.compilerOutputTags(generateCompilerListingFiles) + outputArtifacts: Cpp.compilerOutputArtifacts(input, true) prepare: IAR.prepareCompiler.apply(IAR, arguments) } @@ -122,8 +122,8 @@ CppModule { multiplex: true inputs: ["obj", "linkerscript"] inputsFromDependencies: ["staticlibrary"] - outputFileTags: ModUtils.applicationLinkerOutputTags(generateLinkerMapFile) - outputArtifacts: ModUtils.applicationLinkerOutputArtifacts(product) + outputFileTags: Cpp.applicationLinkerOutputTags(generateLinkerMapFile) + outputArtifacts: Cpp.applicationLinkerOutputArtifacts(product) prepare: IAR.prepareLinker.apply(IAR, arguments) } @@ -132,8 +132,8 @@ CppModule { multiplex: true inputs: ["obj"] inputsFromDependencies: ["staticlibrary"] - outputFileTags: ModUtils.staticLibraryLinkerOutputTags() - outputArtifacts: ModUtils.staticLibraryLinkerOutputArtifacts(product) + outputFileTags: Cpp.staticLibraryLinkerOutputTags() + outputArtifacts: Cpp.staticLibraryLinkerOutputArtifacts(product) prepare: IAR.prepareArchiver.apply(IAR, arguments) } } diff --git a/share/qbs/modules/cpp/keil.js b/share/qbs/modules/cpp/keil.js index e1876e0b2..8b0902d6f 100644 --- a/share/qbs/modules/cpp/keil.js +++ b/share/qbs/modules/cpp/keil.js @@ -436,7 +436,7 @@ function dumpArmCCCompilerMacros(compilerFilePath, tag, nullDevice) { var p = new Process(); p.exec(compilerFilePath, args, false); - return ModUtils.extractMacros(p.readStdOut()); + return Cpp.extractMacros(p.readStdOut()); } function dumpArmClangCompilerMacros(compilerFilePath, tag, nullDevice) { @@ -444,7 +444,7 @@ function dumpArmClangCompilerMacros(compilerFilePath, tag, nullDevice) { "-x", ((tag === "cpp") ? "c++" : "c"), nullDevice ]; var p = new Process(); p.exec(compilerFilePath, args, false); - return ModUtils.extractMacros(p.readStdOut()); + return Cpp.extractMacros(p.readStdOut()); } function dumpMacros(compilerFilePath, tag, nullDevice) { @@ -886,7 +886,7 @@ function linkerFlags(project, product, inputs, outputs) { inputs.obj.map(function(obj) { allObjectPaths.push(obj.filePath) }); // Library dependencies. - var libraryObjects = ModUtils.collectLibraryDependencies(product); + var libraryObjects = Cpp.collectLibraryDependencies(product); 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 @@ -927,7 +927,7 @@ function linkerFlags(project, product, inputs, outputs) { args.push("--userlibpath=" + libraryPaths.join(",")); // Library dependencies. - var libraryDependencies = ModUtils.collectLibraryDependencies(product); + var libraryDependencies = Cpp.collectLibraryDependencies(product); args = args.concat(libraryDependencies.map(function(dep) { return dep.filePath; })); // Debug information flag. diff --git a/share/qbs/modules/cpp/keil.qbs b/share/qbs/modules/cpp/keil.qbs index 94c575b20..ba883c515 100644 --- a/share/qbs/modules/cpp/keil.qbs +++ b/share/qbs/modules/cpp/keil.qbs @@ -31,8 +31,8 @@ import qbs 1.0 import qbs.File import qbs.FileInfo -import qbs.ModUtils import qbs.Probes +import "cpp.js" as Cpp import "keil.js" as KEIL CppModule { @@ -102,8 +102,8 @@ CppModule { Rule { id: assembler inputs: ["asm"] - outputFileTags: ModUtils.compilerOutputTags(generateAssemblerListingFiles) - outputArtifacts: ModUtils.compilerOutputArtifacts(input, false) + outputFileTags: Cpp.compilerOutputTags(generateAssemblerListingFiles) + outputArtifacts: Cpp.compilerOutputArtifacts(input, false) prepare: KEIL.prepareAssembler.apply(KEIL, arguments) } @@ -116,8 +116,8 @@ CppModule { id: compiler inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] - outputFileTags: ModUtils.compilerOutputTags(generateCompilerListingFiles) - outputArtifacts: ModUtils.compilerOutputArtifacts(input, true) + outputFileTags: Cpp.compilerOutputTags(generateCompilerListingFiles) + outputArtifacts: Cpp.compilerOutputArtifacts(input, true) prepare: KEIL.prepareCompiler.apply(KEIL, arguments) } @@ -126,8 +126,8 @@ CppModule { multiplex: true inputs: ["obj", "linkerscript"] inputsFromDependencies: ["staticlibrary"] - outputFileTags: ModUtils.applicationLinkerOutputTags(generateLinkerMapFile) - outputArtifacts: ModUtils.applicationLinkerOutputArtifacts(product) + outputFileTags: Cpp.applicationLinkerOutputTags(generateLinkerMapFile) + outputArtifacts: Cpp.applicationLinkerOutputArtifacts(product) prepare: KEIL.prepareLinker.apply(KEIL, arguments) } @@ -136,8 +136,8 @@ CppModule { multiplex: true inputs: ["obj"] inputsFromDependencies: ["staticlibrary"] - outputFileTags: ModUtils.staticLibraryLinkerOutputTags() - outputArtifacts: ModUtils.staticLibraryLinkerOutputArtifacts(product) + outputFileTags: Cpp.staticLibraryLinkerOutputTags() + outputArtifacts: Cpp.staticLibraryLinkerOutputArtifacts(product) prepare: KEIL.prepareArchiver.apply(KEIL, arguments) } } diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js index 93566a0df..804ae534e 100644 --- a/share/qbs/modules/cpp/sdcc.js +++ b/share/qbs/modules/cpp/sdcc.js @@ -126,7 +126,7 @@ function dumpMacros(compilerFilePath, architecture) { var p = new Process(); p.exec(compilerFilePath, args, true); - return ModUtils.extractMacros(p.readStdOut()); + return Cpp.extractMacros(p.readStdOut()); } function dumpDefaultPaths(compilerFilePath, architecture) { @@ -396,7 +396,7 @@ function linkerFlags(project, product, inputs, outputs) { if (distributionLibraryPaths) allLibraryPaths = allLibraryPaths.uniqueConcat(distributionLibraryPaths); - var libraryDependencies = ModUtils.collectLibraryDependencies(product); + var libraryDependencies = Cpp.collectLibraryDependencies(product); var escapableLinkerFlags = []; diff --git a/share/qbs/modules/cpp/sdcc.qbs b/share/qbs/modules/cpp/sdcc.qbs index 1f0df82bf..2013fae4c 100644 --- a/share/qbs/modules/cpp/sdcc.qbs +++ b/share/qbs/modules/cpp/sdcc.qbs @@ -31,8 +31,8 @@ import qbs 1.0 import qbs.File import qbs.FileInfo -import qbs.ModUtils import qbs.Probes +import "cpp.js" as Cpp import "sdcc.js" as SDCC CppModule { @@ -100,9 +100,9 @@ CppModule { id: assembler inputs: ["asm"] outputFileTags: SDCC.extraCompilerOutputTags().concat( - ModUtils.compilerOutputTags(generateAssemblerListingFiles)) + Cpp.compilerOutputTags(generateAssemblerListingFiles)) outputArtifacts: SDCC.extraCompilerOutputArtifacts(input).concat( - ModUtils.compilerOutputArtifacts(input, false)) + Cpp.compilerOutputArtifacts(input, false)) prepare: SDCC.prepareAssembler.apply(SDCC, arguments) } @@ -116,9 +116,9 @@ CppModule { inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] outputFileTags: SDCC.extraCompilerOutputTags().concat( - ModUtils.compilerOutputTags(generateCompilerListingFiles)) + Cpp.compilerOutputTags(generateCompilerListingFiles)) outputArtifacts: SDCC.extraCompilerOutputArtifacts(input).concat( - ModUtils.compilerOutputArtifacts(input, true)) + Cpp.compilerOutputArtifacts(input, true)) prepare: SDCC.prepareCompiler.apply(SDCC, arguments) } @@ -128,9 +128,9 @@ CppModule { inputs: ["obj", "linkerscript"] inputsFromDependencies: ["staticlibrary"] outputFileTags: SDCC.extraApplicationLinkerOutputTags().concat( - ModUtils.applicationLinkerOutputTags(generateLinkerMapFile)) + Cpp.applicationLinkerOutputTags(generateLinkerMapFile)) outputArtifacts: SDCC.extraApplicationLinkerOutputArtifacts(product).concat( - ModUtils.applicationLinkerOutputArtifacts(product)) + Cpp.applicationLinkerOutputArtifacts(product)) prepare: SDCC.prepareLinker.apply(SDCC, arguments) } @@ -139,8 +139,8 @@ CppModule { multiplex: true inputs: ["obj"] inputsFromDependencies: ["staticlibrary"] - outputFileTags: ModUtils.staticLibraryLinkerOutputTags() - outputArtifacts: ModUtils.staticLibraryLinkerOutputArtifacts(product) + outputFileTags: Cpp.staticLibraryLinkerOutputTags() + outputArtifacts: Cpp.staticLibraryLinkerOutputArtifacts(product) prepare: SDCC.prepareArchiver.apply(SDCC, arguments) } } -- cgit v1.2.3