Files
qt-creator/qbs/modules/qtc/qtc.js
Christian Kandeler a0cceb2810 qbs build: Do not make the ProParser a static library after all.
If ProParser is a library, all plugins depending on it (to be able to
get at the include paths) will also link to it, but there must be only
one instance of its data present. So we go back to building the sources
as part of the QtSupport plugin, while the ProParser product is now only
responsible for exporting the necessary defines and include paths.

Change-Id: I9ad62343064d8aea8ddc4776a462308c4d6ae283
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2016-06-15 12:36:43 +00:00

85 lines
3.7 KiB
JavaScript

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);
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);
}
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();
}
}