Why is qbs ignoring my rule?

I have this simple code

import qbs

Project {
name: "simple_test"

Product {
    name: "micro"
    type: "other"
    Group {
        files: '*.q'
        fileTags: ['qfile']
    }

    Rule {
        id: check1
        inputs: ["qfile"]
        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "QFile passing"
            cmd.silent = false;
            cmd.highlight = "compiler";
            cmd.sourceCode = function() {
                print("Nothing to do");
            };
            return cmd;
        }
    }
    Transformer {
        inputs: ['blink.q']
        Artifact {
            filePath: "processed_qfile.txt"
            fileTags: "processed_qfile"
        }
        prepare: {
            var cmd = new JavaScriptCommand();
            cmd.description = "QFile transformer";
            cmd.highlight = "compiler";
            cmd.sourceCode = function() {
                print("Another nothing");
            };
            return cmd;
        }
    }
}
}

      

And put two files blink.q and blink1.q

According to the documentation, I should see 3 lines in the "Compile Output" window: two with "QFile Passing" and one with "QFile transformer"

But I can see that only the Transformer block is working (no "QFile Passing" at all) (what's wrong with my Rule?

+3


source to share


1 answer


Your Rule should actually generate some Artifacts, and your product type should somehow (directly or indirectly) depend on the tags of your Rule's output artifact files. In other words, nothing depended on the inference of your rule, so the rule was not enforced.

Maybe you want the following:

import qbs

Project {
    name: "simple_test"

    Product {
        name: "micro"
        type: ["other", "processed_qfile"]
        Group {
            files: '*.q'
            fileTags: ['qfile']
        }

        Rule {
            id: check1
            inputs: ["qfile"]
            Artifact {
                filePath: "processed_qfile.txt"
                fileTags: "processed_qfile"
            }
            prepare: {
                var cmd = new JavaScriptCommand();
                cmd.description = "QFile passing"
                cmd.silent = false;
                cmd.highlight = "compiler";
                cmd.sourceCode = function() {
                    print("Nothing to do");
                };
                return cmd;
            }
        }
    }
}

      



Notice the addition:

  • An Artifact element within the rule check1

    that describes the output file that will be generated by the Rule.
  • Add a type processed_qfile

    to a product type, create a connection in the dependency tree, and enforce a rule on product creation
+2


source







All Articles