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
|
var File = loadExtension("qbs.File");
var FileInfo = loadExtension("qbs.FileInfo");
var TextFile = loadExtension("qbs.TextFile");
function getExportBlock(productFile)
{
var exportBlock = "";
var exportIndex = -1;
while (!productFile.atEof()) {
var line = productFile.readLine();
if (exportIndex === -1) {
exportIndex = line.indexOf("Export {");
continue;
}
if (line.indexOf('}') === exportIndex)
break;
exportBlock += " " + line.trim() + '\n';
}
return exportBlock;
}
function insertOrAddToProperty(product, content, propertyName, value)
{
var valueAsList = '[' + value + ']';
var propertyNameIndex = content.indexOf(propertyName + ':');
if (propertyNameIndex !== -1) {
var endListIndex = content.indexOf(']', propertyNameIndex);
if (endListIndex === -1)
throw "Failed to parse Export item of product '" + product.name + "'";
var contentStart = content.slice(0, endListIndex + 1);
var contentEnd = content.slice(endListIndex + 1);
return contentStart + ".concat(" + valueAsList + ')' + contentEnd;
}
return content + '\n' + propertyName + ": " + valueAsList;
}
function transformedExportBlock(product, input, output)
{
var productFilePath = FileInfo.joinPaths(product.sourceDirectory, product.fileName);
var productFile = new TextFile(productFilePath, TextFile.ReadOnly);
try {
var exportBlock = getExportBlock(productFile);
exportBlock = " Depends { name: 'cpp' }\n" + exportBlock;
var modulePath = FileInfo.joinPaths("/",
product.moduleProperty("qtc", "ide_qbs_modules_path"), product.name);
var includePath = FileInfo.joinPaths("/",
product.moduleProperty("qtc", "ide_include_path"));
var relPathToIncludes = FileInfo.relativePath(modulePath, includePath);
var absPathToIncludes = "path + '/" + relPathToIncludes + "'";
exportBlock = exportBlock.replace(/product.sourceDirectory/g, absPathToIncludes + " + '/"
+ FileInfo.fileName(product.sourceDirectory) + "'");
var dataPath = FileInfo.joinPaths("/", product.moduleProperty("qtc", "ide_data_path"));
var relPathToData = FileInfo.relativePath(modulePath, dataPath);
exportBlock = exportBlock.replace(/qtc.export_data_base/g, "path + '/"
+ relPathToData + "'");
exportBlock = insertOrAddToProperty(product, exportBlock, "cpp.includePaths",
absPathToIncludes);
var libInstallPath = FileInfo.joinPaths("/", input.moduleProperty("qbs", "installDir"));
var relPathToLibrary = FileInfo.relativePath(modulePath, libInstallPath);
var fullPathToLibrary = "path + '/" + relPathToLibrary + "/" + input.fileName + "'";
var libType = input.fileTags.contains("dynamiclibrary") ? "dynamic" : "static";
exportBlock = insertOrAddToProperty(product, exportBlock, "cpp." + libType + "Libraries",
fullPathToLibrary);
return exportBlock;
} finally {
productFile.close();
}
}
function writeModuleFile(output, content)
{
var moduleFile = new TextFile(output.filePath, TextFile.WriteOnly);
try {
moduleFile.writeLine("import qbs");
moduleFile.writeLine("");
moduleFile.writeLine("Module {")
moduleFile.writeLine(content);
moduleFile.writeLine("}");
} finally {
moduleFile.close();
}
}
|