forked from qt-creator/qt-creator
Utils: Introduce a non-mutating FileName::pathAppended
... and start using it. The plan is to replace all appendPath() uses. Change-Id: I555bcfa742b99b0951b98b0c0e707422c348fadb Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -166,10 +166,8 @@ bool FileUtils::copyRecursively(const FileName &srcFilePath, const FileName &tgt
|
|||||||
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
|
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot
|
||||||
| QDir::Hidden | QDir::System);
|
| QDir::Hidden | QDir::System);
|
||||||
foreach (const QString &fileName, fileNames) {
|
foreach (const QString &fileName, fileNames) {
|
||||||
FileName newSrcFilePath = srcFilePath;
|
const FileName newSrcFilePath = srcFilePath.pathAppended(fileName);
|
||||||
newSrcFilePath.appendPath(fileName);
|
const FileName newTgtFilePath = tgtFilePath.pathAppended(fileName);
|
||||||
FileName newTgtFilePath = tgtFilePath;
|
|
||||||
newTgtFilePath.appendPath(fileName);
|
|
||||||
if (!copyRecursively(newSrcFilePath, newTgtFilePath, error, copyHelper))
|
if (!copyRecursively(newSrcFilePath, newTgtFilePath, error, copyHelper))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -855,6 +853,17 @@ FileName &FileName::appendPath(const QString &s)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileName FileName::pathAppended(const QString &str) const
|
||||||
|
{
|
||||||
|
FileName fn = *this;
|
||||||
|
if (str.isEmpty())
|
||||||
|
return fn;
|
||||||
|
if (!isEmpty() && !m_data.endsWith(QLatin1Char('/')))
|
||||||
|
fn.m_data.append('/');
|
||||||
|
fn.m_data.append(str);
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
|
|
||||||
FileName FileName::stringAppended(const QString &str) const
|
FileName FileName::stringAppended(const QString &str) const
|
||||||
{
|
{
|
||||||
FileName fn = *this;
|
FileName fn = *this;
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ public:
|
|||||||
|
|
||||||
FileName relativeChildPath(const FileName &parent) const;
|
FileName relativeChildPath(const FileName &parent) const;
|
||||||
FileName &appendPath(const QString &s);
|
FileName &appendPath(const QString &s);
|
||||||
|
FileName pathAppended(const QString &str) const;
|
||||||
FileName stringAppended(const QString &str) const;
|
FileName stringAppended(const QString &str) const;
|
||||||
|
|
||||||
void clear() { m_data.clear(); }
|
void clear() { m_data.clear(); }
|
||||||
|
|||||||
@@ -433,8 +433,7 @@ bool AvdManagerOutputParser::parseAvd(const QStringList &deviceInfo, AndroidDevi
|
|||||||
if (avdPath.exists())
|
if (avdPath.exists())
|
||||||
{
|
{
|
||||||
// Get ABI.
|
// Get ABI.
|
||||||
Utils::FileName configFile = avdPath;
|
const Utils::FileName configFile = avdPath.pathAppended("config.ini");
|
||||||
configFile.appendPath("config.ini");
|
|
||||||
QSettings config(configFile.toString(), QSettings::IniFormat);
|
QSettings config(configFile.toString(), QSettings::IniFormat);
|
||||||
value = config.value(avdInfoAbiKey).toString();
|
value = config.value(avdInfoAbiKey).toString();
|
||||||
if (!value.isEmpty())
|
if (!value.isEmpty())
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ void AndroidBuildApkStep::doRun()
|
|||||||
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
qmlRootPath = target()->project()->rootProjectDirectory().toString();
|
||||||
deploySettings["qml-root-path"] = qmlImportPath;
|
deploySettings["qml-root-path"] = qmlImportPath;
|
||||||
|
|
||||||
QFile f{bc->buildDirectory().appendPath("android_deployment_settings.json").toString()};
|
QFile f{bc->buildDirectory().pathAppended("android_deployment_settings.json").toString()};
|
||||||
if (!f.open(QIODevice::WriteOnly))
|
if (!f.open(QIODevice::WriteOnly))
|
||||||
return false;
|
return false;
|
||||||
f.write(QJsonDocument{deploySettings}.toJson());
|
f.write(QJsonDocument{deploySettings}.toJson());
|
||||||
|
|||||||
@@ -271,8 +271,7 @@ void AndroidConfig::updateNdkInformation() const
|
|||||||
if (m_NdkInformationUpToDate)
|
if (m_NdkInformationUpToDate)
|
||||||
return;
|
return;
|
||||||
m_availableNdkPlatforms.clear();
|
m_availableNdkPlatforms.clear();
|
||||||
FileName path = ndkLocation();
|
QDirIterator it(m_ndkLocation.pathAppended("platforms").toString(), QStringList("android-*"), QDir::Dirs);
|
||||||
QDirIterator it(path.appendPath("platforms").toString(), QStringList("android-*"), QDir::Dirs);
|
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
const QString &fileName = it.next();
|
const QString &fileName = it.next();
|
||||||
m_availableNdkPlatforms.push_back(fileName.midRef(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
|
m_availableNdkPlatforms.push_back(fileName.midRef(fileName.lastIndexOf(QLatin1Char('-')) + 1).toInt());
|
||||||
@@ -294,8 +293,7 @@ void AndroidConfig::updateNdkInformation() const
|
|||||||
default: /* unknown host */ return;
|
default: /* unknown host */ return;
|
||||||
}
|
}
|
||||||
|
|
||||||
path = ndkLocation();
|
QDirIterator jt(m_ndkLocation.pathAppended("prebuilt").toString(), hostPatterns, QDir::Dirs);
|
||||||
QDirIterator jt(path.appendPath(QLatin1String("prebuilt")).toString(), hostPatterns, QDir::Dirs);
|
|
||||||
if (jt.hasNext()) {
|
if (jt.hasNext()) {
|
||||||
jt.next();
|
jt.next();
|
||||||
m_toolchainHost = jt.fileName();
|
m_toolchainHost = jt.fileName();
|
||||||
@@ -317,8 +315,7 @@ QString AndroidConfig::apiLevelNameFor(const SdkPlatform *platform)
|
|||||||
|
|
||||||
FileName AndroidConfig::adbToolPath() const
|
FileName AndroidConfig::adbToolPath() const
|
||||||
{
|
{
|
||||||
FileName path = m_sdkLocation;
|
return m_sdkLocation.pathAppended("platform-tools/adb" QTC_HOST_EXE_SUFFIX);
|
||||||
return path.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::androidToolPath() const
|
FileName AndroidConfig::androidToolPath() const
|
||||||
@@ -326,35 +323,28 @@ FileName AndroidConfig::androidToolPath() const
|
|||||||
if (HostOsInfo::isWindowsHost()) {
|
if (HostOsInfo::isWindowsHost()) {
|
||||||
// I want to switch from using android.bat to using an executable. All it really does is call
|
// I want to switch from using android.bat to using an executable. All it really does is call
|
||||||
// Java and I've made some progress on it. So if android.exe exists, return that instead.
|
// Java and I've made some progress on it. So if android.exe exists, return that instead.
|
||||||
FileName path = m_sdkLocation;
|
const FileName path = m_sdkLocation.pathAppended("tools/android" QTC_HOST_EXE_SUFFIX);
|
||||||
path.appendPath(QLatin1String("tools/android" QTC_HOST_EXE_SUFFIX));
|
|
||||||
if (path.exists())
|
if (path.exists())
|
||||||
return path;
|
return path;
|
||||||
path = m_sdkLocation;
|
return m_sdkLocation.pathAppended("tools/android" ANDROID_BAT_SUFFIX);
|
||||||
return path.appendPath(QLatin1String("tools/android" ANDROID_BAT_SUFFIX));
|
|
||||||
} else {
|
|
||||||
FileName path = m_sdkLocation;
|
|
||||||
return path.appendPath(QLatin1String("tools/android"));
|
|
||||||
}
|
}
|
||||||
|
return m_sdkLocation.pathAppended("tools/android");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::emulatorToolPath() const
|
FileName AndroidConfig::emulatorToolPath() const
|
||||||
{
|
{
|
||||||
FileName path = m_sdkLocation;
|
|
||||||
QString relativePath = "emulator/emulator";
|
QString relativePath = "emulator/emulator";
|
||||||
if (sdkToolsVersion() < QVersionNumber(25, 3, 0))
|
if (sdkToolsVersion() < QVersionNumber(25, 3, 0))
|
||||||
relativePath = "tools/emulator";
|
relativePath = "tools/emulator";
|
||||||
return path.appendPath(relativePath + QTC_HOST_EXE_SUFFIX);
|
return m_sdkLocation.pathAppended(relativePath + QTC_HOST_EXE_SUFFIX);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::sdkManagerToolPath() const
|
FileName AndroidConfig::sdkManagerToolPath() const
|
||||||
{
|
{
|
||||||
FileName sdkPath = m_sdkLocation;
|
|
||||||
QString toolPath = "tools/bin/sdkmanager";
|
QString toolPath = "tools/bin/sdkmanager";
|
||||||
if (HostOsInfo::isWindowsHost())
|
if (HostOsInfo::isWindowsHost())
|
||||||
toolPath += ANDROID_BAT_SUFFIX;
|
toolPath += ANDROID_BAT_SUFFIX;
|
||||||
sdkPath = sdkPath.appendPath(toolPath);
|
return m_sdkLocation.pathAppended(toolPath);
|
||||||
return sdkPath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::avdManagerToolPath() const
|
FileName AndroidConfig::avdManagerToolPath() const
|
||||||
@@ -380,10 +370,8 @@ FileName AndroidConfig::aaptToolPath() const
|
|||||||
|
|
||||||
FileName AndroidConfig::clangPath() const
|
FileName AndroidConfig::clangPath() const
|
||||||
{
|
{
|
||||||
FileName clangPath = m_ndkLocation;
|
const FileName clangPath = m_ndkLocation.pathAppended("toolchains/llvm/prebuilt/");
|
||||||
clangPath.appendPath("toolchains/llvm/prebuilt/");
|
const FileName oldNdkClangPath = m_ndkLocation.pathAppended("toolchains/llvm-3.6/prebuilt/");
|
||||||
FileName oldNdkClangPath = m_ndkLocation;
|
|
||||||
oldNdkClangPath.appendPath("toolchains/llvm-3.6/prebuilt/");
|
|
||||||
const QVector<FileName> clangSearchPaths{clangPath, oldNdkClangPath};
|
const QVector<FileName> clangSearchPaths{clangPath, oldNdkClangPath};
|
||||||
|
|
||||||
// detect toolchain host
|
// detect toolchain host
|
||||||
@@ -430,22 +418,21 @@ FileName AndroidConfig::gdbPath(const ProjectExplorer::Abi &abi) const
|
|||||||
|
|
||||||
FileName AndroidConfig::makePath() const
|
FileName AndroidConfig::makePath() const
|
||||||
{
|
{
|
||||||
FileName path = m_ndkLocation;
|
return m_ndkLocation.pathAppended(
|
||||||
path.appendPath(QString("prebuilt/%1/bin/make%2").arg(toolchainHost(), QTC_HOST_EXE_SUFFIX));
|
QString("prebuilt/%1/bin/make%2").arg(toolchainHost(), QTC_HOST_EXE_SUFFIX));
|
||||||
return path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::openJDKBinPath() const
|
FileName AndroidConfig::openJDKBinPath() const
|
||||||
{
|
{
|
||||||
FileName path = m_openJDKLocation;
|
const FileName path = m_openJDKLocation;
|
||||||
if (!path.isEmpty())
|
if (!path.isEmpty())
|
||||||
return path.appendPath(QLatin1String("bin"));
|
return path.pathAppended("bin");
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileName AndroidConfig::keytoolPath() const
|
FileName AndroidConfig::keytoolPath() const
|
||||||
{
|
{
|
||||||
return openJDKBinPath().appendPath(keytoolName);
|
return openJDKBinPath().pathAppended(keytoolName);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(QString *error) const
|
QVector<AndroidDeviceInfo> AndroidConfig::connectedDevices(QString *error) const
|
||||||
|
|||||||
Reference in New Issue
Block a user