diff options
Diffstat (limited to 'tools/repogen/repogen.cpp')
-rw-r--r-- | tools/repogen/repogen.cpp | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/tools/repogen/repogen.cpp b/tools/repogen/repogen.cpp index b630f8cd3..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,13 +34,15 @@ #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> @@ -50,6 +52,8 @@ 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; @@ -71,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; @@ -105,6 +114,8 @@ int main(int argc, char** argv) 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) { @@ -149,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()) { @@ -175,7 +185,7 @@ 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")); } @@ -197,6 +207,30 @@ int main(int argc, char** argv) 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; @@ -218,17 +252,6 @@ int main(int argc, char** argv) if (remove) QInstaller::removeDirectory(repoInfo.repositoryDir); - if (updateExistingRepositoryWithNewComponents) { - QStringList meta7z = QDir(repoInfo.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(',')))); - } - } - if (!update && QFile::exists(repoInfo.repositoryDir) && !QDir(repoInfo.repositoryDir).entryList( QDir::AllEntries | QDir::NoDotAndDotDot).isEmpty()) { @@ -248,11 +271,9 @@ int main(int argc, char** argv) tmp.setAutoRemove(false); tmpMetaDir = tmp.path(); QInstallerTools::createRepository(repoInfo, &packages, tmpMetaDir, - createComponentMetadata, createUnifiedMetadata); + 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 (...) { |