forked from qt-creator/qt-creator
Generalize support for extra compilers
Allow for different extra compilers which may get called to generate additional code for the code model. The build system is expected to know what files are generated from which source file and the extra compilers know how to generate the content of those files, without touching the build directory. the uic adapter is refactored to be the first such extra compiler. The extra compiler is run when an editor for its source document loses focus, or after a timeout of 1s when the source document has been changed. Change-Id: I13c110c61120c812f02639a3684144daf8979b37 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
@@ -52,8 +52,12 @@
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
#include <qtsupport/customexecutablerunconfiguration.h>
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
#include <qtsupport/uicodemodelsupport.h>
|
||||
|
||||
#include <cpptools/generatedcodemodelsupport.h>
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <cpptools/projectinfo.h>
|
||||
#include <cpptools/projectpartbuilder.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/stringutils.h>
|
||||
@@ -108,7 +112,7 @@ CMakeProject::~CMakeProject()
|
||||
{
|
||||
setRootProjectNode(nullptr);
|
||||
m_codeModelFuture.cancel();
|
||||
delete m_buildDirManager;
|
||||
qDeleteAll(m_extraCompilers);
|
||||
}
|
||||
|
||||
void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc)
|
||||
@@ -287,7 +291,7 @@ void CMakeProject::parseCMakeOutput()
|
||||
|
||||
updateApplicationAndDeploymentTargets();
|
||||
|
||||
createUiCodeModelSupport();
|
||||
createGeneratedCodeModelSupport();
|
||||
|
||||
ToolChain *tc = ProjectExplorer::ToolChainKitInformation::toolChain(m_buildDirManager->kit());
|
||||
if (!tc) {
|
||||
@@ -624,11 +628,11 @@ CMakeBuildTarget CMakeProject::buildTargetForTitle(const QString &title)
|
||||
return CMakeBuildTarget();
|
||||
}
|
||||
|
||||
QString CMakeProject::uiHeaderFile(const QString &uiFile)
|
||||
QStringList CMakeProject::filesGeneratedFrom(const QString &sourceFile) const
|
||||
{
|
||||
if (!activeTarget())
|
||||
return QString();
|
||||
QFileInfo fi(uiFile);
|
||||
return QStringList();
|
||||
QFileInfo fi(sourceFile);
|
||||
FileName project = projectDirectory();
|
||||
FileName baseDirectory = FileName::fromString(fi.absolutePath());
|
||||
|
||||
@@ -645,12 +649,17 @@ QString CMakeProject::uiHeaderFile(const QString &uiFile)
|
||||
QDir srcDirRoot = QDir(project.toString());
|
||||
QString relativePath = srcDirRoot.relativeFilePath(baseDirectory.toString());
|
||||
QDir buildDir = QDir(activeTarget()->activeBuildConfiguration()->buildDirectory().toString());
|
||||
QString uiHeaderFilePath = buildDir.absoluteFilePath(relativePath);
|
||||
uiHeaderFilePath += QLatin1String("/ui_");
|
||||
uiHeaderFilePath += fi.completeBaseName();
|
||||
uiHeaderFilePath += QLatin1String(".h");
|
||||
QString generatedFilePath = buildDir.absoluteFilePath(relativePath);
|
||||
|
||||
return QDir::cleanPath(uiHeaderFilePath);
|
||||
if (fi.suffix() == QLatin1String("ui")) {
|
||||
generatedFilePath += QLatin1String("/ui_");
|
||||
generatedFilePath += fi.completeBaseName();
|
||||
generatedFilePath += QLatin1String(".h");
|
||||
return QStringList(QDir::cleanPath(generatedFilePath));
|
||||
} else {
|
||||
// TODO: Other types will be added when adapters for their compilers become available.
|
||||
return QStringList();
|
||||
}
|
||||
}
|
||||
|
||||
void CMakeProject::updateRunConfigurations()
|
||||
@@ -753,17 +762,31 @@ void CMakeProject::updateApplicationAndDeploymentTargets()
|
||||
t->setDeploymentData(deploymentData);
|
||||
}
|
||||
|
||||
void CMakeProject::createUiCodeModelSupport()
|
||||
void CMakeProject::createGeneratedCodeModelSupport()
|
||||
{
|
||||
QHash<QString, QString> uiFileHash;
|
||||
qDeleteAll(m_extraCompilers);
|
||||
m_extraCompilers.clear();
|
||||
QList<ProjectExplorer::ExtraCompilerFactory *> factories =
|
||||
ProjectExplorer::ExtraCompilerFactory::extraCompilerFactories();
|
||||
|
||||
// Find all ui files
|
||||
foreach (const QString &uiFile, files(SourceFiles)) {
|
||||
if (uiFile.endsWith(QLatin1String(".ui")))
|
||||
uiFileHash.insert(uiFile, uiHeaderFile(uiFile));
|
||||
// Find all files generated by any of the extra compilers, in a rather crude way.
|
||||
foreach (const QString &file, files(SourceFiles)) {
|
||||
foreach (ProjectExplorer::ExtraCompilerFactory *factory, factories) {
|
||||
if (file.endsWith(QLatin1Char('.') + factory->sourceTag())) {
|
||||
QStringList generated = filesGeneratedFrom(file);
|
||||
if (!generated.isEmpty()) {
|
||||
const FileNameList fileNames = Utils::transform(generated,
|
||||
[](const QString &s) {
|
||||
return FileName::fromString(s);
|
||||
});
|
||||
m_extraCompilers.append(factory->create(this, FileName::fromString(file),
|
||||
fileNames));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QtSupport::UiCodeModelManager::update(this, uiFileHash);
|
||||
CppTools::GeneratedCodeModelSupport::update(m_extraCompilers);
|
||||
}
|
||||
|
||||
void CMakeBuildTarget::clear()
|
||||
|
||||
Reference in New Issue
Block a user