Android: Further FilePathify AndroidBuildApkStep

Change-Id: I98073dfc74baaa145867cae64e4b23735e3c730d
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
hjk
2021-08-17 18:10:52 +02:00
parent d3ff45ad8b
commit 2d019ed659
2 changed files with 35 additions and 40 deletions

View File

@@ -228,8 +228,7 @@ QWidget *AndroidBuildApkWidget::createSignPackageGroup()
keystoreLocationChooser->setInitialBrowsePathBackup(FileUtils::homePath()); keystoreLocationChooser->setInitialBrowsePathBackup(FileUtils::homePath());
keystoreLocationChooser->setPromptDialogFilter(tr("Keystore files (*.keystore *.jks)")); keystoreLocationChooser->setPromptDialogFilter(tr("Keystore files (*.keystore *.jks)"));
keystoreLocationChooser->setPromptDialogTitle(tr("Select Keystore File")); keystoreLocationChooser->setPromptDialogTitle(tr("Select Keystore File"));
connect(keystoreLocationChooser, &PathChooser::pathChanged, this, [this](const QString &path) { connect(keystoreLocationChooser, &PathChooser::filePathChanged, this, [this](const FilePath &file) {
FilePath file = FilePath::fromString(path);
m_step->setKeystorePath(file); m_step->setKeystorePath(file);
m_signPackageCheckBox->setChecked(!file.isEmpty()); m_signPackageCheckBox->setChecked(!file.isEmpty());
if (!file.isEmpty()) if (!file.isEmpty())
@@ -565,10 +564,9 @@ bool AndroidBuildApkStep::init()
qCDebug(buildapkstepLog) << "APK or AAB path:" << m_packagePath; qCDebug(buildapkstepLog) << "APK or AAB path:" << m_packagePath;
FilePath command = version->hostBinPath().pathAppended("androiddeployqt").withExecutableSuffix(); FilePath command = version->hostBinPath().pathAppended("androiddeployqt").withExecutableSuffix();
FilePath outputDir = buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY);
QString outputDir = buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY).toString(); m_inputFile = AndroidQtVersion::androidDeploymentSettings(target());
m_inputFile = AndroidQtVersion::androidDeploymentSettings(target()).toString();
if (m_inputFile.isEmpty()) { if (m_inputFile.isEmpty()) {
qCDebug(buildapkstepLog) << "no input file" << target()->activeBuildKey(); qCDebug(buildapkstepLog) << "no input file" << target()->activeBuildKey();
m_skipBuilding = true; m_skipBuilding = true;
@@ -583,8 +581,8 @@ bool AndroidBuildApkStep::init()
return false; return false;
} }
QStringList arguments = {"--input", m_inputFile, QStringList arguments = {"--input", m_inputFile.toString(),
"--output", outputDir, "--output", outputDir.toString(),
"--android-platform", m_buildTargetSdk, "--android-platform", m_buildTargetSdk,
"--jdk", AndroidConfigurations::currentConfig().openJDKLocation().toString()}; "--jdk", AndroidConfigurations::currentConfig().openJDKLocation().toString()};
@@ -625,7 +623,7 @@ bool AndroidBuildApkStep::init()
ProjectExplorer::ProcessParameters pp2; ProjectExplorer::ProcessParameters pp2;
setupProcessParameters(&pp2); setupProcessParameters(&pp2);
pp2.setCommandLine({command, argumentsPasswordConcealed}); pp2.setCommandLine({command, argumentsPasswordConcealed});
m_command = pp2.effectiveCommand().toString(); m_command = pp2.effectiveCommand();
m_argumentsPasswordConcealed = pp2.prettyArguments(); m_argumentsPasswordConcealed = pp2.prettyArguments();
return true; return true;
@@ -638,11 +636,10 @@ void AndroidBuildApkStep::setupOutputFormatter(OutputFormatter *formatter)
const QString buildKey = target()->activeBuildKey(); const QString buildKey = target()->activeBuildKey();
const ProjectNode *node = project()->findNodeForBuildKey(buildKey); const ProjectNode *node = project()->findNodeForBuildKey(buildKey);
QString sourceDirName; FilePath sourceDirPath;
if (node) if (node)
sourceDirName = node->data(Constants::AndroidPackageSourceDir).toString(); sourceDirPath = FilePath::fromVariant(node->data(Constants::AndroidPackageSourceDir));
QFileInfo sourceDirInfo(sourceDirName); parser->setSourceDirectory(sourceDirPath.canonicalPath());
parser->setSourceDirectory(Utils::FilePath::fromString(sourceDirInfo.canonicalFilePath()));
parser->setBuildDirectory(buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY)); parser->setBuildDirectory(buildDirectory().pathAppended(Constants::ANDROID_BUILDDIRECTORY));
formatter->addLineParser(parser); formatter->addLineParser(parser);
AbstractProcessStep::setupOutputFormatter(formatter); AbstractProcessStep::setupOutputFormatter(formatter);
@@ -714,23 +711,21 @@ bool AndroidBuildApkStep::verifyCertificatePassword()
} }
static bool copyFileIfNewer(const QString &sourceFileName, static bool copyFileIfNewer(const FilePath &sourceFilePath,
const QString &destinationFileName) const FilePath &destinationFilePath)
{ {
if (sourceFileName == destinationFileName) if (sourceFilePath == destinationFilePath)
return true; return true;
if (QFile::exists(destinationFileName)) { if (destinationFilePath.exists()) {
QFileInfo destinationFileInfo(destinationFileName); if (sourceFilePath.lastModified() <= destinationFilePath.lastModified())
QFileInfo sourceFileInfo(sourceFileName);
if (sourceFileInfo.lastModified() <= destinationFileInfo.lastModified())
return true; return true;
if (!QFile(destinationFileName).remove()) if (!destinationFilePath.removeFile())
return false; return false;
} }
if (!QDir().mkpath(QFileInfo(destinationFileName).path())) if (!destinationFilePath.parentDir().ensureWritableDir())
return false; return false;
return QFile::copy(sourceFileName, destinationFileName); return sourceFilePath.copyFile(destinationFilePath);
} }
void AndroidBuildApkStep::doRun() void AndroidBuildApkStep::doRun()
@@ -754,9 +749,9 @@ void AndroidBuildApkStep::doRun()
for (const auto &abi : androidAbis) { for (const auto &abi : androidAbis) {
FilePath androidLibsDir = buildDirectory() / "android-build/libs" / abi; FilePath androidLibsDir = buildDirectory() / "android-build/libs" / abi;
if (!androidLibsDir.exists()) { if (!androidLibsDir.exists()) {
if (!QDir{buildDirectory().toString()}.mkpath(androidLibsDir.toString())) { if (!androidLibsDir.ensureWritableDir()) {
const QString error = tr("The Android build folder %1 wasn't found and " const QString error = tr("The Android build folder %1 wasn't found and "
"couldn't be created.").arg(androidLibsDir.toString()); "couldn't be created.").arg(androidLibsDir.toUserOutput());
emit addOutput(error, BuildStep::OutputFormat::ErrorMessage); emit addOutput(error, BuildStep::OutputFormat::ErrorMessage);
TaskHub::addTask(BuildSystemTask(Task::Error, error)); TaskHub::addTask(BuildSystemTask(Task::Error, error));
return false; return false;
@@ -771,10 +766,10 @@ void AndroidBuildApkStep::doRun()
if (!from.exists() || to.exists()) if (!from.exists() || to.exists())
continue; continue;
if (!QFile::copy(from.toString(), to.toString())) { if (!from.copyFile(to)) {
const QString error = tr("Couldn't copy the target's lib file %1 to the " const QString error = tr("Couldn't copy the target's lib file %1 to the "
"Android build folder %2.") "Android build folder %2.")
.arg(fileName, androidLibsDir.toString()); .arg(fileName, androidLibsDir.toUserOutput());
emit addOutput(error, BuildStep::OutputFormat::ErrorMessage); emit addOutput(error, BuildStep::OutputFormat::ErrorMessage);
TaskHub::addTask(BuildSystemTask(Task::Error, error)); TaskHub::addTask(BuildSystemTask(Task::Error, error));
return false; return false;
@@ -784,12 +779,13 @@ void AndroidBuildApkStep::doRun()
} }
bool inputExists = QFile::exists(m_inputFile); bool inputExists = m_inputFile.exists();
if (inputExists && !AndroidManager::isQtCreatorGenerated(FilePath::fromString(m_inputFile))) if (inputExists && !AndroidManager::isQtCreatorGenerated(m_inputFile))
return true; // use the generated file if it was not generated by qtcreator return true; // use the generated file if it was not generated by qtcreator
BuildSystem *bs = buildSystem(); BuildSystem *bs = buildSystem();
auto targets = bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(); const FilePaths targets = Utils::transform(bs->extraData(buildKey, Android::Constants::AndroidTargets).toStringList(),
&FilePath::fromString);
if (targets.isEmpty()) if (targets.isEmpty())
return inputExists; // qmake does this job for us return inputExists; // qmake does this job for us
@@ -799,8 +795,8 @@ void AndroidBuildApkStep::doRun()
QTC_ASSERT(androidAbis.size() == 1, return false); QTC_ASSERT(androidAbis.size() == 1, return false);
applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.toString(); applicationBinary = buildSystem()->buildTarget(buildKey).targetFilePath.toString();
FilePath androidLibsDir = buildDirectory() / "android-build/libs" / androidAbis.first(); FilePath androidLibsDir = buildDirectory() / "android-build/libs" / androidAbis.first();
for (const auto &target : targets) { for (const FilePath &target : targets) {
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(QFileInfo{target}.fileName()).toString())) if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName())))
return false; return false;
} }
deploySettings["target-architecture"] = androidAbis.first(); deploySettings["target-architecture"] = androidAbis.first();
@@ -817,9 +813,9 @@ void AndroidBuildApkStep::doRun()
} }
FilePath androidLibsDir = buildDirectory() / "android-build/libs" / abi; FilePath androidLibsDir = buildDirectory() / "android-build/libs" / abi;
for (const auto &target : targets) { for (const FilePath &target : targets) {
if (target.endsWith(targetSuffix)) { if (target.endsWith(targetSuffix)) {
if (!copyFileIfNewer(target, androidLibsDir.pathAppended(QFileInfo{target}.fileName()).toString())) if (!copyFileIfNewer(target, androidLibsDir.pathAppended(target.fileName())))
return false; return false;
architectures[abi] = AndroidManager::archTriplet(abi); architectures[abi] = AndroidManager::archTriplet(abi);
} }
@@ -846,7 +842,7 @@ void AndroidBuildApkStep::doRun()
qmlRootPath = target()->project()->rootProjectDirectory().toString(); qmlRootPath = target()->project()->rootProjectDirectory().toString();
deploySettings["qml-root-path"] = qmlRootPath; deploySettings["qml-root-path"] = qmlRootPath;
QFile f{m_inputFile}; QFile f{m_inputFile.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());
@@ -867,14 +863,13 @@ void AndroidBuildApkStep::doRun()
void AndroidBuildApkStep::processStarted() void AndroidBuildApkStep::processStarted()
{ {
emit addOutput(tr("Starting: \"%1\" %2") emit addOutput(tr("Starting: \"%1\" %2")
.arg(QDir::toNativeSeparators(m_command), .arg(m_command.toUserOutput(), m_argumentsPasswordConcealed),
m_argumentsPasswordConcealed),
BuildStep::OutputFormat::NormalMessage); BuildStep::OutputFormat::NormalMessage);
} }
bool AndroidBuildApkStep::fromMap(const QVariantMap &map) bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
{ {
m_keystorePath = Utils::FilePath::fromString(map.value(KeystoreLocationKey).toString()); m_keystorePath = FilePath::fromVariant(map.value(KeystoreLocationKey));
m_signPackage = false; // don't restore this m_signPackage = false; // don't restore this
m_buildTargetSdk = map.value(BuildTargetSdkKey).toString(); m_buildTargetSdk = map.value(BuildTargetSdkKey).toString();
if (m_buildTargetSdk.isEmpty()) { if (m_buildTargetSdk.isEmpty()) {
@@ -888,7 +883,7 @@ bool AndroidBuildApkStep::fromMap(const QVariantMap &map)
QVariantMap AndroidBuildApkStep::toMap() const QVariantMap AndroidBuildApkStep::toMap() const
{ {
QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap(); QVariantMap map = ProjectExplorer::AbstractProcessStep::toMap();
map.insert(KeystoreLocationKey, m_keystorePath.toString()); map.insert(KeystoreLocationKey, m_keystorePath.toVariant());
map.insert(BuildTargetSdkKey, m_buildTargetSdk); map.insert(BuildTargetSdkKey, m_buildTargetSdk);
map.insert(VerboseOutputKey, m_verbose); map.insert(VerboseOutputKey, m_verbose);
return map; return map;

View File

@@ -106,10 +106,10 @@ private:
QString m_certificatePasswd; QString m_certificatePasswd;
Utils::FilePath m_packagePath; Utils::FilePath m_packagePath;
QString m_command; Utils::FilePath m_command;
QString m_argumentsPasswordConcealed; QString m_argumentsPasswordConcealed;
bool m_skipBuilding = false; bool m_skipBuilding = false;
QString m_inputFile; Utils::FilePath m_inputFile;
}; };
class AndroidBuildApkStepFactory : public ProjectExplorer::BuildStepFactory class AndroidBuildApkStepFactory : public ProjectExplorer::BuildStepFactory