diff options
Diffstat (limited to 'tools/repogen')
-rw-r--r-- | tools/repogen/repogen.cpp | 145 | ||||
-rw-r--r-- | tools/repogen/repogen.pro | 7 |
2 files changed, 67 insertions, 85 deletions
diff --git a/tools/repogen/repogen.cpp b/tools/repogen/repogen.cpp index a88867e92..2abe67e78 100644 --- a/tools/repogen/repogen.cpp +++ b/tools/repogen/repogen.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -34,24 +34,26 @@ #include <settings.h> #include <utils.h> #include <loggingutils.h> -#include <lib7z_facade.h> +#include <archivefactory.h> +#include <abstractarchive.h> #include <QDomDocument> #include <QtCore/QDir> #include <QtCore/QDirIterator> #include <QtCore/QFileInfo> #include <QTemporaryDir> +#include <QMetaEnum> #include <iostream> -#define QUOTE_(x) #x -#define QUOTE(x) QUOTE_(x) using namespace QInstaller; static void printUsage() { const QString appName = QFileInfo(QCoreApplication::applicationFilePath()).fileName(); + const QString archiveFormats = ArchiveFactory::supportedTypes().join(QLatin1Char('|')); + std::cout << "Usage: " << appName << " [options] repository-dir" << std::endl; std::cout << std::endl; std::cout << "Options:" << std::endl; @@ -73,6 +75,11 @@ static void printUsage() std::cout << " download phase." << std::endl; std::cout << " --component-metadata Creates one metadata 7z per component. " << std::endl; + std::cout << " --af|--archive-format " << archiveFormats << std::endl; + std::cout << " Set the format used when packaging new component data archives. If" << std::endl; + std::cout << " you omit this option the 7z format will be used as a default." << std::endl; + std::cout << " --ac|--compression 0,1,3,5,7,9" << std::endl; + std::cout << " Sets the compression level used when packaging new data archives." << std::endl; std::cout << std::endl; std::cout << "Example:" << std::endl; @@ -100,13 +107,15 @@ int main(int argc, char** argv) QStringList filteredPackages; bool updateExistingRepository = false; - QStringList packagesDirectories; - QStringList repositoryDirectories; + QInstallerTools::RepositoryInfo repoInfo; + QStringList packagesUpdatedWithSha; QInstallerTools::FilterType filterType = QInstallerTools::Exclude; bool remove = false; bool updateExistingRepositoryWithNewComponents = false; bool createUnifiedMetadata = true; bool createComponentMetadata = true; + QString archiveSuffix = QLatin1String("7z"); + AbstractArchive::CompressionLevel compression = AbstractArchive::Normal; //TODO: use a for loop without removing values from args like it is in binarycreator.cpp //for (QStringList::const_iterator it = args.begin(); it != args.end(); ++it) { @@ -151,7 +160,6 @@ int main(int argc, char** argv) } else if (args.first() == QLatin1String("--update-new-components")) { args.removeFirst(); updateExistingRepositoryWithNewComponents = true; - createUnifiedMetadata = false; } else if (args.first() == QLatin1String("-p") || args.first() == QLatin1String("--packages")) { args.removeFirst(); if (args.isEmpty()) { @@ -168,7 +176,7 @@ int main(int argc, char** argv) "Error: Package directory is empty")); } - packagesDirectories.append(args.first()); + repoInfo.packages.append(args.first()); args.removeFirst(); } else if (args.first() == QLatin1String("--repository")) { args.removeFirst(); @@ -177,11 +185,11 @@ int main(int argc, char** argv) "Error: Repository parameter missing argument")); } - if (!QFileInfo(args.first()).exists()) { + if (!QFileInfo::exists(args.first())) { return printErrorAndUsageAndExit(QCoreApplication::translate("QInstaller", "Error: Only local filesystem repositories now supported")); } - repositoryDirectories.append(args.first()); + repoInfo.repositoryPackages.append(args.first()); args.removeFirst(); } else if (args.first() == QLatin1String("--ignore-translations") || args.first() == QLatin1String("--ignore-invalid-packages")) { @@ -195,14 +203,41 @@ int main(int argc, char** argv) } else if (args.first() == QLatin1String("--component-metadata")) { createUnifiedMetadata = false; args.removeFirst(); - } - else { + } else if (args.first() == QLatin1String("--sha-update") || args.first() == QLatin1String("-s")) { + args.removeFirst(); + packagesUpdatedWithSha = args.first().split(QLatin1Char(',')); + args.removeFirst(); + } else if (args.first() == QLatin1String("--af") || args.first() == QLatin1String("--archive-format")) { + args.removeFirst(); + if (args.isEmpty()) { + return printErrorAndUsageAndExit(QCoreApplication::translate("QInstaller", + "Error: Archive format parameter missing argument")); + } + // TODO: do we need early check for supported formats? + archiveSuffix = args.first(); + args.removeFirst(); + } else if (args.first() == QLatin1String("--ac") || args.first() == QLatin1String("--compression")) { + args.removeFirst(); + if (args.isEmpty()) { + return printErrorAndUsageAndExit(QCoreApplication::translate("QInstaller", + "Error: Compression parameter missing argument")); + } + bool ok = false; + QMetaEnum levels = QMetaEnum::fromType<AbstractArchive::CompressionLevel>(); + const int value = args.first().toInt(&ok); + if (!ok || !levels.valueToKey(value)) { + return printErrorAndUsageAndExit(QCoreApplication::translate("QInstaller", + "Error: Unknown compression level \"%1\".").arg(value)); + } + compression = static_cast<AbstractArchive::CompressionLevel>(value); + args.removeFirst(); + } else { printUsage(); return 1; } } - if ((packagesDirectories.isEmpty() && repositoryDirectories.isEmpty()) || (args.count() != 1)) { + if ((repoInfo.packages.isEmpty() && repoInfo.repositoryPackages.isEmpty()) || (args.count() != 1)) { printUsage(); return 1; } @@ -213,90 +248,32 @@ int main(int argc, char** argv) "Argument -r|--remove and --update|--update-new-components are mutually exclusive!")); } - const QString repositoryDir = QInstallerTools::makePathAbsolute(args.first()); + repoInfo.repositoryDir = QInstallerTools::makePathAbsolute(args.first()); if (remove) - QInstaller::removeDirectory(repositoryDir); - - if (updateExistingRepositoryWithNewComponents) { - QStringList meta7z = QDir(repositoryDir).entryList(QStringList() - << QLatin1String("*_meta.7z"), QDir::Files); - if (!meta7z.isEmpty()) { - throw QInstaller::Error(QCoreApplication::translate("QInstaller", - "Cannot update \"%1\" with --update-new-components. Use --update instead. " - "Currently it is not possible to update partial components inside one 7z.") - .arg(meta7z.join(QLatin1Char(',')))); - } - } + QInstaller::removeDirectory(repoInfo.repositoryDir); - if (!update && QFile::exists(repositoryDir) && !QDir(repositoryDir).entryList( + if (!update && QFile::exists(repoInfo.repositoryDir) && !QDir(repoInfo.repositoryDir).entryList( QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) { throw QInstaller::Error(QCoreApplication::translate("QInstaller", - "Repository target directory \"%1\" already exists.").arg(QDir::toNativeSeparators(repositoryDir))); - } - - QInstallerTools::PackageInfoVector packages; - - QInstallerTools::PackageInfoVector precompressedPackages = QInstallerTools::createListOfRepositoryPackages(repositoryDirectories, - &filteredPackages, filterType); - packages.append(precompressedPackages); - - QInstallerTools::PackageInfoVector preparedPackages = QInstallerTools::createListOfPackages(packagesDirectories, - &filteredPackages, filterType); - packages.append(preparedPackages); - - if (updateExistingRepositoryWithNewComponents) { - QInstallerTools::filterNewComponents(repositoryDir, packages); - if (packages.isEmpty()) { - std::cout << QString::fromLatin1("Cannot find new components to update \"%1\".") - .arg(repositoryDir) << std::endl; - return EXIT_SUCCESS; - } + "Repository target directory \"%1\" already exists.").arg(QDir::toNativeSeparators(repoInfo.repositoryDir))); } - QHash<QString, QString> pathToVersionMapping = QInstallerTools::buildPathToVersionMapping(packages); - - foreach (const QInstallerTools::PackageInfo &package, packages) { - const QFileInfo fi(repositoryDir, package.name); - if (fi.exists()) - removeDirectory(fi.absoluteFilePath()); + QInstallerTools::PackageInfoVector packages = QInstallerTools::collectPackages(repoInfo, + &filteredPackages, filterType, updateExistingRepositoryWithNewComponents, packagesUpdatedWithSha); + if (packages.isEmpty()) { + std::cout << QString::fromLatin1("Cannot find components to update \"%1\".") + .arg(repoInfo.repositoryDir) << std::endl; + return EXIT_SUCCESS; } QTemporaryDir tmp; tmp.setAutoRemove(false); tmpMetaDir = tmp.path(); - QStringList directories; - directories.append(packagesDirectories); - directories.append(repositoryDirectories); - QStringList unite7zFiles; - foreach (const QString &repositoryDirectory, repositoryDirectories) { - QDirIterator it(repositoryDirectory, QStringList(QLatin1String("*_meta.7z")) - , QDir::Files | QDir::CaseSensitive); - while (it.hasNext()) { - it.next(); - unite7zFiles.append(it.fileInfo().absoluteFilePath()); - } - } - QInstallerTools::copyComponentData(directories, repositoryDir, &packages); - QInstallerTools::copyMetaData(tmpMetaDir, repositoryDir, packages, QLatin1String("{AnyApplication}"), - QLatin1String(QUOTE(IFW_REPOSITORY_FORMAT_VERSION)), unite7zFiles); - - QString existing7z = QInstallerTools::existingUniteMeta7z(repositoryDir); - if (!existing7z.isEmpty()) - existing7z = repositoryDir + QDir::separator() + existing7z; - QInstallerTools::compressMetaDirectories(tmpMetaDir, existing7z, pathToVersionMapping, - createComponentMetadata, createUnifiedMetadata); - - QDirIterator it(repositoryDir, QStringList(QLatin1String("Updates*.xml")) - << QLatin1String("*_meta.7z"), QDir::Files | QDir::CaseSensitive); - while (it.hasNext()) { - it.next(); - QFile::remove(it.fileInfo().absoluteFilePath()); - } - QInstaller::moveDirectoryContents(tmpMetaDir, repositoryDir); + QInstallerTools::createRepository(repoInfo, &packages, tmpMetaDir, + createComponentMetadata, createUnifiedMetadata, archiveSuffix, compression); + exitCode = EXIT_SUCCESS; - } catch (const Lib7z::SevenZipException &e) { - std::cerr << "Caught 7zip exception: " << e.message() << std::endl; } catch (const QInstaller::Error &e) { std::cerr << "Caught exception: " << e.message() << std::endl; } catch (...) { diff --git a/tools/repogen/repogen.pro b/tools/repogen/repogen.pro index 0380bb78b..2740167fc 100644 --- a/tools/repogen/repogen.pro +++ b/tools/repogen/repogen.pro @@ -5,11 +5,16 @@ INCLUDEPATH += . .. include(../../installerfw.pri) QT -= gui -QT += qml xml +QT += qml xml concurrent + +CONFIG -= import_plugins CONFIG += console DESTDIR = $$IFW_APP_PATH +!macos:QTPLUGIN += qopensslbackend +macos:QTPLUGIN += qsecuretransportbackend + SOURCES += repogen.cpp macx:include(../../no_app_bundle.pri) |