From 4068328fdb9eb5b9d99b0e9f1866cb3f879274ec Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Wed, 16 Oct 2019 13:59:53 +0300 Subject: baremetal: Introduce new cpp::generate{Assembler|Compiler}ListingFiles This properties enables or disables generation of a compiler or assembler listing files. Reason why we need in this property is in that some compilers (e.g. KEIL C51) generates a listing files by default, that spams a project sources directory. So, we need to have a possibility e.g. to disable it or to generate to an output directory. This patch implements this feature for KEIL, IAR, SDCC compilers with the following restrictions: * IAR (8051, AVR, STM8, MSP430, ARM) - full support. * KEIL (8051) - full support. * KEIL (ARM) - has only one restriction in that a compiler does not support specifying of an output listing file name. It is possible to specify only an output listing directory. So, a listing file names will be a bit different than for other compilers (e.g. if a source file name is 'foo.c', then the listing file name will be 'foo.lst', instead of 'foo.c.lst'). * SDCC (8051, STM8) - seems, has not possibility to disable an auto-generated listing files. But it generates an output listing files to a right output directory with the object files. Besides, a listing files has a correct names (e.g. for the 'foo.c' file, the listing file will be 'foo.c.lst'). Change-Id: Ic3516101e69eed156cf71606a7144efc72d40204 Reviewed-by: Christian Kandeler --- doc/reference/modules/cpp-module.qdoc | 22 +++++++++++++ share/qbs/modules/cpp/CppModule.qbs | 12 +++++++ share/qbs/modules/cpp/iar.js | 40 ++++++++++++++++------- share/qbs/modules/cpp/iar.qbs | 10 +++--- share/qbs/modules/cpp/keil.js | 60 +++++++++++++++++++++++++++-------- share/qbs/modules/cpp/keil.qbs | 10 +++--- share/qbs/modules/cpp/sdcc.js | 10 ++++-- share/qbs/modules/cpp/sdcc.qbs | 4 +-- 8 files changed, 129 insertions(+), 39 deletions(-) diff --git a/doc/reference/modules/cpp-module.qdoc b/doc/reference/modules/cpp-module.qdoc index e70f2bf5a..4ef1e4e5b 100644 --- a/doc/reference/modules/cpp-module.qdoc +++ b/doc/reference/modules/cpp-module.qdoc @@ -1679,3 +1679,25 @@ \defaultvalue \c{false} */ + +/*! + \qmlproperty bool cpp::generateCompilerListingFiles + \since Qbs 1.15 + + \baremetalproperty + + Whether to auto-generate a compiler listing files. + + \defaultvalue \c{false} +*/ + +/*! + \qmlproperty bool cpp::generateAssemblerListingFiles + \since Qbs 1.15 + + \baremetalproperty + + Whether to auto-generate an assembler listing files. + + \defaultvalue \c{false} +*/ diff --git a/share/qbs/modules/cpp/CppModule.qbs b/share/qbs/modules/cpp/CppModule.qbs index 50ce59b95..efda896da 100644 --- a/share/qbs/modules/cpp/CppModule.qbs +++ b/share/qbs/modules/cpp/CppModule.qbs @@ -257,6 +257,18 @@ Module { description: "generate linker map file" } + property bool generateCompilerListingFiles: false + PropertyOptions { + name: "generateCompilerListingFiles" + description: "generate compiler listing files" + } + + property bool generateAssemblerListingFiles: false + PropertyOptions { + name: "generateAssemblerListingFiles" + description: "generate assembler listing files" + } + property bool positionIndependentCode: true PropertyOptions { name: "positionIndependentCode" diff --git a/share/qbs/modules/cpp/iar.js b/share/qbs/modules/cpp/iar.js index bff0739b1..fd6f993e4 100644 --- a/share/qbs/modules/cpp/iar.js +++ b/share/qbs/modules/cpp/iar.js @@ -339,13 +339,21 @@ function collectLibraryDependencies(product) { return result; } -function compilerOutputArtifacts(input) { - var obj = { +function compilerOutputArtifacts(input, useListing) { + var artifacts = []; + artifacts.push({ fileTags: ["obj"], filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + input.cpp.objectSuffix - }; - return [obj]; + }); + if (useListing) { + artifacts.push({ + fileTags: ["lst"], + filePath: Utilities.getHash(input.baseDir) + "/" + + input.fileName + ".lst" + }); + } + return artifacts; } function applicationLinkerOutputArtifacts(product) { @@ -374,9 +382,9 @@ function staticLibraryLinkerOutputArtifacts(product) { return [staticLib] } -function compilerFlags(project, product, input, output, explicitlyDependsOn) { +function compilerFlags(project, product, input, outputs, explicitlyDependsOn) { // Determine which C-language we're compiling. - var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags)); var args = []; @@ -384,7 +392,7 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { args.push(input.filePath); // Output. - args.push("-o", output.filePath); + args.push("-o", outputs.obj[0].filePath); // Defines. var allDefines = []; @@ -490,6 +498,10 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { break; } + // Listing files generation flag. + if (product.cpp.generateCompilerListingFiles) + args.push("-l", outputs.lst[0].filePath); + // Misc flags. args = args.concat(ModUtils.moduleProperty(input, "platformFlags"), ModUtils.moduleProperty(input, "flags"), @@ -499,9 +511,9 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { return args; } -function assemblerFlags(project, product, input, output, explicitlyDependsOn) { +function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) { // Determine which C-language we"re compiling - var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags)); var args = []; @@ -509,7 +521,7 @@ function assemblerFlags(project, product, input, output, explicitlyDependsOn) { args.push(input.filePath); // Output. - args.push("-o", output.filePath); + args.push("-o", outputs.obj[0].filePath); // Includes. var allIncludePaths = []; @@ -543,6 +555,10 @@ function assemblerFlags(project, product, input, output, explicitlyDependsOn) { break; } + // Listing files generation flag. + if (product.cpp.generateAssemblerListingFiles) + args.push("-l", outputs.lst[0].filePath); + // Misc flags. args = args.concat(ModUtils.moduleProperty(input, "platformFlags", tag), ModUtils.moduleProperty(input, "flags", tag), @@ -633,7 +649,7 @@ function archiverFlags(project, product, input, outputs) { } function prepareCompiler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { - var args = compilerFlags(project, product, input, output, explicitlyDependsOn); + var args = compilerFlags(project, product, input, outputs, explicitlyDependsOn); var compilerPath = input.cpp.compilerPath; var cmd = new Command(compilerPath, args); cmd.description = "compiling " + input.fileName; @@ -642,7 +658,7 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli } function prepareAssembler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { - var args = assemblerFlags(project, product, input, output, explicitlyDependsOn); + var args = assemblerFlags(project, product, input, outputs, explicitlyDependsOn); var assemblerPath = input.cpp.assemblerPath; var cmd = new Command(assemblerPath, args); cmd.description = "assembling " + input.fileName; diff --git a/share/qbs/modules/cpp/iar.qbs b/share/qbs/modules/cpp/iar.qbs index e006856bf..bc226389b 100644 --- a/share/qbs/modules/cpp/iar.qbs +++ b/share/qbs/modules/cpp/iar.qbs @@ -99,8 +99,9 @@ CppModule { Rule { id: assembler inputs: ["asm"] - outputFileTags: ["obj"] - outputArtifacts: IAR.compilerOutputArtifacts(input) + outputFileTags: ["obj", "lst"] + outputArtifacts: IAR.compilerOutputArtifacts( + input, input.cpp.generateAssemblerListingFiles) prepare: IAR.prepareAssembler.apply(IAR, arguments) } @@ -113,8 +114,9 @@ CppModule { id: compiler inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] - outputFileTags: ["obj"] - outputArtifacts: IAR.compilerOutputArtifacts(input) + outputFileTags: ["obj", "lst"] + outputArtifacts: IAR.compilerOutputArtifacts( + input, input.cpp.generateCompilerListingFiles) prepare: IAR.prepareCompiler.apply(IAR, arguments) } diff --git a/share/qbs/modules/cpp/keil.js b/share/qbs/modules/cpp/keil.js index dd73b375e..befcc5a33 100644 --- a/share/qbs/modules/cpp/keil.js +++ b/share/qbs/modules/cpp/keil.js @@ -328,13 +328,23 @@ function filterStdOutput(cmd) { }; } -function compilerOutputArtifacts(input) { - var obj = { +function compilerOutputArtifacts(input, useListing) { + var artifacts = []; + artifacts.push({ fileTags: ["obj"], filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + input.cpp.objectSuffix - }; - return [obj]; + }); + if (useListing) { + artifacts.push({ + fileTags: ["lst"], + filePath: Utilities.getHash(input.baseDir) + "/" + + (input.cpp.architecture === "mcs51" + ? input.fileName : input.baseName) + + ".lst" + }); + } + return artifacts; } function applicationLinkerOutputArtifacts(product) { @@ -364,9 +374,9 @@ function staticLibraryLinkerOutputArtifacts(product) { return [staticLib] } -function compilerFlags(project, product, input, output, explicitlyDependsOn) { +function compilerFlags(project, product, input, outputs, explicitlyDependsOn) { // Determine which C-language we're compiling. - var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags)); var args = []; var allDefines = []; @@ -394,7 +404,7 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { args.push(FileInfo.toWindowsSeparators(input.filePath)); // Output. - args.push("OBJECT (" + FileInfo.toWindowsSeparators(output.filePath) + ")"); + args.push("OBJECT (" + FileInfo.toWindowsSeparators(outputs.obj[0].filePath) + ")"); // Defines. if (allDefines.length > 0) @@ -433,12 +443,18 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { args.push("FARWARNING"); break; } + + // Listing files generation flag. + if (!product.cpp.generateCompilerListingFiles) + args.push("NOPRINT"); + else + args.push("PRINT(" + FileInfo.toWindowsSeparators(outputs.lst[0].filePath) + ")"); } else if (architecture === "arm") { // Input. args.push("-c", input.filePath); // Output. - args.push("-o", output.filePath); + args.push("-o", outputs.obj[0].filePath); // Defines. args = args.concat(allDefines.map(function(define) { return '-D' + define })); @@ -513,6 +529,12 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { if (enableRtti !== undefined) args.push(enableRtti ? "--rtti" : "--no_rtti"); } + + // Listing files generation flag. + if (product.cpp.generateCompilerListingFiles) { + args.push("--list"); + args.push("--list_dir", FileInfo.path(outputs.lst[0].filePath)); + } } // Misc flags. @@ -524,9 +546,9 @@ function compilerFlags(project, product, input, output, explicitlyDependsOn) { return args; } -function assemblerFlags(project, product, input, output, explicitlyDependsOn) { +function assemblerFlags(project, product, input, outputs, explicitlyDependsOn) { // Determine which C-language we're compiling - var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(output.fileTags)); + var tag = ModUtils.fileTagForTargetLanguage(input.fileTags.concat(outputs.obj[0].fileTags)); var args = []; var allDefines = []; @@ -554,7 +576,7 @@ function assemblerFlags(project, product, input, output, explicitlyDependsOn) { args.push(FileInfo.toWindowsSeparators(input.filePath)); // Output. - args.push("OBJECT (" + FileInfo.toWindowsSeparators(output.filePath) + ")"); + args.push("OBJECT (" + FileInfo.toWindowsSeparators(outputs.obj[0].filePath) + ")"); // Defines. if (allDefines.length > 0) @@ -572,12 +594,18 @@ function assemblerFlags(project, product, input, output, explicitlyDependsOn) { // Enable errors printing. args.push("EP"); + + // Listing files generation flag. + if (!product.cpp.generateAssemblerListingFiles) + args.push("NOPRINT"); + else + args.push("PRINT(" + FileInfo.toWindowsSeparators(outputs.lst[0].filePath) + ")"); } else if (architecture === "arm") { // Input. args.push(input.filePath); // Output. - args.push("-o", output.filePath); + args.push("-o", outputs.obj[0].filePath); // Defines. allDefines.forEach(function(define) { @@ -608,6 +636,10 @@ function assemblerFlags(project, product, input, output, explicitlyDependsOn) { var endianness = input.cpp.endianness; if (endianness) args.push((endianness === "little") ? "--littleend" : "--bigend"); + + // Listing files generation flag. + if (product.cpp.generateAssemblerListingFiles) + args.push("--list", outputs.lst[0].filePath); } // Misc flags. @@ -737,7 +769,7 @@ function archiverFlags(project, product, input, outputs) { } function prepareCompiler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { - var args = compilerFlags(project, product, input, output, explicitlyDependsOn); + var args = compilerFlags(project, product, input, outputs, explicitlyDependsOn); var compilerPath = input.cpp.compilerPath; var architecture = input.cpp.architecture; var cmd = new Command(compilerPath, args); @@ -750,7 +782,7 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli function prepareAssembler(project, product, inputs, outputs, input, output, explicitlyDependsOn) { - var args = assemblerFlags(project, product, input, output, explicitlyDependsOn); + var args = assemblerFlags(project, product, input, outputs, explicitlyDependsOn); var assemblerPath = input.cpp.assemblerPath; var cmd = new Command(assemblerPath, args); cmd.description = "assembling " + input.fileName; diff --git a/share/qbs/modules/cpp/keil.qbs b/share/qbs/modules/cpp/keil.qbs index aca00eb99..67ea5e675 100644 --- a/share/qbs/modules/cpp/keil.qbs +++ b/share/qbs/modules/cpp/keil.qbs @@ -97,8 +97,9 @@ CppModule { Rule { id: assembler inputs: ["asm"] - outputFileTags: ["obj"] - outputArtifacts: KEIL.compilerOutputArtifacts(input) + outputFileTags: ["obj", "lst"] + outputArtifacts: KEIL.compilerOutputArtifacts( + input, input.cpp.generateAssemblerListingFiles) prepare: KEIL.prepareAssembler.apply(KEIL, arguments) } @@ -111,8 +112,9 @@ CppModule { id: compiler inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] - outputFileTags: ["obj"] - outputArtifacts: KEIL.compilerOutputArtifacts(input) + outputFileTags: ["obj", "lst"] + outputArtifacts: KEIL.compilerOutputArtifacts( + input, input.cpp.generateCompilerListingFiles) prepare: KEIL.prepareCompiler.apply(KEIL, arguments) } diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js index 5cd5fa960..70d0506b9 100644 --- a/share/qbs/modules/cpp/sdcc.js +++ b/share/qbs/modules/cpp/sdcc.js @@ -224,13 +224,17 @@ function compilerOutputArtifacts(input) { filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + input.cpp.objectSuffix }; + + // We need to use the asm_adb, lst, asm_src, asm_sym and rst_data + // artifacts without of any conditions. Because SDCC always generates + // it (and seems, this behavior can not be disabled for SDCC). var asm_adb = { fileTags: ["asm_adb"], filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + ".adb" }; - var asm_lst = { - fileTags: ["asm_lst"], + var lst = { + fileTags: ["lst"], filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + ".lst" }; @@ -249,7 +253,7 @@ function compilerOutputArtifacts(input) { filePath: Utilities.getHash(input.baseDir) + "/" + input.fileName + ".rst" }; - return [obj, asm_adb, asm_lst, asm_src, asm_sym, rst_data]; + return [obj, asm_adb, lst, asm_src, asm_sym, rst_data]; } function applicationLinkerOutputArtifacts(product) { diff --git a/share/qbs/modules/cpp/sdcc.qbs b/share/qbs/modules/cpp/sdcc.qbs index bf44b6f8e..ec763ba47 100644 --- a/share/qbs/modules/cpp/sdcc.qbs +++ b/share/qbs/modules/cpp/sdcc.qbs @@ -99,7 +99,7 @@ CppModule { Rule { id: assembler inputs: ["asm"] - outputFileTags: ["obj", "asm_adb", "asm_lst", "asm_src", "asm_sym", "rst_data"] + outputFileTags: ["obj", "asm_adb", "lst", "asm_src", "asm_sym", "rst_data"] outputArtifacts: SDCC.compilerOutputArtifacts(input) prepare: SDCC.prepareAssembler.apply(SDCC, arguments) } @@ -120,7 +120,7 @@ CppModule { id: compiler inputs: ["cpp", "c"] auxiliaryInputs: ["hpp"] - outputFileTags: ["obj", "asm_adb", "asm_lst", "asm_src", "asm_sym", "rst_data"] + outputFileTags: ["obj", "asm_adb", "lst", "asm_src", "asm_sym", "rst_data"] outputArtifacts: SDCC.compilerOutputArtifacts(input) prepare: SDCC.prepareCompiler.apply(SDCC, arguments) } -- cgit v1.2.3