Android: add helper functions to append .exe/.bat suffix when needed
Instead of having to do that each time for multiple paths, a common helper function is better. Change-Id: Ice2499f390a5790c5768eca037d186ad2e656ec7 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
63d630bcbb
commit
a91cc01011
@ -329,19 +329,48 @@ QString architectureFromName(const QString &name)
|
|||||||
return match.captured(1);
|
return match.captured(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString execSuffixAppended(QString path)
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN32)
|
||||||
|
path += ".exe"_L1;
|
||||||
|
#endif
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString batSuffixAppended(QString path)
|
||||||
|
{
|
||||||
|
#if defined(Q_OS_WIN32)
|
||||||
|
path += ".bat"_L1;
|
||||||
|
#endif
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString defaultLibexecDir()
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
return "bin"_L1;
|
||||||
|
#else
|
||||||
|
return "libexec"_L1;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString llvmReadobjPath(const Options &options)
|
||||||
|
{
|
||||||
|
return execSuffixAppended("%1/toolchains/%2/prebuilt/%3/bin/llvm-readobj"_L1
|
||||||
|
.arg(options.ndkPath,
|
||||||
|
options.toolchainPrefix,
|
||||||
|
options.ndkHost));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString fileArchitecture(const Options &options, const QString &path)
|
QString fileArchitecture(const Options &options, const QString &path)
|
||||||
{
|
{
|
||||||
auto arch = architectureFromName(path);
|
auto arch = architectureFromName(path);
|
||||||
if (!arch.isEmpty())
|
if (!arch.isEmpty())
|
||||||
return arch;
|
return arch;
|
||||||
|
|
||||||
QString readElf = "%1/toolchains/%2/prebuilt/%3/bin/llvm-readobj"_L1.arg(options.ndkPath,
|
QString readElf = llvmReadobjPath(options);
|
||||||
options.toolchainPrefix,
|
|
||||||
options.ndkHost);
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
readElf += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(readElf)) {
|
if (!QFile::exists(readElf)) {
|
||||||
fprintf(stderr, "Command does not exist: %s\n", qPrintable(readElf));
|
fprintf(stderr, "Command does not exist: %s\n", qPrintable(readElf));
|
||||||
return {};
|
return {};
|
||||||
@ -1853,13 +1882,7 @@ bool readAndroidDependencyXml(Options *options,
|
|||||||
|
|
||||||
QStringList getQtLibsFromElf(const Options &options, const QString &fileName)
|
QStringList getQtLibsFromElf(const Options &options, const QString &fileName)
|
||||||
{
|
{
|
||||||
QString readElf = "%1/toolchains/%2/prebuilt/%3/bin/llvm-readobj"_L1.arg(options.ndkPath,
|
QString readElf = llvmReadobjPath(options);
|
||||||
options.toolchainPrefix,
|
|
||||||
options.ndkHost);
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
readElf += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(readElf)) {
|
if (!QFile::exists(readElf)) {
|
||||||
fprintf(stderr, "Command does not exist: %s\n", qPrintable(readElf));
|
fprintf(stderr, "Command does not exist: %s\n", qPrintable(readElf));
|
||||||
return QStringList();
|
return QStringList();
|
||||||
@ -1951,15 +1974,6 @@ bool readDependenciesFromElf(Options *options,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString defaultLibexecDir()
|
|
||||||
{
|
|
||||||
#ifdef Q_OS_WIN32
|
|
||||||
return QStringLiteral("bin");
|
|
||||||
#else
|
|
||||||
return QStringLiteral("libexec");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies);
|
bool goodToCopy(const Options *options, const QString &file, QStringList *unmetDependencies);
|
||||||
bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath);
|
bool checkQmlFileInRootPaths(const Options *options, const QString &absolutePath);
|
||||||
|
|
||||||
@ -1972,12 +1986,9 @@ bool scanImports(Options *options, QSet<QString> *usedDependencies)
|
|||||||
if (!options->qmlImportScannerBinaryPath.isEmpty()) {
|
if (!options->qmlImportScannerBinaryPath.isEmpty()) {
|
||||||
qmlImportScanner = options->qmlImportScannerBinaryPath;
|
qmlImportScanner = options->qmlImportScannerBinaryPath;
|
||||||
} else {
|
} else {
|
||||||
qmlImportScanner = options->qtInstallDirectory + u'/' + defaultLibexecDir()
|
qmlImportScanner = execSuffixAppended(options->qtInstallDirectory + u'/'
|
||||||
+ "/qmlimportscanner"_L1;
|
+ defaultLibexecDir() + "/qmlimportscanner"_L1);
|
||||||
}
|
}
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
qmlImportScanner += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
QStringList importPaths;
|
QStringList importPaths;
|
||||||
importPaths += shellQuote(options->qtInstallDirectory + "/qml"_L1);
|
importPaths += shellQuote(options->qtInstallDirectory + "/qml"_L1);
|
||||||
@ -2227,14 +2238,12 @@ bool createRcc(const Options &options)
|
|||||||
|
|
||||||
|
|
||||||
QString rcc;
|
QString rcc;
|
||||||
if (!options.rccBinaryPath.isEmpty())
|
if (!options.rccBinaryPath.isEmpty()) {
|
||||||
rcc = options.rccBinaryPath;
|
rcc = options.rccBinaryPath;
|
||||||
else
|
} else {
|
||||||
rcc = options.qtInstallDirectory + u'/' + defaultLibexecDir() + "/rcc"_L1;
|
rcc = execSuffixAppended(options.qtInstallDirectory + u'/' + defaultLibexecDir() +
|
||||||
|
"/rcc"_L1);
|
||||||
#if defined(Q_OS_WIN32)
|
}
|
||||||
rcc += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(rcc)) {
|
if (!QFile::exists(rcc)) {
|
||||||
fprintf(stderr, "rcc not found: %s\n", qPrintable(rcc));
|
fprintf(stderr, "rcc not found: %s\n", qPrintable(rcc));
|
||||||
@ -2358,11 +2367,7 @@ bool containsApplicationBinary(Options *options)
|
|||||||
|
|
||||||
FILE *runAdb(const Options &options, const QString &arguments)
|
FILE *runAdb(const Options &options, const QString &arguments)
|
||||||
{
|
{
|
||||||
QString adb = options.sdkPath + "/platform-tools/adb"_L1;
|
QString adb = execSuffixAppended(options.sdkPath + "/platform-tools/adb"_L1);
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
adb += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(adb)) {
|
if (!QFile::exists(adb)) {
|
||||||
fprintf(stderr, "Cannot find adb tool: %s\n", qPrintable(adb));
|
fprintf(stderr, "Cannot find adb tool: %s\n", qPrintable(adb));
|
||||||
return 0;
|
return 0;
|
||||||
@ -2636,10 +2641,8 @@ bool buildAndroidProject(const Options &options)
|
|||||||
if (!mergeGradleProperties(gradlePropertiesPath, gradleProperties))
|
if (!mergeGradleProperties(gradlePropertiesPath, gradleProperties))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
#if defined(Q_OS_WIN32)
|
QString gradlePath = batSuffixAppended(options.outputDirectory + "gradlew"_L1);
|
||||||
QString gradlePath(options.outputDirectory + "gradlew.bat"_L1);
|
#ifndef Q_OS_WIN32
|
||||||
#else
|
|
||||||
QString gradlePath(options.outputDirectory + "gradlew"_L1);
|
|
||||||
{
|
{
|
||||||
QFile f(gradlePath);
|
QFile f(gradlePath);
|
||||||
if (!f.setPermissions(f.permissions() | QFileDevice::ExeUser))
|
if (!f.setPermissions(f.permissions() | QFileDevice::ExeUser))
|
||||||
@ -2820,6 +2823,22 @@ bool copyStdCpp(Options *options)
|
|||||||
return copyFileIfNewer(stdCppPath, destinationFile, *options);
|
return copyFileIfNewer(stdCppPath, destinationFile, *options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QString zipalignPath(const Options &options, bool *ok)
|
||||||
|
{
|
||||||
|
*ok = true;
|
||||||
|
QString zipAlignTool = execSuffixAppended(options.sdkPath + "/tools/zipalign"_L1);
|
||||||
|
if (!QFile::exists(zipAlignTool)) {
|
||||||
|
zipAlignTool = execSuffixAppended(options.sdkPath + "/build-tools/"_L1 +
|
||||||
|
options.sdkBuildToolsVersion + "/zipalign"_L1);
|
||||||
|
if (!QFile::exists(zipAlignTool)) {
|
||||||
|
fprintf(stderr, "zipalign tool not found: %s\n", qPrintable(zipAlignTool));
|
||||||
|
*ok = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return zipAlignTool;
|
||||||
|
}
|
||||||
|
|
||||||
bool jarSignerSignPackage(const Options &options)
|
bool jarSignerSignPackage(const Options &options)
|
||||||
{
|
{
|
||||||
if (options.verbose)
|
if (options.verbose)
|
||||||
@ -2830,12 +2849,7 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
if (jdkPath.isEmpty())
|
if (jdkPath.isEmpty())
|
||||||
jdkPath = QString::fromLocal8Bit(qgetenv("JAVA_HOME"));
|
jdkPath = QString::fromLocal8Bit(qgetenv("JAVA_HOME"));
|
||||||
|
|
||||||
#if defined(Q_OS_WIN32)
|
QString jarSignerTool = execSuffixAppended("jarsigner"_L1);
|
||||||
QString jarSignerTool = "jarsigner.exe"_L1;
|
|
||||||
#else
|
|
||||||
QString jarSignerTool = "jarsigner"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (jdkPath.isEmpty() || !QFile::exists(jdkPath + "/bin/"_L1 + jarSignerTool))
|
if (jdkPath.isEmpty() || !QFile::exists(jdkPath + "/bin/"_L1 + jarSignerTool))
|
||||||
jarSignerTool = findInPath(jarSignerTool);
|
jarSignerTool = findInPath(jarSignerTool);
|
||||||
else
|
else
|
||||||
@ -2912,21 +2926,10 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
if (options.buildAAB && !signPackage(packagePath(options, AAB)))
|
if (options.buildAAB && !signPackage(packagePath(options, AAB)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
QString zipAlignTool = options.sdkPath + "/tools/zipalign"_L1;
|
bool ok;
|
||||||
#if defined(Q_OS_WIN32)
|
QString zipAlignTool = zipalignPath(options, &ok);
|
||||||
zipAlignTool += ".exe"_L1;
|
if (!ok)
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(zipAlignTool)) {
|
|
||||||
zipAlignTool = options.sdkPath + "/build-tools/"_L1 + options.sdkBuildToolsVersion + "/zipalign"_L1;
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
zipAlignTool += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
if (!QFile::exists(zipAlignTool)) {
|
|
||||||
fprintf(stderr, "zipalign tool not found: %s\n", qPrintable(zipAlignTool));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
zipAlignTool = "%1%2 -f 4 %3 %4"_L1.arg(shellQuote(zipAlignTool),
|
zipAlignTool = "%1%2 -f 4 %3 %4"_L1.arg(shellQuote(zipAlignTool),
|
||||||
options.verbose ? " -v"_L1 : QLatin1StringView(),
|
options.verbose ? " -v"_L1 : QLatin1StringView(),
|
||||||
@ -2956,31 +2959,18 @@ bool jarSignerSignPackage(const Options &options)
|
|||||||
|
|
||||||
bool signPackage(const Options &options)
|
bool signPackage(const Options &options)
|
||||||
{
|
{
|
||||||
QString apksignerTool = options.sdkPath + "/build-tools/"_L1 + options.sdkBuildToolsVersion + "/apksigner"_L1;
|
const QString apksignerTool = batSuffixAppended(options.sdkPath + "/build-tools/"_L1 +
|
||||||
#if defined(Q_OS_WIN32)
|
options.sdkBuildToolsVersion + "/apksigner"_L1);
|
||||||
apksignerTool += ".bat"_L1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (options.jarSigner || !QFile::exists(apksignerTool))
|
if (options.jarSigner || !QFile::exists(apksignerTool))
|
||||||
return jarSignerSignPackage(options);
|
return jarSignerSignPackage(options);
|
||||||
|
|
||||||
// APKs signed with apksigner must not be changed after they're signed, therefore we need to zipalign it before we sign it.
|
// APKs signed with apksigner must not be changed after they're signed,
|
||||||
|
// therefore we need to zipalign it before we sign it.
|
||||||
|
|
||||||
QString zipAlignTool = options.sdkPath + "/tools/zipalign"_L1;
|
bool ok;
|
||||||
#if defined(Q_OS_WIN32)
|
QString zipAlignTool = zipalignPath(options, &ok);
|
||||||
zipAlignTool += ".exe"_L1;
|
if (!ok)
|
||||||
#endif
|
|
||||||
|
|
||||||
if (!QFile::exists(zipAlignTool)) {
|
|
||||||
zipAlignTool = options.sdkPath + "/build-tools/"_L1 + options.sdkBuildToolsVersion + "/zipalign"_L1;
|
|
||||||
#if defined(Q_OS_WIN32)
|
|
||||||
zipAlignTool += ".exe"_L1;
|
|
||||||
#endif
|
|
||||||
if (!QFile::exists(zipAlignTool)) {
|
|
||||||
fprintf(stderr, "zipalign tool not found: %s\n", qPrintable(zipAlignTool));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto zipalignRunner = [](const QString &zipAlignCommandLine) {
|
auto zipalignRunner = [](const QString &zipAlignCommandLine) {
|
||||||
FILE *zipAlignCommand = openProcess(zipAlignCommandLine);
|
FILE *zipAlignCommand = openProcess(zipAlignCommandLine);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user