1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
import qbs.Environment
import qbs.FileInfo
import qbs.Host
import qbs.Process
import qbs.TextFile
Project {
Product {
condition: {
var result = qbs.targetPlatform === Host.platform() && qbs.architecture === Host.architecture();
if (!result)
console.info("target platform/arch differ from host platform/arch");
return result;
}
Depends { name: "cpp" }
type: ["dummy"]
name: "dummy"
files: ["main.cpp"]
Rule {
multiplex: true
inputs: ["application"]
outputFileTags: "dummy"
prepare: {
var cmd = new JavaScriptCommand();
cmd.silent = true;
cmd.sourceCode = function() {
var exeFilePath = FileInfo.joinPaths(product.buildDirectory,
product.cpp.executablePrefix
+ "dummy"
+ product.cpp.executableSuffix);
// Synchronous run, successful.
var process = new Process();
var pathVal = "why, hello!";
process.setEnv("SOME_ENV", pathVal);
process.exec(exeFilePath, ["help"], true);
var output = new TextFile("output.txt", TextFile.WriteOnly);
output.writeLine(process.exitCode());
output.writeLine(process.readLine());
process.close();
// Asynchronous run, successful.
process = new Process();
process.setEnv("SOME_ENV", pathVal);
output.writeLine(process.start(exeFilePath, ["help"]));
output.writeLine(process.waitForFinished());
output.writeLine(process.exitCode());
output.writeLine(process.readLine());
process.close();
// Asynchronous run, unsuccessful.
process = new Process();
output.writeLine(process.errorString());
output.writeLine(process.start("blubb", []));
output.writeLine(process.errorString());
process.close();
// Synchronous run, unsuccessful.
process = new Process();
output.writeLine(process.errorString());
output.writeLine(process.exec("blubb", []));
output.writeLine(process.errorString());
process.close();
// Synchronous run, unsuccessful (throw).
process = new Process();
try {
process.exec("blubb", [], true);
} catch (e) {
output.writeLine(e);
} finally {
process.close();
}
// closeWriteChannel test
process = new Process();
if (Host.os().includes("windows"))
process.start(product.qbs.windowsShellPath,
["/C", product.qbs.windowsSystemRoot + "\\system32\\sort.exe"]);
else
process.start("cat", []);
process.writeLine("should be");
process.closeWriteChannel();
process.writeLine("should not be");
if (!process.waitForFinished())
process.kill();
output.write(process.readStdOut());
process.close();
// readLine and atEnd
var testReadlineFile = new TextFile("123.txt", TextFile.WriteOnly);
testReadlineFile.writeLine("1");
testReadlineFile.writeLine("2");
testReadlineFile.writeLine("3");
testReadlineFile.close();
process = new Process();
if (Host.os().includes("windows"))
process.exec(product.qbs.windowsShellPath,
["/C", "type", "123.txt"],
true);
else
process.exec("cat", ["123.txt"], true);
while(!process.atEnd())
output.write(process.readLine());
// TODO: Test all the other Process methods as well.
output.close();
};
return [cmd];
}
}
}
}
|