Skip to content

Instantly share code, notes, and snippets.

@orgads
Created March 31, 2016 05:29
Show Gist options
  • Select an option

  • Save orgads/00cc12650211eed9c2fdf86ddddcd16a to your computer and use it in GitHub Desktop.

Select an option

Save orgads/00cc12650211eed9c2fdf86ddddcd16a to your computer and use it in GitHub Desktop.
import qbs
import qbs.File
import qbs.FileInfo
import qbs.TextFile
Product {
name: "UnitTests"
type: "hpp"
readonly property string targetFile: FileInfo.joinPaths(buildDirectory, ".current-unit-test-flag")
property string content: {
var res = "// GTEST";
if (project.gtest)
res += "1";
res += "\n";
return res;
}
Rule {
id: unitTestEnabled
inputs: ["qbs"]
Artifact {
filePath: product.targetFile
fileTags: ["hpp"]
}
condition: {
if (File.exists(product.targetFile)) {
var file = new TextFile(product.targetFile);
return file.readAll() != product.content;
}
return true;
}
prepare: {
var cmd = new JavaScriptCommand();
cmd.description = 'generating ' + product.targetFile;
cmd.highlight = 'codegen';
cmd.content = product.content
cmd.sourceCode = function() {
var outfile = new TextFile(product.targetFile, TextFile.WriteOnly);
outfile.truncate();
outfile.write(content);
outfile.close();
}
return cmd;
}
}
Export {
Depends { name: "cpp" }
cpp.includePaths: product.buildDirectory
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment