aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2021-02-26 21:09:46 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2021-02-28 08:41:20 +0000
commitf6c55eb946d064fd0aacc8af0b68ad6d0db59e82 (patch)
treee93074248f11da199e0e3f00f8938515038cae07
parent316acdd4db8fcb788f5cbf54dad729820b65ca09 (diff)
baremetal: Patch *.rel files generated by SDCC compiler on windows host
... before linking. SDCC still has an bug on Windows where it generates the object files in the DOS format instead of Unix format, that leads to the linking errors: * https://sourceforge.net/p/sdcc/bugs/2970/ A workaround is to remove all CR characters from the object files, what was done in the previous fix in Qbs. But that solution does not work since the TextFile service forcibly adds the CP characters to the ends of lines on the Windows host. We need to use the BinaryFile service instead which operates with the RAW data. Change-Id: I09f44a707081de6af7300348e743b6076366dd2c Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com>
-rw-r--r--share/qbs/modules/cpp/sdcc.js60
1 files changed, 40 insertions, 20 deletions
diff --git a/share/qbs/modules/cpp/sdcc.js b/share/qbs/modules/cpp/sdcc.js
index 6f5fcc3d6..71ed22ffa 100644
--- a/share/qbs/modules/cpp/sdcc.js
+++ b/share/qbs/modules/cpp/sdcc.js
@@ -28,6 +28,7 @@
**
****************************************************************************/
+var BinaryFile = require("qbs.BinaryFile");
var Cpp = require("cpp.js");
var Environment = require("qbs.Environment");
var File = require("qbs.File");
@@ -546,6 +547,35 @@ function archiverFlags(project, product, inputs, outputs) {
return args;
}
+// This is the workaround for the SDCC bug on a Windows host:
+// * 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) {
+ var isWindows = input.qbs.hostOS.contains("windows");
+ if (isWindows && input.cpp.debugInformation) {
+ cmd = new JavaScriptCommand();
+ cmd.objectPath = outputs.obj[0].filePath;
+ cmd.silent = true;
+ cmd.sourceCode = function() {
+ var file = new BinaryFile(objectPath, BinaryFile.ReadWrite);
+ var data = file.read(file.size());
+ file.resize(0);
+ for (var pos = 0; pos < data.length; ++pos) {
+ // Find the next index of CR (\r) symbol.
+ var index = data.indexOf(0x0d, pos);
+ if (index < 0)
+ index = data.length;
+ // Write next data chunk between the previous position and the CR
+ // symbol, exclude the CR symbol.
+ file.write(data.slice(pos, index));
+ pos = index;
+ }
+ };
+ return cmd;
+ }
+}
+
function prepareCompiler(project, product, inputs, outputs, input, output, explicitlyDependsOn) {
var cmds = [];
var args = compilerFlags(project, product, input, outputs, explicitlyDependsOn);
@@ -555,37 +585,27 @@ function prepareCompiler(project, product, inputs, outputs, input, output, expli
cmd.highlight = "compiler";
cmds.push(cmd);
- // This is the workaround for the SDCC bug on a Windows host:
- // * 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.
- var isWindows = input.qbs.hostOS.contains("windows");
- if (isWindows) {
- cmd = new JavaScriptCommand();
- cmd.objectPath = outputs.obj[0].filePath;
- cmd.silent = true;
- cmd.sourceCode = function() {
- var lines = [];
- var file = new TextFile(objectPath, TextFile.ReadWrite);
- while (!file.atEof())
- lines.push(file.readLine() + "\n");
- file.truncate();
- for (var l in lines)
- file.write(lines[l]);
- };
+ cmd = patchObjectFiles(project, product, inputs, outputs, input, output);
+ if (cmd)
cmds.push(cmd);
- }
return cmds;
}
function prepareAssembler(project, product, inputs, outputs, input, output, explicitlyDependsOn) {
+ var cmds = [];
var args = assemblerFlags(project, product, input, outputs, explicitlyDependsOn);
var assemblerPath = input.cpp.assemblerPath;
var cmd = new Command(assemblerPath, args);
cmd.description = "assembling " + input.fileName;
cmd.highlight = "compiler";
- return [cmd];
+ cmds.push(cmd);
+
+ cmd = patchObjectFiles(project, product, inputs, outputs, input, output);
+ if (cmd)
+ cmds.push(cmd);
+
+ return cmds;
}
function prepareLinker(project, product, inputs, outputs, input, output) {