From 2ad4a39aea4a916e0a14892a307c8fed54833dfa Mon Sep 17 00:00:00 2001 From: Martchus Date: Thu, 26 Aug 2021 22:56:48 +0200 Subject: [PATCH] Handle case when a split package overrides the archs from the base --- cli/main.cpp | 2 + libpkg/data/database.cpp | 10 ++-- libpkg/data/package.cpp | 14 +++++ libpkg/data/package.h | 6 +- libpkg/parser/package.cpp | 7 ++- libpkg/testfiles/jdk/SRCINFO | 71 ++++++++++++++++++++++++ libpkg/tests/parser.cpp | 21 +++++++ librepomgr/CMakeLists.txt | 2 +- librepomgr/buildactions/conductbuild.cpp | 4 +- 9 files changed, 124 insertions(+), 13 deletions(-) create mode 100644 libpkg/testfiles/jdk/SRCINFO diff --git a/cli/main.cpp b/cli/main.cpp index b7318b9..65b3a70 100644 --- a/cli/main.cpp +++ b/cli/main.cpp @@ -133,6 +133,8 @@ static void printPackageDetails(const LibRepoMgr::WebClient::Response::body_type t.format().hide_border(); if (pkg->packageInfo) { t.add_row({ "Arch", pkg->packageInfo->arch }); + } else if (!pkg->archs.empty()) { + t.add_row({ "Archs", formatList(pkg->archs) }); } else if (pkg->sourceInfo) { t.add_row({ "Archs", formatList(pkg->sourceInfo->archs) }); } diff --git a/libpkg/data/database.cpp b/libpkg/data/database.cpp index 7fb99c5..712e92a 100644 --- a/libpkg/data/database.cpp +++ b/libpkg/data/database.cpp @@ -439,7 +439,9 @@ LIBPKG_EXPORT void push( push(pkgInfo->arch, "arch", obj, allocator); push(pkgInfo->buildDate, "buildDate", obj, allocator); } - if (const auto &srcInfo = pkg->sourceInfo) { + if (!pkg->archs.empty()) { + push(pkg->archs, "archs", obj, allocator); + } else if (const auto &srcInfo = pkg->sourceInfo) { push(srcInfo->archs, "archs", obj, allocator); } if (const auto *const dbInfo = std::get_if(&reflectable.db)) { @@ -484,11 +486,7 @@ LIBPKG_EXPORT void pull(LibPkg::PackageSearchResult } ReflectiveRapidJSON::JsonReflector::pull(pkgInfo->arch, "arch", obj, errors); ReflectiveRapidJSON::JsonReflector::pull(pkgInfo->buildDate, "buildDate", obj, errors); - auto &srcInfo = pkg->sourceInfo; - if (!srcInfo) { - srcInfo = make_shared(); - } - ReflectiveRapidJSON::JsonReflector::pull(srcInfo->archs, "archs", obj, errors); + ReflectiveRapidJSON::JsonReflector::pull(pkg->archs, "archs", obj, errors); auto &dbInfo = reflectable.db.emplace(); ReflectiveRapidJSON::JsonReflector::pull(dbInfo.name, "db", obj, errors); ReflectiveRapidJSON::JsonReflector::pull(dbInfo.arch, "dbArch", obj, errors); diff --git a/libpkg/data/package.cpp b/libpkg/data/package.cpp index 8ee0dae..e18b55a 100644 --- a/libpkg/data/package.cpp +++ b/libpkg/data/package.cpp @@ -404,6 +404,20 @@ bool Package::addDepsAndProvidesFromOtherPackage(const Package &otherPackage, bo return true; } +bool Package::isArchAny() const +{ + const auto &a = archs.empty() && sourceInfo ? sourceInfo->archs : archs; + if (a.empty()) { + return false; + } + for (const auto &arch : a) { + if (arch != "any") { + return false; + } + } + return true; +} + DependencySetBase::iterator DependencySet::find(const Dependency &dependency) { for (auto range = equal_range(dependency.name); range.first != range.second; ++range.first) { diff --git a/libpkg/data/package.h b/libpkg/data/package.h index ad5e4df..ebae423 100644 --- a/libpkg/data/package.h +++ b/libpkg/data/package.h @@ -162,7 +162,7 @@ struct SourceFile : public ReflectiveRapidJSON::JsonSerializable, pu struct LIBPKG_EXPORT SourceInfo : public ReflectiveRapidJSON::JsonSerializable, public ReflectiveRapidJSON::BinarySerializable { std::string name; - std::vector archs; + std::vector archs; // archs specified in base package std::vector makeDependencies; std::vector checkDependencies; std::string maintainer; @@ -186,7 +186,7 @@ struct LIBPKG_EXPORT PackageInfo : public ReflectiveRapidJSON::JsonSerializable< std::string md5; std::string sha256; std::string pgpSignature; - std::string arch; + std::string arch; // arch of concrete binary package std::uint32_t size = 0; }; @@ -302,6 +302,7 @@ struct LIBPKG_EXPORT Package : public ReflectiveRapidJSON::JsonSerializable &&dllsReferencedByImportLibs); bool addDepsAndProvidesFromOtherPackage(const Package &otherPackage, bool force = false); + bool isArchAny() const; static bool isPkgInfoFileOrBinary(const char *filePath, const char *fileName, mode_t mode); static bool isLicense(const char *filePath, const char *fileName, mode_t mode); @@ -319,6 +320,7 @@ struct LIBPKG_EXPORT Package : public ReflectiveRapidJSON::JsonSerializable archs; // set if a split package overrides the base archs; if empty, archs from sourceInfo apply std::string description; std::string upstreamUrl; std::vector licenses; diff --git a/libpkg/parser/package.cpp b/libpkg/parser/package.cpp index 40b2b33..5aba2f0 100644 --- a/libpkg/parser/package.cpp +++ b/libpkg/parser/package.cpp @@ -230,10 +230,15 @@ void addPackageInfo( else_if_field("arch") { if (isPackageInfo) { + // add as binary arch when parsing PKGINFO ensure_pkg_info; package.packageInfo->arch = valueString; - } else { + } else if (package.sourceInfo.use_count() <= 1) { + // add to sourceInfo when still parsing base info package.sourceInfo->archs.emplace_back(value, valueSize); + } else { + // add to package itself when a split package overrides the archs from the base + package.archs.emplace_back(value, valueSize); } } else_if_field("license") diff --git a/libpkg/testfiles/jdk/SRCINFO b/libpkg/testfiles/jdk/SRCINFO new file mode 100644 index 0000000..1fd7962 --- /dev/null +++ b/libpkg/testfiles/jdk/SRCINFO @@ -0,0 +1,71 @@ +pkgbase = jdk + pkgdesc = Oracle Java + pkgver = 16.0.2 + pkgrel = 2 + url = https://www.oracle.com/java/ + arch = x86_64 + license = custom + makedepends = python-html2text + noextract = jdk-16.0.2_doc-all.zip + source = https://download.oracle.com/otn-pub/java/jdk/16.0.2+7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_linux-x64_bin.tar.gz + source = https://download.oracle.com/otn-pub/java/jdk/16.0.2+7/d4a915d82b4c4fbb9bde534da945d746/jdk-16.0.2_doc-all.zip + source = java-16-jdk-license.html::https://download.oracle.com/otndocs/jcp/java_se-16-final-spec/license.html + source = java.desktop + source = jconsole.desktop + source = jshell.desktop + source = java_16.png + source = java_48.png + source = LICENSE + sha256sums = 630e3e56c58f45db3788343ce842756d5a5a401a63884242cc6a141071285a62 + sha256sums = 7cd96f9aa11d9e1a1adbee3e941a78e899bc9079370e4c12c106761d3df80f82 + sha256sums = 2f14da815e019b3f5558e5176c969227a2530bac1cfdfd42dbd6ccc2ee618346 + sha256sums = 9fc4cd168fd3e0d654093c1b2dd070f627ffae9b7f5c2c0741bac0b5c1ed0635 + sha256sums = 12b6e632e38e2c2ef54d6b03976290ca649380a89f78b5dae8827423eae52a1b + sha256sums = b2fd5a8f273a103569bf03af6f4ff4d3a5448472abc79b8649cecd0ee9313fc7 + sha256sums = d27fec1d74f7a3081c3d175ed184d15383666dc7f02cc0f7126f11549879c6ed + sha256sums = 7cf8ca096e6d6e425b3434446b0835537d0fc7fe64b3ccba7a55f7bd86c7e176 + sha256sums = ef331c118f613261f06771161e9aebf8d26ab6cc131edd51358b01cc20fc759d + +pkgname = jre + pkgdesc = Oracle Java Runtime Environment + install = jre.install + depends = java-runtime-common + depends = ca-certificates-utils + depends = freetype2 + depends = libxtst + depends = libxrender + depends = libnet + optdepends = alsa-lib: for basic sound support + provides = java-runtime=16 + provides = java-runtime-headless=16 + provides = java-runtime-jre=16 + provides = java-runtime-headless-jre=16 + backup = etc/java-jdk/management/jmxremote.access + backup = etc/java-jdk/management/jmxremote.password.template + backup = etc/java-jdk/management/management.properties + backup = etc/java-jdk/security/policy/limited/default_US_export.policy + backup = etc/java-jdk/security/policy/limited/default_local.policy + backup = etc/java-jdk/security/policy/limited/exempt_local.policy + backup = etc/java-jdk/security/policy/unlimited/default_US_export.policy + backup = etc/java-jdk/security/policy/unlimited/default_local.policy + backup = etc/java-jdk/security/policy/README.txt + backup = etc/java-jdk/security/java.policy + backup = etc/java-jdk/security/java.security + backup = etc/java-jdk/logging.properties + backup = etc/java-jdk/net.properties + backup = etc/java-jdk/sound.properties + +pkgname = jdk + pkgdesc = Oracle Java Development Kit + install = jdk.install + depends = java-environment-common + depends = jre>=16 + depends = jre<17 + depends = zlib + depends = hicolor-icon-theme + provides = java-environment=16 + provides = java-environment-jdk=16 + +pkgname = jdk-doc + pkgdesc = Oracle Java documentation + arch = any diff --git a/libpkg/tests/parser.cpp b/libpkg/tests/parser.cpp index 0c67400..88b8135 100644 --- a/libpkg/tests/parser.cpp +++ b/libpkg/tests/parser.cpp @@ -32,6 +32,7 @@ class ParserTests : public TestFixture { CPPUNIT_TEST(testParsingConfig); CPPUNIT_TEST(testParsingPlainSrcInfo); CPPUNIT_TEST(testParsingSplitPackageSrcInfo); + CPPUNIT_TEST(testParsingSplitPackageSrcInfoWithDifferentArchs); CPPUNIT_TEST(testParsingPkgInfo); CPPUNIT_TEST(testParsingPkgName); CPPUNIT_TEST(testExtractingPkgFile); @@ -51,6 +52,7 @@ public: void testParsingConfig(); void testParsingPlainSrcInfo(); void testParsingSplitPackageSrcInfo(); + void testParsingSplitPackageSrcInfoWithDifferentArchs(); void testParsingPkgInfo(); void testParsingPkgName(); void testExtractingPkgFile(); @@ -228,6 +230,25 @@ void ParserTests::testParsingSplitPackageSrcInfo() CPPUNIT_ASSERT_EQUAL_MESSAGE("arch (2)"s, archs, pkg2.sourceInfo->archs); } +void ParserTests::testParsingSplitPackageSrcInfoWithDifferentArchs() +{ + const auto srcInfo = readFile(testFilePath("jdk/SRCINFO"s)); + const auto packages = Package::fromInfo(srcInfo, false); + CPPUNIT_ASSERT_EQUAL_MESSAGE("3 (split) packages present"s, 3ul, packages.size()); + + const auto &jre = packages[0], &jdk = packages[1], &doc = packages[2]; + CPPUNIT_ASSERT_MESSAGE("source info present", jdk->sourceInfo); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jre has same source info as base", jdk->sourceInfo, jre->sourceInfo); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jdk-doc has same source info as base", jdk->sourceInfo, doc->sourceInfo); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jre name", "jre"s, jre->name); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jdk name", "jdk"s, jdk->name); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jdk-doc name", "jdk-doc"s, doc->name); + CPPUNIT_ASSERT_EQUAL_MESSAGE("base archs", std::vector{ "x86_64"s }, jre->sourceInfo->archs); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jre archs (empty, base applies)", std::vector{}, jre->archs); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jdk archs (empty, base applies)", std::vector{}, jdk->archs); + CPPUNIT_ASSERT_EQUAL_MESSAGE("jdk-doc archs (overidden)", std::vector{ "any"s }, doc->archs); +} + void ParserTests::testParsingPkgInfo() { const auto pkgInfo = readFile(testFilePath("mingw-w64-harfbuzz/PKGINFO")); diff --git a/librepomgr/CMakeLists.txt b/librepomgr/CMakeLists.txt index bb5f86d..fc4291e 100644 --- a/librepomgr/CMakeLists.txt +++ b/librepomgr/CMakeLists.txt @@ -71,7 +71,7 @@ set(META_APP_DESCRIPTION "Library for managing custom Arch Linux repositories") set(META_VERSION_MAJOR 0) set(META_VERSION_MINOR 0) set(META_VERSION_PATCH 1) -set(META_VERSION_CACHE 9) +set(META_VERSION_CACHE 10) set(META_VERSION_BUILD_ACTIONS_JSON 0) set(META_VERSION_LIBRARY_DEPENDENCIES_JSON 0) set(LINK_TESTS_AGAINST_APP_TARGET ON) diff --git a/librepomgr/buildactions/conductbuild.cpp b/librepomgr/buildactions/conductbuild.cpp index 7db441a..67e53a2 100644 --- a/librepomgr/buildactions/conductbuild.cpp +++ b/librepomgr/buildactions/conductbuild.cpp @@ -970,7 +970,6 @@ void ConductBuild::addPackageToRepo( { // make arrays to store binary package names auto binaryPackages = std::vector{}; - static const auto anyArch = std::vector{ "any" }; // determine name of source package to be copied auto buildResult = BuildResult{}; @@ -983,8 +982,7 @@ void ConductBuild::addPackageToRepo( binaryPackages.reserve(buildData.packages.size()); buildResult.binaryPackageNames.reserve(buildData.packages.size()); for (const auto &package : buildData.packages) { - const auto isAny = package->sourceInfo->archs - == anyArch; // FIXME: Shouldn't there still be a package->archs if e.g. base is x86_64 but a split package any? + const auto isAny = package->isArchAny(); const auto &arch = isAny ? "any" : m_buildPreparation.targetArch; const auto &packageFileName = buildResult.binaryPackageNames.emplace_back( package->name % '-' % (packageProgress.updatedVersion.empty() ? package->version : packageProgress.updatedVersion) % '-' % arch