2017-10-02 17:30:25 +02:00
|
|
|
var File = require("qbs.File");
|
|
|
|
|
var FileInfo = require("qbs.FileInfo");
|
|
|
|
|
var TextFile = require("qbs.TextFile");
|
2016-06-08 17:10:04 +02:00
|
|
|
|
|
|
|
|
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;
|
2016-06-10 17:51:22 +02:00
|
|
|
exportBlock += " " + line.trim() + '\n';
|
2016-06-08 17:10:04 +02:00
|
|
|
}
|
|
|
|
|
return exportBlock;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-10 17:51:22 +02:00
|
|
|
function insertOrAddToProperty(product, content, propertyName, value)
|
2016-06-08 17:10:04 +02:00
|
|
|
{
|
2016-06-10 17:51:22 +02:00
|
|
|
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;
|
2016-06-08 17:10:04 +02:00
|
|
|
}
|
2016-06-10 17:51:22 +02:00
|
|
|
return content + '\n' + propertyName + ": " + valueAsList;
|
2016-06-08 17:10:04 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-10 17:51:22 +02:00
|
|
|
function transformedExportBlock(product, input, output)
|
2016-06-08 17:10:04 +02:00
|
|
|
{
|
2016-06-10 17:51:22 +02:00
|
|
|
var productFilePath = FileInfo.joinPaths(product.sourceDirectory, product.fileName);
|
2016-06-08 17:10:04 +02:00
|
|
|
var productFile = new TextFile(productFilePath, TextFile.ReadOnly);
|
|
|
|
|
try {
|
|
|
|
|
var exportBlock = getExportBlock(productFile);
|
2016-06-10 17:51:22 +02:00
|
|
|
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);
|
2016-06-14 16:38:44 +02:00
|
|
|
if (input.fileTags.contains("dynamiclibrary") || input.fileTags.contains("staticlibrary")) {
|
|
|
|
|
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);
|
|
|
|
|
}
|
2016-06-10 17:51:22 +02:00
|
|
|
return exportBlock;
|
2016-06-08 17:10:04 +02:00
|
|
|
} finally {
|
|
|
|
|
productFile.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-10 17:51:22 +02:00
|
|
|
function writeModuleFile(output, content)
|
2016-06-08 17:10:04 +02:00
|
|
|
{
|
|
|
|
|
var moduleFile = new TextFile(output.filePath, TextFile.WriteOnly);
|
|
|
|
|
try {
|
|
|
|
|
moduleFile.writeLine("import qbs");
|
|
|
|
|
moduleFile.writeLine("");
|
|
|
|
|
moduleFile.writeLine("Module {")
|
2016-06-10 17:51:22 +02:00
|
|
|
moduleFile.writeLine(content);
|
2016-06-08 17:10:04 +02:00
|
|
|
moduleFile.writeLine("}");
|
|
|
|
|
} finally {
|
|
|
|
|
moduleFile.close();
|
|
|
|
|
}
|
|
|
|
|
}
|