Commit bac2d184 authored by Ulf Hermann's avatar Ulf Hermann

ProjectExplorer: Resolve any CurrentProject:<foo> in default build path

If ProjectMacroExpander doesn't resolve it we fall back to the generic
ProjectExplorer resolution, which is likely to pick the wrong project.

Task-number: QTCREATORBUG-16724
Change-Id: I201b722c5fe184905f744a1f344ec46941f92ae3
Reviewed-by: Tobias Hunger's avatarTobias Hunger <tobias.hunger@qt.io>
parent 9142934d
......@@ -193,7 +193,7 @@ FileName CMakeBuildConfiguration::shadowBuildDirectory(const FileName &projectFi
return FileName();
const QString projectName = projectFilePath.parentDir().fileName();
ProjectMacroExpander expander(projectName, k, bcName, buildType);
ProjectMacroExpander expander(projectFilePath.toString(), projectName, k, bcName, buildType);
QDir projectDir = QDir(Project::projectDirectory(projectFilePath).toString());
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return FileName::fromUserInput(projectDir.absoluteFilePath(buildPath));
......
......@@ -180,7 +180,7 @@ FileName NimBuildConfigurationFactory::defaultBuildDirectory(const Kit *k,
{
QFileInfo projectFileInfo(projectFilePath);
ProjectMacroExpander expander(projectFileInfo.baseName(), k, bc, buildType);
ProjectMacroExpander expander(projectFilePath, projectFileInfo.baseName(), k, bc, buildType);
QString buildDirectory = expander.expand(Core::DocumentManager::buildDirectory());
if (FileUtils::isAbsolutePath(buildDirectory))
......
......@@ -29,10 +29,14 @@
namespace ProjectExplorer {
ProjectMacroExpander::ProjectMacroExpander(const QString &projectName,
ProjectMacroExpander::ProjectMacroExpander(const QString &mainFilePath, const QString &projectName,
const Kit *kit, const QString &bcName,
BuildConfiguration::BuildType buildType)
{
registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
QCoreApplication::translate("ProjectExplorer", "Main file of current project"),
[mainFilePath]() -> QString { return mainFilePath; });
registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
QCoreApplication::translate("ProjectExplorer", "Name of current project"),
[projectName] { return projectName; });
......
......@@ -37,8 +37,8 @@ class Kit;
class PROJECTEXPLORER_EXPORT ProjectMacroExpander : public Utils::MacroExpander
{
public:
ProjectMacroExpander(const QString &projectName, const Kit *kit, const QString &bcName,
BuildConfiguration::BuildType buildType);
ProjectMacroExpander(const QString &mainFilePath, const QString &projectName, const Kit *kit,
const QString &bcName, BuildConfiguration::BuildType buildType);
};
} // namespace ProjectExplorer
......@@ -398,7 +398,7 @@ static Utils::FileName defaultBuildDirectory(const QString &projectFilePath, con
BuildConfiguration::BuildType buildType)
{
const QString projectName = QFileInfo(projectFilePath).completeBaseName();
ProjectMacroExpander expander(projectName, k, bcName, buildType);
ProjectMacroExpander expander(projectFilePath, projectName, k, bcName, buildType);
QString projectDir = Project::projectDirectory(Utils::FileName::fromString(projectFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return Utils::FileName::fromString(Utils::FileUtils::resolvePath(projectDir, buildPath));
......
......@@ -78,7 +78,7 @@ QString QmakeBuildConfiguration::shadowBuildDirectory(const QString &proFilePath
return QString();
const QString projectName = QFileInfo(proFilePath).completeBaseName();
ProjectMacroExpander expander(projectName, k, suffix, buildType);
ProjectMacroExpander expander(proFilePath, projectName, k, suffix, buildType);
QString projectDir = Project::projectDirectory(FileName::fromString(proFilePath)).toString();
QString buildPath = expander.expand(Core::DocumentManager::buildDirectory());
return FileUtils::resolvePath(projectDir, buildPath);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment