[Qbs] Second rule reads empty file generated by first rule

Denis Shienkov denis.shienkov at gmail.com
Wed Oct 11 19:11:26 CEST 2017


Hi all,

I have a project with some rules: 'producer' and 'consumer',

The 'producer' generates an artifact with the JSON file, and the 'consumer'
receive this artifact on input and does trying to read content of this JSON
file.

BUT: The consumer always reads an empty content, even the file exists and
is not empty.

== Producer ==

Rule {

        //alwaysRun: true

        multiplex: true

        inputs: ["rwwcoreapp", "nrwwcoreapp", "mergedcoreapp"]


        Artifact {

            fileTags: ["firmwarebin"]

            filePath: product.targetName + ".bin"

        }


        Artifact {

            fileTags: ["firmwarecrc"]

            filePath: "crcs.json"

        }


        prepare: {

            var cmd = new JavaScriptCommand();

            cmd.workingDirectory = product.buildDirectory

            cmd.patcher = project.sourceDirectory + "/tools/patcher.exe";

            cmd.outputFirmwareFilePath = outputs["firmwarebin"][0].filePath;

            cmd.outputCrcFilePath = outputs["firmwarecrc"][0].filePath;

            cmd.inputMergedFilePaths =
inputs["mergedcoreapp"].map(function(a) { return a.filePath;
}).sort();

            cmd.inputRwwFilePaths =
inputs["rwwcoreapp"].map(function(a) { return a.filePath; }).sort();

            cmd.inputNrwwFilePaths =
inputs["nrwwcoreapp"].map(function(a) { return a.filePath; }).sort();

            cmd.crcSize = 2;

            cmd.sourceCode = function() {

                var p = new Process();

                p.setWorkingDirectory(workingDirectory);


                // TODO: Make it more good!!

                var crcStarts = [ 0x1EBFE, 0x1F3FE ];

                var crcEnds = [ 0x1EBFE + crcSize, 0x1F3FE + crcSize ];


                var crcConfigs = { };

                crcConfigs["crcs"] = [];


                // Patch each of NRWW file.

                for (var i = 0; i < inputMergedFilePaths.length; ++i) {

                    var args = [

                                                        // Some arguments

                            ];

                    var crcValue = p.exec(patcher, args, false);

                    var startOffset = crcStarts[i];

                    var endOffset = crcEnds[i];


                    var crcConfig = {};

                    crcConfig["crcValue"] = crcValue;

                    crcConfig["startOffset"] = startOffset;

                    crcConfig["endOffset"] = endOffset;


                    crcConfigs["crcs"].push(crcConfig);

                }

                // Generate JSON file.

                var tf = new TextFile(outputCrcFilePath, TextFile.WriteOnly);

                tf.writeLine(JSON.stringify(crcConfigs, undefined, 4));


                // Generate final binary firmware.

                var args = [ "/C", "copy", "/b" ];

                for (var i = 0; i < inputRwwFilePaths.length; ++i) {


args.push(FileInfo.toWindowsSeparators(inputRwwFilePaths[i]));

                    args.push("+");


args.push(FileInfo.toWindowsSeparators(inputNrwwFilePaths[i]));

                    if (i < (inputRwwFilePaths.length - 1))

                        args.push("+");

                }

                args.push(FileInfo.toWindowsSeparators(outputFirmwareFilePath));

                p.exec("cmd.exe", args, true);

            }

            cmd.description = "generating " +
FileInfo.fileName(cmd.outputFirmwareFilePath);

            return cmd;

        }

    }

== Consumer==

    Rule {        //alwaysRun: true        multiplex: true
inputs: ["firmwarecrc"]        inputsFromDependencies: ["hex",
"firmwarecrc"]        explicitlyDependsOn: ["firmwarecrc"]
        Artifact {            fileTags: ["firmwarehex"]
filePath: product.targetName + ".hex"        }
        prepare: {            var cmd = new JavaScriptCommand();
     cmd.workingDirectory = product.buildDirectory
cmd.sreccat = project.sourceDirectory + "/tools/srec_cat.exe";
   cmd.inputCrcFilePath = inputs["firmwarecrc"][0].filePath;
 cmd.inputHexFilePaths = inputs["hex"].map(function(a) { return
a.filePath; }).sort();            cmd.outputFirmwareFilePath =
outputs["firmwarehex"][0].filePath;            cmd.description =
"generating " + FileInfo.fileName(cmd.outputFirmwareFilePath);
   cmd.sourceCode = function() {                var p = new Process();
               p.setWorkingDirectory(workingDirectory);
                // Merge all hex files to one.                var
srecArgs = [];                for (var i = 0; i <
inputHexFilePaths.length; ++i) {
srecArgs.push(inputHexFilePaths[i]);
srecArgs.push("-I");                }
srecArgs.push("-o");
srecArgs.push(outputFirmwareFilePath);
srecArgs.push("-I");                p.exec(sreccat, srecArgs, true);
                // Add crc                var tf = new
TextFile(inputCrcFilePath, TextFile.ReadOnly);                var
content = tf.readAll();                console.info("tf: " +
inputCrcFilePath + ", content : " + content);                //var
crcs = JSON.parse(tf.readAll())["crcs"];            }
return cmd;        }    }

I had tries to add the 'firmwarecrc' target to inputsFromDependencies,

and to explicitlyDependsOn ..


*But, it does not help... What's wrong?*

BR,
Denis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qbs/attachments/20171011/0fbd4259/attachment.html>


More information about the Qbs mailing list