diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2021-04-08 17:17:03 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2021-04-12 06:36:42 +0000 |
commit | c3e10d620124f18452f0f059d3f3d2a4a7c632ae (patch) | |
tree | 84230dcd31658681ef5162e819327f9b147cf19d | |
parent | 4b5680cc16f5a190b98b7c0ed42bc43f8e9438b7 (diff) | |
download | qbs-c3e10d620124f18452f0f059d3f3d2a4a7c632ae.tar.gz |
baremetal: Fix generation of compiler listing files
... with custom extension for SDCC compiler.
The SDCC compiler always generates the listing files in the
format of 'module.c.lst', and there is no way to disable a
generation, or to specify a different name for the listing
file. In addition, we cannot change or delete the generated
listing file until the linking is complete (this is such a
feature of the SDCC compiler).
So, to turn off the listing file generation, or to specify
a custom listing file extension, we need to do the following
extra steps:
1. If the custom cpp.compilerListingSuffix property is set,
then we need to make a copy of the generated listing file
after the compilation completes. And then to delete the all
listing files with the '*.lst' extension after the linking
completes.
2. If the cpp.generateCompilerListingFiles property is disabled,
then we need to remove the all generated listing files with
the '*.lst' extension after the linking completes.
Change-Id: Ia235f7e2ebf88695e4648fb894624c7420968079
Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r-- | share/qbs/modules/cpp/sdcc.js | 59 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackboxbaremetal.cpp | 12 |
2 files changed, 52 insertions, 19 deletions
diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js index 8635d468b..1904f59fc 100644 --- a/share/qbs/modules/cpp/sdcc.js +++ b/share/qbs/modules/cpp/sdcc.js @@ -562,7 +562,7 @@ function buildLinkerMapFilePath(target, suffix) { // * https://sourceforge.net/p/sdcc/bugs/2970/ // We need to replace the '\r\n\' line endings with the'\n' line // endings for each generated object file. -function patchObjectFiles(project, product, inputs, outputs, input, output) { +function patchObjectFile(project, product, inputs, outputs, input, output) { var isWindows = input.qbs.hostOS.contains("windows"); if (isWindows && input.cpp.debugInformation) { var cmd = new JavaScriptCommand(); @@ -620,27 +620,48 @@ function renameLinkerMapFile(project, product, inputs, outputs, input, output) { } // It is a workaround which removes the generated listing files -// if it is disabled by cpp.generateCompilerListingFiles property. +// if it is disabled by cpp.generateCompilerListingFiles property +// or when the cpp.compilerListingSuffix differs with '.lst'. // Reason is that the SDCC compiler does not have an option to // disable generation for a listing files. Besides, the SDCC // compiler use this files and for the linking. So, we can to // remove a listing files only after the linking completes. function removeCompilerListingFiles(project, product, inputs, outputs, input, output) { - if (!product.cpp.generateCompilerListingFiles) { + var cmd = new JavaScriptCommand(); + cmd.objects = inputs.obj.map(function(a) { return a; }); + cmd.silent = true; + cmd.sourceCode = function() { + objects.forEach(function(object) { + if (!object.filePath.endsWith(".c" + object.cpp.objectSuffix)) + return; // Skip the assembler generated objects. + if (!object.cpp.generateCompilerListingFiles + || (object.cpp.compilerListingSuffix !== ".lst")) { + var listingPath = FileInfo.joinPaths(FileInfo.path(object.filePath), + object.completeBaseName + ".lst"); + File.remove(listingPath); + } + }) + }; + return cmd; +} + +// It is a workaround that duplicates the generated listing files +// but with desired names. The problem is that the SDCC compiler does +// not support an options to specify names for the generated listing +// files. At the same time, the compiler always generates the listing +// files in the form of 'module.c.lst', which makes it impossible to +// change the file suffix to a user-specified one. In addition, these +// files are also somehow used for linking. Thus, we can not rename them +// on the compiling stage. +function duplicateCompilerListingFile(project, product, inputs, outputs, input, output) { + if (input.cpp.generateCompilerListingFiles + && (input.cpp.compilerListingSuffix !== ".lst")) { var cmd = new JavaScriptCommand(); - cmd.objectPaths = inputs.obj.map(function(a) { return a.filePath; }); - cmd.objectSuffix = product.cpp.objectSuffix; + cmd.newListing = outputs.lst[0].filePath; + cmd.oldListing = FileInfo.joinPaths(FileInfo.path(outputs.lst[0].filePath), + outputs.lst[0].completeBaseName + ".lst"); cmd.silent = true; - cmd.sourceCode = function() { - objectPaths.forEach(function(objectPath) { - if (!objectPath.endsWith(".c" + objectSuffix)) - return; // Skip the assembler objects. - var listingPath = FileInfo.joinPaths( - FileInfo.path(objectPath), - FileInfo.completeBaseName(objectPath) + ".lst"); - File.remove(listingPath); - }); - }; + cmd.sourceCode = function() { File.copy(oldListing, newListing); }; return cmd; } } @@ -654,7 +675,11 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli cmd.highlight = "compiler"; cmds.push(cmd); - cmd = patchObjectFiles(project, product, inputs, outputs, input, output); + cmd = patchObjectFile(project, product, inputs, outputs, input, output); + if (cmd) + cmds.push(cmd); + + cmd = duplicateCompilerListingFile(project, product, inputs, outputs, input, output); if (cmd) cmds.push(cmd); @@ -670,7 +695,7 @@ function prepareAssembler(project, product, inputs, outputs, input, output, expl cmd.highlight = "compiler"; cmds.push(cmd); - cmd = patchObjectFiles(project, product, inputs, outputs, input, output); + cmd = patchObjectFile(project, product, inputs, outputs, input, output); if (cmd) cmds.push(cmd); diff --git a/tests/auto/blackbox/tst_blackboxbaremetal.cpp b/tests/auto/blackbox/tst_blackboxbaremetal.cpp index 467c95122..e0a068bc6 100644 --- a/tests/auto/blackbox/tst_blackboxbaremetal.cpp +++ b/tests/auto/blackbox/tst_blackboxbaremetal.cpp @@ -187,18 +187,23 @@ void TestBlackboxBareMetal::defines() void TestBlackboxBareMetal::compilerListingFiles_data() { QTest::addColumn<bool>("generateListing"); - QTest::newRow("do-not-generate-compiler-listing") << false; - QTest::newRow("generate-compiler-listing") << true; + QTest::addColumn<QString>("customListingSuffix"); + QTest::newRow("do-not-generate-compiler-listing") << false << ""; + QTest::newRow("generate-default-compiler-listing") << true << ""; + QTest::newRow("generate-custom-compiler-listing") << true << ".lll"; } void TestBlackboxBareMetal::compilerListingFiles() { QFETCH(bool, generateListing); + QFETCH(QString, customListingSuffix); QDir::setCurrent(testDataDir + "/compiler-listing"); rmDirR(relativeBuildDir()); QStringList args = {QStringLiteral("modules.cpp.generateCompilerListingFiles:%1") .arg(generateListing ? "true" : "false")}; + if (!customListingSuffix.isEmpty()) + args << QStringLiteral("modules.cpp.compilerListingSuffix:%1").arg(customListingSuffix); QCOMPARE(runQbs(QbsRunParameters("resolve", args)), 0); if (m_qbsStdout.contains("unsupported toolset:")) @@ -210,6 +215,9 @@ void TestBlackboxBareMetal::compilerListingFiles() if (!extractQuitedValue(m_qbsStdout, compilerListingSuffix)) QFAIL("Unable to extract current compiler listing suffix"); + if (!customListingSuffix.isEmpty()) + QCOMPARE(compilerListingSuffix, customListingSuffix); + QCOMPARE(runQbs(QbsRunParameters(args)), 0); const QString productBuildDir = relativeProductBuildDir("compiler-listing"); const QString hash = inputDirHash("."); |