diff options
author | Soheil Armin <soheil.armin@qt.io> | 2024-04-25 16:26:38 +0300 |
---|---|---|
committer | Tinja Paavoseppä <tinja.paavoseppa@qt.io> | 2024-05-15 12:34:08 +0300 |
commit | 28b384898924fc2862c21876c73b1bcba52edd72 (patch) | |
tree | edfd049fc3445bc4e32178fbff3dec3ab9afc4a2 | |
parent | 79f3fe70407932450e36e9a69046bbe923b8e445 (diff) |
Android: Refactor packagePath() in androiddeployqt
Make the method handle all the different possible
paths in a more clean way.
Task-number: QTBUG-116955
Task-number: QTBUG-65567
Change-Id: If0ed1b529011b942c0fb67d0ad7a940896e03c85
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r-- | src/tools/androiddeployqt/main.cpp | 67 |
1 files changed, 29 insertions, 38 deletions
diff --git a/src/tools/androiddeployqt/main.cpp b/src/tools/androiddeployqt/main.cpp index c2af8d381c..4ff5737381 100644 --- a/src/tools/androiddeployqt/main.cpp +++ b/src/tools/androiddeployqt/main.cpp @@ -2972,47 +2972,38 @@ enum PackageType { SignedAPK }; -QString packagePath(const Options &options, PackageType pt) +QString packagePath(const Options &options, PackageType packageType) { - QString path(options.outputDirectory); // The package type is always AAR if option.buildAar has been set if (options.buildAar) - pt = AAR; - static QHash<PackageType, QString> packageTypeToPath{ { AAB, QStringLiteral("bundle") }, - { AAR, QStringLiteral("aar") }, - { UnsignedAPK, QStringLiteral("apk") }, - { SignedAPK, QStringLiteral("apk") } }; - path += "/build/outputs/%1/"_L1.arg(packageTypeToPath[pt]); - QString buildType(options.releasePackage ? "release/"_L1 : "debug/"_L1); - if (QDir(path + buildType).exists()) - path += buildType; - path += QDir(options.outputDirectory).dirName() + u'-'; - if (options.releasePackage) { - path += "release-"_L1; - if (pt >= UnsignedAPK) { - if (pt == UnsignedAPK) - path += "un"_L1; - path += "signed.apk"_L1; - } else if (pt == AAR){ - path.chop(1); - path += ".aar"_L1; - } else { - path.chop(1); - path += ".aab"_L1; - } - } else { - path += "debug"_L1; - if (pt >= UnsignedAPK) { - if (pt == SignedAPK) - path += "-signed"_L1; - path += ".apk"_L1; - } else if (pt == AAR){ - path += ".aar"_L1; - } else { - path += ".aab"_L1; - } - } - return path; + packageType = AAR; + + static const QHash<PackageType, QLatin1StringView> packageTypeToPath{ + { AAB, "bundle"_L1 }, { AAR, "aar"_L1 }, { UnsignedAPK, "apk"_L1 }, { SignedAPK, "apk"_L1 } + }; + static const QHash<PackageType, QLatin1StringView> packageTypeToExtension{ + { AAB, "aab"_L1 }, { AAR, "aar"_L1 }, { UnsignedAPK, "apk"_L1 }, { SignedAPK, "apk"_L1 } + }; + + const QString buildType(options.releasePackage ? "release"_L1 : "debug"_L1); + QString signedSuffix; + if (packageType == SignedAPK) + signedSuffix = "-signed"_L1; + else if (packageType == UnsignedAPK && options.releasePackage) + signedSuffix = "-unsigned"_L1; + + QString dirPath(options.outputDirectory); + dirPath += "/build/outputs/%1/"_L1.arg(packageTypeToPath[packageType]); + if (QDir(dirPath + buildType).exists()) + dirPath += buildType; + + const QString fileName = "/%1-%2%3.%4"_L1.arg( + QDir(options.outputDirectory).dirName(), + buildType, + signedSuffix, + packageTypeToExtension[packageType]); + + return dirPath + fileName; } bool installApk(const Options &options) |