Commit 52a41ecb authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Qt4BC: Simplify shadowbuild/builddirectory handling



Change-Id: Id46a239588d21b6aa5d4c43e4d85b52a04bd17ab
Reviewed-by: default avatarDaniel Teske <daniel.teske@digia.com>
parent 769788a4
......@@ -218,6 +218,18 @@ QString FileUtils::shortNativePath(const FileName &path)
return path.toUserOutput();
}
QString FileUtils::fileSystemFriendlyName(const QString &name)
{
QString result = name;
result.replace(QRegExp(QLatin1String("\\W")), QLatin1String("_"));
result.replace(QRegExp(QLatin1String("_+")), QLatin1String("_")); // compact _
result.remove(QRegExp(QLatin1String("^_*"))); // remove leading _
result.remove(QRegExp(QLatin1String("_+$"))); // remove trailing _
if (result.isEmpty())
result = QLatin1String("unknown");
return result;
}
bool FileUtils::makeWritable(const FileName &path)
{
const QString fileName = path.toString();
......
......@@ -96,6 +96,7 @@ public:
static bool isFileNewerThan(const FileName &filePath, const QDateTime &timeStamp);
static FileName resolveSymlinks(const FileName &path);
static QString shortNativePath(const FileName &path);
static QString fileSystemFriendlyName(const QString &name);
static bool makeWritable(const FileName &path);
};
......
......@@ -33,6 +33,8 @@
#include "ioutputparser.h"
#include "osparser.h"
#include <utils/fileutils.h>
#include <QApplication>
#include <QFileInfo>
#include <QIcon>
......@@ -55,22 +57,6 @@ const char ICON_KEY[] = "PE.Profile.Icon";
namespace ProjectExplorer {
// --------------------------------------------------------------------
// Helper:
// --------------------------------------------------------------------
static QString cleanName(const QString &name)
{
QString result = name;
result.replace(QRegExp(QLatin1String("\\W")), QLatin1String("_"));
result.replace(QRegExp(QLatin1String("_+")), QLatin1String("_")); // compact _
result.remove(QRegExp(QLatin1String("^_*"))); // remove leading _
result.remove(QRegExp(QLatin1String("_+$"))); // remove trailing _
if (result.isEmpty())
result = QLatin1String("unknown");
return result;
}
// -------------------------------------------------------------------------
// KitPrivate
// -------------------------------------------------------------------------
......@@ -265,14 +251,14 @@ QStringList Kit::candidateNameList(const QString &base) const
QString Kit::fileSystemFriendlyName() const
{
QString name = cleanName(displayName());
QString name = Utils::FileUtils::fileSystemFriendlyName(displayName());
foreach (Kit *i, KitManager::kits()) {
if (i == this)
continue;
if (name == cleanName(i->displayName())) {
if (name == Utils::FileUtils::fileSystemFriendlyName(i->displayName())) {
// append part of the kit id: That should be unique enough;-)
// Leading { will be turned into _ which should be fine.
name = cleanName(name + QLatin1Char('_') + (id().toString().left(7)));
name = Utils::FileUtils::fileSystemFriendlyName(name + QLatin1Char('_') + (id().toString().left(7)));
break;
}
}
......
......@@ -136,6 +136,8 @@ bool Qt4BuildConfiguration::fromMap(const QVariantMap &map)
void Qt4BuildConfiguration::ctor()
{
m_buildDirectory = target()->project()->projectDirectory(); // default to in-source build!
connect(this, SIGNAL(environmentChanged()),
this, SLOT(emitBuildDirectoryChanged()));
connect(this, SIGNAL(environmentChanged()),
......@@ -169,7 +171,7 @@ void Qt4BuildConfiguration::qtVersionsChanged(const QList<int> &,const QList<int
emitProFileEvaluateNeeded();
}
void Qt4BuildConfiguration::emitBuildDirectoryChanged()
bool Qt4BuildConfiguration::emitBuildDirectoryChanged()
{
// We also emit buildDirectoryChanged if the the Qt version's supportShadowBuild changed
if (buildDirectory() != m_lastEmmitedBuildDirectory
......@@ -177,7 +179,9 @@ void Qt4BuildConfiguration::emitBuildDirectoryChanged()
m_lastEmmitedBuildDirectory = buildDirectory();
m_qtVersionSupportsShadowBuilds = supportsShadowBuilds();
emit buildDirectoryChanged();
return true;
}
return false;
}
NamedWidget *Qt4BuildConfiguration::createConfigWidget()
......@@ -195,16 +199,7 @@ QString Qt4BuildConfiguration::defaultShadowBuildDirectory() const
/// returns the unexpanded build directory
QString Qt4BuildConfiguration::rawBuildDirectory() const
{
QString workingDirectory;
if (m_shadowBuild) {
if (!m_buildDirectory.isEmpty())
workingDirectory = m_buildDirectory;
else
workingDirectory = defaultShadowBuildDirectory();
}
if (workingDirectory.isEmpty())
workingDirectory = target()->project()->projectDirectory();
return workingDirectory;
return m_buildDirectory;
}
/// Returns the build directory.
......@@ -253,33 +248,21 @@ void Qt4BuildConfiguration::setFileNodeBuild(FileNode *node)
/// note, even if shadowBuild() returns true, it might be using the
/// source directory as the shadow build directory, thus it
/// still is a in-source build
bool Qt4BuildConfiguration::shadowBuild() const
bool Qt4BuildConfiguration::isShadowBuild() const
{
return m_shadowBuild;
return buildDirectory() != target()->project()->projectDirectory();
}
/// returns the shadow build directory if set
/// \note buildDirectory() is probably the function you want to call
QString Qt4BuildConfiguration::shadowBuildDirectory() const
void Qt4BuildConfiguration::setBuildDirectory(const QString &directory)
{
if (m_buildDirectory.isEmpty())
return defaultShadowBuildDirectory();
return m_buildDirectory;
}
void Qt4BuildConfiguration::setShadowBuildAndDirectory(bool shadowBuild, const QString &buildDirectory)
{
BaseQtVersion *version = QtKitInformation::qtVersion(target()->kit());
QString directoryToSet = buildDirectory;
bool toSet = (shadowBuild && version && version->isValid() && version->supportsShadowBuilds());
if (m_shadowBuild == toSet && m_buildDirectory == directoryToSet)
return;
m_shadowBuild = toSet;
m_buildDirectory = directoryToSet;
if (!supportsShadowBuilds()) {
m_buildDirectory = target()->project()->projectDirectory();
} else {
m_buildDirectory = directory;
}
emitBuildDirectoryChanged();
emitProFileEvaluateNeeded();
if (emitBuildDirectoryChanged())
emitProFileEvaluateNeeded();
}
QString Qt4BuildConfiguration::makefile() const
......@@ -742,8 +725,10 @@ Qt4BuildConfiguration *Qt4BuildConfiguration::setup(Target *t, QString defaultDi
bc->setQMakeBuildConfiguration(qmakeBuildConfiguration);
if (!directory.isEmpty())
bc->setShadowBuildAndDirectory(directory != t->project()->projectDirectory(), directory);
if (directory.isEmpty())
bc->setBuildDirectory(t->project()->projectDirectory());
else
bc->setBuildDirectory(directory);
return bc;
}
......
......@@ -56,9 +56,9 @@ public:
ProjectExplorer::NamedWidget *createConfigWidget();
QString buildDirectory() const;
bool shadowBuild() const;
QString shadowBuildDirectory() const;
void setShadowBuildAndDirectory(bool shadowBuild, const QString &buildDirectory);
QString rawBuildDirectory() const;
bool isShadowBuild() const;
void setBuildDirectory(const QString &dir);
void setSubNodeBuild(Qt4ProjectManager::Qt4ProFileNode *node);
Qt4ProjectManager::Qt4ProFileNode *subNodeBuild() const;
......@@ -120,12 +120,13 @@ signals:
/// emitted for setQMakeBuildConfig, not emitted for Qt version changes, even
/// if those change the qmakebuildconfig
void qmakeBuildConfigurationChanged();
void shadowBuildChanged();
private slots:
void kitChanged();
void toolChainUpdated(ProjectExplorer::ToolChain *tc);
void qtVersionsChanged(const QList<int> &, const QList<int> &, const QList<int> &changed);
void emitBuildDirectoryChanged();
bool emitBuildDirectoryChanged();
protected:
Qt4BuildConfiguration(ProjectExplorer::Target *target, Qt4BuildConfiguration *source);
......@@ -134,7 +135,6 @@ protected:
private:
void ctor();
QString rawBuildDirectory() const;
QString defaultShadowBuildDirectory() const;
class LastKitState
......
......@@ -48,6 +48,11 @@ Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4BuildConfiguration *bc)
m_buildConfiguration(bc),
m_ignoreChange(false)
{
m_defaultShadowBuildDir
= Qt4Project::shadowBuildDirectory(bc->target()->project()->projectFilePath(),
bc->target()->kit(),
Utils::FileUtils::fileSystemFriendlyName(bc->displayName()));
QVBoxLayout *vbox = new QVBoxLayout(this);
vbox->setMargin(0);
m_detailsContainer = new Utils::DetailsWidget(this);
......@@ -62,6 +67,19 @@ Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4BuildConfiguration *bc)
m_ui->shadowBuildDirEdit->setPromptDialogTitle(tr("Shadow Build Directory"));
m_ui->shadowBuildDirEdit->setExpectedKind(Utils::PathChooser::ExistingDirectory);
bool isShadowBuild = bc->isShadowBuild();
if (isShadowBuild) {
m_ui->shadowBuildDirEdit->setPath(bc->rawBuildDirectory());
m_ui->inSourceBuildDirEdit->setVisible(false);
} else {
m_ui->shadowBuildDirEdit->setPath(m_defaultShadowBuildDir);
m_ui->shadowBuildDirEdit->setVisible(false);
}
m_ui->inSourceBuildDirEdit->setPath(bc->target()->project()->projectDirectory());
m_ui->inSourceBuildDirEdit->setReadOnly(true);
m_ui->inSourceBuildDirEdit->setEnabled(false);
m_ui->shadowBuildCheckBox->setChecked(isShadowBuild);
connect(m_ui->shadowBuildCheckBox, SIGNAL(clicked(bool)),
this, SLOT(shadowBuildClicked(bool)));
......@@ -88,9 +106,10 @@ Qt4ProjectConfigWidget::Qt4ProjectConfigWidget(Qt4BuildConfiguration *bc)
m_ui->shadowBuildDirEdit->setBaseDirectory(m_buildConfiguration->target()->project()->projectDirectory());
buildDirectoryChanged();
setDisplayName(tr("General"));
updateDetails();
updateProblemLabel();
}
Qt4ProjectConfigWidget::~Qt4ProjectConfigWidget()
......@@ -121,12 +140,16 @@ void Qt4ProjectConfigWidget::buildDirectoryChanged()
{
if (m_ignoreChange)
return;
m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->shadowBuildDirectory());
bool shadowBuild = m_buildConfiguration->shadowBuild();
m_ui->shadowBuildCheckBox->setChecked(shadowBuild);
bool shadowBuild = m_ui->shadowBuildCheckBox->isChecked();
m_ui->inSourceBuildDirEdit->setVisible(!shadowBuild);
m_ui->shadowBuildDirEdit->setVisible(shadowBuild);
m_ui->shadowBuildDirEdit->setEnabled(shadowBuild);
m_browseButton->setEnabled(shadowBuild);
m_ui->shadowBuildDirEdit->setPath(m_buildConfiguration->rawBuildDirectory());
updateDetails();
updateProblemLabel();
}
......@@ -142,10 +165,15 @@ void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
{
m_ui->shadowBuildDirEdit->setEnabled(checked);
m_browseButton->setEnabled(checked);
bool b = m_ui->shadowBuildCheckBox->isChecked();
m_ui->shadowBuildDirEdit->setVisible(checked);
m_ui->inSourceBuildDirEdit->setVisible(!checked);
m_ignoreChange = true;
m_buildConfiguration->setShadowBuildAndDirectory(b, m_ui->shadowBuildDirEdit->rawPath());
if (checked)
m_buildConfiguration->setBuildDirectory(m_ui->shadowBuildDirEdit->rawPath());
else
m_buildConfiguration->setBuildDirectory(m_ui->inSourceBuildDirEdit->rawPath());
m_ignoreChange = false;
updateDetails();
......@@ -154,17 +182,12 @@ void Qt4ProjectConfigWidget::shadowBuildClicked(bool checked)
void Qt4ProjectConfigWidget::shadowBuildEdited()
{
if (m_buildConfiguration->shadowBuildDirectory() == m_ui->shadowBuildDirEdit->rawPath())
if (m_buildConfiguration->rawBuildDirectory() == m_ui->shadowBuildDirEdit->rawPath())
return;
m_ignoreChange = true;
m_buildConfiguration->setShadowBuildAndDirectory(m_buildConfiguration->shadowBuild(), m_ui->shadowBuildDirEdit->rawPath());
m_buildConfiguration->setBuildDirectory(m_ui->shadowBuildDirEdit->rawPath());
m_ignoreChange = false;
// if the directory already exists
// check if we have a build in there and
// offer to import it
updateProblemLabel();
updateDetails();
}
void Qt4ProjectConfigWidget::updateProblemLabel()
......@@ -214,7 +237,7 @@ void Qt4ProjectConfigWidget::updateProblemLabel()
}
QString shadowBuildWarning;
if (!version->supportsShadowBuilds() && m_buildConfiguration->shadowBuild()) {
if (!version->supportsShadowBuilds() && m_buildConfiguration->isShadowBuild()) {
shadowBuildWarning = tr("The Qt version %1 does not support shadow builds, building might fail.")
.arg(version->displayName())
+ QLatin1String("<br>");
......@@ -222,7 +245,7 @@ void Qt4ProjectConfigWidget::updateProblemLabel()
if (allGood) {
QString buildDirectory = m_buildConfiguration->target()->project()->projectDirectory();;
if (m_buildConfiguration->shadowBuild())
if (m_buildConfiguration->isShadowBuild())
buildDirectory = m_buildConfiguration->buildDirectory();
QList<ProjectExplorer::Task> issues;
issues = version->reportIssues(proFileName, buildDirectory);
......
......@@ -75,6 +75,7 @@ private:
QAbstractButton *m_browseButton;
Qt4BuildConfiguration *m_buildConfiguration;
Utils::DetailsWidget *m_detailsContainer;
QString m_defaultShadowBuildDir;
bool m_ignoreChange;
};
......
......@@ -11,6 +11,20 @@
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="shadowBuildLabel">
<property name="text">
<string>Shadow build:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="shadowBuildCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="buildDirLabel">
<property name="sizePolicy">
......@@ -24,6 +38,23 @@
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="Utils::PathChooser" name="shadowBuildDirEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="Utils::PathChooser" name="inSourceBuildDirEdit" native="true"/>
</item>
</layout>
</item>
<item row="2" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......@@ -51,30 +82,6 @@
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="shadowBuildLabel">
<property name="text">
<string>Shadow build:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Utils::PathChooser" name="shadowBuildDirEdit" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="shadowBuildCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
......
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