// two transactions with two transaction items -> $reason
void
TransactionItemReasonTest::test_TwoTransactions_TwoTransactionItems()
{
    Swdb swdb(conn);

    {
        swdb.initTransaction();

        auto rpm_bash = std::make_shared< RPMItem >(conn);
        rpm_bash->setName("bash");
        rpm_bash->setEpoch(0);
        rpm_bash->setVersion("4.4.12");
        rpm_bash->setRelease("5.fc26");
        rpm_bash->setArch("x86_64");
        std::string repoid = "base";
        TransactionItemAction action = TransactionItemAction::INSTALL;
        TransactionItemReason reason = TransactionItemReason::GROUP;
        swdb.addItem(rpm_bash, repoid, action, reason);

        swdb.beginTransaction(1, "", "", 0);
        swdb.endTransaction(2, "", true);
    }

    {
        swdb.initTransaction();

        auto rpm_bash = std::make_shared< RPMItem >(conn);
        rpm_bash->setName("bash");
        rpm_bash->setEpoch(0);
        rpm_bash->setVersion("4.4.12");
        rpm_bash->setRelease("5.fc26");
        rpm_bash->setArch("i686");
        std::string repoid = "base";
        TransactionItemAction action = TransactionItemAction::INSTALL;
        TransactionItemReason reason = TransactionItemReason::USER;
        swdb.addItem(rpm_bash, repoid, action, reason);

        swdb.beginTransaction(1, "", "", 0);
        swdb.endTransaction(2, "", true);
    }

    // package exists -> $reason
    CPPUNIT_ASSERT_EQUAL(static_cast< TransactionItemReason >(
                             swdb.resolveRPMTransactionItemReason("bash", "x86_64", -1)),
                         TransactionItemReason::GROUP);

    // package exists -> $reason
    CPPUNIT_ASSERT_EQUAL(static_cast< TransactionItemReason >(
                             swdb.resolveRPMTransactionItemReason("bash", "i686", -1)),
                         TransactionItemReason::USER);

    // 2 packages exists, arch not specified -> return best $reason
    CPPUNIT_ASSERT_EQUAL(
        static_cast< TransactionItemReason >(swdb.resolveRPMTransactionItemReason("bash", "", -1)),
        TransactionItemReason::USER);
}
Example #2
0
static MergedTransactionPtr
prepareMergedTransaction(SQLite3Ptr conn,
                         TransactionItemAction actionFirst,
                         TransactionItemAction actionSecond,
                         const std::string &versionFirst,
                         const std::string &versionSecond,
                         TransactionItemAction oldFirstAction = TransactionItemAction::INSTALL,
                         const std::string &oldFirstVersion = {}

)
{
    auto firstRPM = std::make_shared< RPMItem >(conn);
    firstRPM->setName("foo");
    firstRPM->setEpoch(0);
    firstRPM->setVersion(versionFirst);
    firstRPM->setRelease("2.fc26");
    firstRPM->setArch("x86_64");
    firstRPM->save();

    auto secondRPM = std::make_shared< RPMItem >(conn);
    secondRPM->setName("foo");
    secondRPM->setEpoch(0);
    secondRPM->setVersion(versionSecond);
    secondRPM->setRelease("2.fc26");
    secondRPM->setArch("x86_64");
    secondRPM->save();

    auto first = initTransFirst(conn);
    if (oldFirstAction != TransactionItemAction::INSTALL) {
        auto oldFirst = std::make_shared< RPMItem >(conn);
        oldFirst->setName("foo");
        oldFirst->setEpoch(0);
        oldFirst->setVersion(oldFirstVersion);
        oldFirst->setRelease("2.fc26");
        oldFirst->setArch("x86_64");
        oldFirst->save();
        first->addItem(oldFirst, "base", oldFirstAction, TransactionItemReason::USER);
    }

    first->addItem(firstRPM, "base", actionFirst, TransactionItemReason::USER);
    first->begin();
    first->finish(true);

    auto second = initTransSecond(conn);
    second->addItem(secondRPM, "base", actionSecond, TransactionItemReason::USER);
    second->begin();
    second->finish(true);

    auto merged = std::make_shared< MergedTransaction >(first);
    merged->merge(second);
    return merged;
}
Example #3
0
static RPMItemPtr
nevraToRPMItem(SQLite3Ptr conn, std::string nevra)
{
    auto nevraObject = new Nevra;
    if (hy_nevra_possibility(nevra.c_str(), HY_FORM_NEVRA, nevraObject)) {
        return nullptr;
    }
    if (nevraObject->getEpoch() < 0) {
        nevraObject->setEpoch(0);
    }

    auto rpm = std::make_shared< RPMItem >(conn);
    rpm->setName(nevraObject->getName());
    rpm->setEpoch(nevraObject->getEpoch());
    rpm->setVersion(nevraObject->getVersion());
    rpm->setRelease(nevraObject->getRelease());
    rpm->setArch(nevraObject->getArch());
    return rpm;
}
Example #4
0
static SwdbPrivate::TransactionPtr
initTransSecond(SQLite3Ptr conn)
{
    // create the second transaction
    auto second = std::make_shared< SwdbPrivate::Transaction >(conn);
    second->setDtBegin(3);
    second->setDtEnd(4);
    second->setRpmdbVersionBegin("begin 2");
    second->setRpmdbVersionEnd("end 2");
    second->setUserId(1001);
    second->setCmdline("dnf install bar");

    auto rpmRpm = std::make_shared< RPMItem >(conn);
    rpmRpm->setName("rpm");
    rpmRpm->setEpoch(0);
    rpmRpm->setVersion("4.14.0");
    rpmRpm->setRelease("2.fc26");
    rpmRpm->setArch("x86_64");
    rpmRpm->save();

    second->addSoftwarePerformedWith(rpmRpm);
    return second;
}
Example #5
0
static SwdbPrivate::TransactionPtr
initTransFirst(SQLite3Ptr conn)
{
    // create the first transaction
    auto first = std::make_shared< SwdbPrivate::Transaction >(conn);
    first->setDtBegin(1);
    first->setDtEnd(2);
    first->setRpmdbVersionBegin("begin 1");
    first->setRpmdbVersionEnd("end 1");
    first->setUserId(1000);
    first->setCmdline("dnf install foo");

    auto dnfRpm = std::make_shared< RPMItem >(conn);
    dnfRpm->setName("dnf");
    dnfRpm->setEpoch(0);
    dnfRpm->setVersion("3.0.0");
    dnfRpm->setRelease("2.fc26");
    dnfRpm->setArch("x86_64");
    dnfRpm->save();

    first->addSoftwarePerformedWith(dnfRpm);
    return first;
}
// one FAILED transaction with one transaction item -> $reason
void
TransactionItemReasonTest::test_OneFailedTransaction_OneTransactionItem()
{
    Swdb swdb(conn);

    swdb.initTransaction();

    auto rpm_bash = std::make_shared< RPMItem >(conn);
    rpm_bash->setName("bash");
    rpm_bash->setEpoch(0);
    rpm_bash->setVersion("4.4.12");
    rpm_bash->setRelease("5.fc26");
    rpm_bash->setArch("x86_64");
    std::string repoid = "base";
    TransactionItemAction action = TransactionItemAction::INSTALL;
    TransactionItemReason reason = TransactionItemReason::GROUP;
    swdb.addItem(rpm_bash, repoid, action, reason);

    swdb.beginTransaction(1, "", "", 0);
    swdb.endTransaction(2, "", false);

    // failed transaction -> UNKNOWN
    CPPUNIT_ASSERT_EQUAL(static_cast< TransactionItemReason >(
                             swdb.resolveRPMTransactionItemReason("bash", "x86_64", -1)),
                         TransactionItemReason::UNKNOWN);

    // failed transaction -> UNKNOWN
    CPPUNIT_ASSERT_EQUAL(static_cast< TransactionItemReason >(
                             swdb.resolveRPMTransactionItemReason("bash", "i686", -1)),
                         TransactionItemReason::UNKNOWN);

    // failed transaction -> UNKNOWN
    CPPUNIT_ASSERT_EQUAL(
        static_cast< TransactionItemReason >(swdb.resolveRPMTransactionItemReason("bash", "", -1)),
        TransactionItemReason::UNKNOWN);
}
Example #7
0
void IosProbe::setupDefaultToolchains(const QString &devPath, const QString &xcodeName)
{
    if (debugProbe)
        qDebug() << QString::fromLatin1("Setting up platform '%1'.").arg(xcodeName);
    QString indent = QLatin1String("  ");

    // detect clang (default toolchain)
    QFileInfo clangFileInfo(devPath
                            + QLatin1String("/Toolchains/XcodeDefault.xctoolchain/usr/bin")
                            + QLatin1String("/clang++"));
    bool hasClang = clangFileInfo.exists();
    if (!hasClang)
        qDebug() << indent << QString::fromLatin1("Default toolchain %1 not found.")
                     .arg(clangFileInfo.canonicalFilePath());
    // Platforms
    QDir platformsDir(devPath + QLatin1String("/Platforms"));
    QFileInfoList platforms = platformsDir.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
    foreach (const QFileInfo &fInfo, platforms) {
        if (fInfo.isDir() && fInfo.suffix() == QLatin1String("platform")) {
            if (debugProbe)
                qDebug() << indent << QString::fromLatin1("Setting up %1").arg(fInfo.fileName());
            QSettingsPtr infoSettings(new QSettings(
                                   fInfo.absoluteFilePath() + QLatin1String("/Info.plist"),
                                   QSettings::NativeFormat));
            if (!infoSettings->contains(QLatin1String("Name"))) {
                qDebug() << indent << QString::fromLatin1("Missing platform name in Info.plist of %1")
                             .arg(fInfo.absoluteFilePath());
                continue;
            }
            QString name = infoSettings->value(QLatin1String("Name")).toString();
            if (name != QLatin1String("macosx") && name != QLatin1String("iphoneos")
                    && name != QLatin1String("iphonesimulator"))
            {
                qDebug() << indent << QString::fromLatin1("Skipping unknown platform %1").arg(name);
                continue;
            }

            // prepare default platform properties
            QVariantMap defaultProp = infoSettings->value(QLatin1String("DefaultProperties"))
                    .toMap();
            QVariantMap overrideProp = infoSettings->value(QLatin1String("OverrideProperties"))
                    .toMap();
            QMapIterator<QString, QVariant> i(overrideProp);
            while (i.hasNext()) {
                i.next();
                // use unite? might lead to double insertions...
                defaultProp[i.key()] = i.value();
            }

            QString clangFullName = name + QLatin1String("-clang") + xcodeName;
            QString clang11FullName = name + QLatin1String("-clang11") + xcodeName;
            // detect gcc
            QFileInfo gccFileInfo(fInfo.absoluteFilePath() + QLatin1String("/Developer/usr/bin/g++"));
            QString gccFullName = name + QLatin1String("-gcc") + xcodeName;
            if (!gccFileInfo.exists())
                gccFileInfo = QFileInfo(devPath + QLatin1String("/usr/bin/g++"));
            bool hasGcc = gccFileInfo.exists();

            QStringList extraFlags;
            if (defaultProp.contains(QLatin1String("ARCHS"))) {
                QString arch = defaultProp.value(QLatin1String("ARCHS")).toString();
                if (arch == QLatin1String("$(NATIVE_ARCH_32_BIT)"))
                    extraFlags << QLatin1String("-arch") << QLatin1String("i386");
            }
            if (defaultProp.contains(QLatin1String("NATIVE_ARCH"))) {
                QString arch = defaultProp.value(QLatin1String("NATIVE_ARCH")).toString();
                if (!arch.startsWith(QLatin1String("arm")))
                    qDebug() << indent << QString::fromLatin1("Expected arm architecture, not %1").arg(arch);
                extraFlags << QLatin1String("-arch") << arch;
            }
            if (hasClang) {
                Platform clangProfile;
                clangProfile.developerPath = Utils::FileName::fromString(devPath);
                clangProfile.platformKind = 0;
                clangProfile.name = clangFullName;
                clangProfile.platformPath = Utils::FileName(fInfo);
                clangProfile.platformInfo = infoSettings;
                clangProfile.compilerPath = Utils::FileName(clangFileInfo);
                setArch(&clangProfile, clangFileInfo.canonicalFilePath(), extraFlags);
                if (debugProbe)
                    qDebug() << indent << QString::fromLatin1("* adding profile %1").arg(clangProfile.name);
                m_platforms[clangProfile.name] = clangProfile;
                clangProfile.platformKind |= Platform::Cxx11Support;
                clangProfile.backendFlags.append(QLatin1String("-std=c++11"));
                clangProfile.backendFlags.append(QLatin1String("-stdlib=libc++"));
                clangProfile.name = clang11FullName;
                m_platforms[clangProfile.name] = clangProfile;
            }
            if (hasGcc) {
                Platform gccProfile;
                gccProfile.developerPath = Utils::FileName::fromString(devPath);
                gccProfile.name = gccFullName;
                gccProfile.platformKind = 0;
                // use the arm-apple-darwin10-llvm-* variant and avoid the extraFlags if available???
                gccProfile.platformPath = Utils::FileName(fInfo);
                gccProfile.platformInfo = infoSettings;
                gccProfile.compilerPath = Utils::FileName(gccFileInfo);
                setArch(&gccProfile, gccFileInfo.canonicalFilePath(), extraFlags);
                if (debugProbe)
                    qDebug() << indent << QString::fromLatin1("* adding profile %1").arg(gccProfile.name);
                m_platforms[gccProfile.name] = gccProfile;
            }

            // set SDKs/sysroot
            QString sysRoot;
            QSettingsPtr sdkSettings;
            {
                QString sdkName;
                if (defaultProp.contains(QLatin1String("SDKROOT")))
                    sdkName = defaultProp.value(QLatin1String("SDKROOT")).toString();
                QString sdkPath;
                QDir sdks(fInfo.absoluteFilePath() + QLatin1String("/Developer/SDKs"));
                QString maxVersion;
                foreach (const QFileInfo &sdkDirInfo, sdks.entryInfoList(QDir::Dirs
                                                                         | QDir::NoDotAndDotDot)) {
                    indent = QLatin1String("    ");
                    QSettingsPtr sdkInfo(new QSettings(sdkDirInfo.absoluteFilePath()
                                                       + QLatin1String("/SDKSettings.plist"),
                                                       QSettings::NativeFormat));
                    QString versionStr = sdkInfo->value(QLatin1String("Version")).toString();
                    QVariant currentSdkName = sdkInfo->value(QLatin1String("CanonicalName"));
                    bool isBaseSdk = sdkInfo->value((QLatin1String("isBaseSDK"))).toString()
                            .toLower() != QLatin1String("no");
                    if (!isBaseSdk) {
                        if (debugProbe)
                            qDebug() << indent << QString::fromLatin1("Skipping non base Sdk %1")
                                        .arg(currentSdkName.toString());
                        continue;
                    }
                    QString safeName = currentSdkName.toString().replace(QLatin1Char('-'), QLatin1Char('_'))
                            .replace(QRegExp(QLatin1String("[^-a-zA-Z0-9]")), QLatin1String("-"));
                    if (sdkName.isEmpty()) {
                        if (compareVersions(maxVersion, versionStr) > 0) {
                            maxVersion = versionStr;
                            sdkPath = sdkDirInfo.canonicalFilePath();
                            sdkSettings = sdkInfo;
                        }
                    } else if (currentSdkName == sdkName) {
                        sdkPath = sdkDirInfo.canonicalFilePath();
                        sdkSettings = sdkInfo;
                    }
                    if (hasClang){
                        Platform pSdk;
                        pSdk = m_platforms[clangFullName];
                        pSdk.name = safeName + QLatin1String("-clang") + xcodeName;
                        pSdk.sdkPath = Utils::FileName(sdkDirInfo);
                        pSdk.sdkSettings = sdkInfo;
                        if (debugProbe)
                            qDebug() << indent << QString::fromLatin1("* adding profile %1").arg(pSdk.name);
                        m_platforms[pSdk.name] = pSdk;
                        pSdk.backendFlags.append(QLatin1String("-std=c++11"));
                        pSdk.backendFlags.append(QLatin1String("-stdlib=libc++"));
                        pSdk.name = safeName + QLatin1String("-clang11") + xcodeName;
                        m_platforms[pSdk.name] = pSdk;
                    }
                    if (hasGcc) {
                        Platform pSdk;
                        pSdk = m_platforms[gccFullName];
                        pSdk.name = safeName + QLatin1String("-gcc") + xcodeName;
                        pSdk.sdkPath = Utils::FileName(sdkDirInfo);
                        pSdk.sdkSettings = sdkInfo;
                        if (debugProbe)
                            qDebug() << indent << QString::fromLatin1("* adding profile %1").arg(pSdk.name);
                        m_platforms[pSdk.name] = pSdk;
                    }
                }
                if (!sdkPath.isEmpty())
                    sysRoot = sdkPath;
                else if (!sdkName.isEmpty())
                    qDebug() << indent << QString::fromLatin1("Failed to find sysroot %1").arg(sdkName);
            }
            //m_platforms.remove(clangFullName);
            if (hasClang && !sysRoot.isEmpty()) {
                m_platforms[clangFullName].platformKind |= Platform::BasePlatform;
                m_platforms[clangFullName].sdkPath = Utils::FileName::fromString(sysRoot);
                m_platforms[clangFullName].sdkSettings = sdkSettings;
                m_platforms[clang11FullName].platformKind |= Platform::BasePlatform;
                m_platforms[clang11FullName].sdkPath = Utils::FileName::fromString(sysRoot);
                m_platforms[clang11FullName].sdkSettings = sdkSettings;
            }
            //m_platforms.remove(gccFullName);
            if (hasGcc && !sysRoot.isEmpty()) {
                m_platforms[gccFullName].platformKind |= Platform::BasePlatform;
                m_platforms[gccFullName].sdkPath = Utils::FileName::fromString(sysRoot);
                m_platforms[gccFullName].sdkSettings = sdkSettings;
            }
        }
        indent = QLatin1String("  ");
    }
}
Example #8
0
void
WorkflowTest::testDefaultWorkflow()
{
    // TODO: init/begin/end trans

    // STEP 1: create transaction object
    SwdbPrivate::Transaction trans(conn);
    CPPUNIT_ASSERT(trans.getDone() == false);

    // STEP 2: set vars
    trans.setReleasever("26");

    // populate goal
    // resolve dependencies
    // prepare RPM transaction

    // STEP 3: associate RPMs to the transaction
    // bash-4.4.12-5.fc26.x86_64
    auto rpm_bash = std::make_shared< RPMItem >(conn);
    rpm_bash->setName("bash");
    rpm_bash->setEpoch(0);
    rpm_bash->setVersion("4.4.12");
    rpm_bash->setRelease("5.fc26");
    rpm_bash->setArch("x86_64");
    std::string repoid = "base";
    TransactionItemAction action = TransactionItemAction::INSTALL;
    TransactionItemReason reason = TransactionItemReason::GROUP;
    trans.addItem(rpm_bash, repoid, action, reason);

    // systemd-233-6.fc26
    auto rpm_systemd = std::make_shared< RPMItem >(conn);
    rpm_systemd->setName("systemd");
    rpm_systemd->setEpoch(0);
    rpm_systemd->setVersion("233");
    rpm_systemd->setRelease("6.fc26");
    rpm_systemd->setArch("x86_64");
    repoid = "base";
    action = TransactionItemAction::OBSOLETE;
    reason = TransactionItemReason::USER;
    auto ti_rpm_systemd = trans.addItem(rpm_systemd, repoid, action, reason);

    // sysvinit-2.88-14.dsf.fc20
    auto rpm_sysvinit = std::make_shared< RPMItem >(conn);
    rpm_sysvinit->setName("sysvinit");
    rpm_sysvinit->setEpoch(0);
    rpm_sysvinit->setVersion("2.88");
    rpm_sysvinit->setRelease("14.dsf.fc20");
    rpm_sysvinit->setArch("x86_64");
    repoid = "f20";
    action = TransactionItemAction::OBSOLETED;
    reason = TransactionItemReason::USER;
    auto ti_rpm_sysvinit = trans.addItem(rpm_sysvinit, repoid, action, reason);
    ti_rpm_sysvinit->addReplacedBy(ti_rpm_systemd);

    auto comps_group_core = std::make_shared< CompsGroupItem >(conn);
    comps_group_core->setGroupId("core");
    comps_group_core->setName("Core");
    comps_group_core->setTranslatedName("Úplný základ");
    comps_group_core->addPackage("bash", true, CompsPackageType::MANDATORY);
    repoid = "";
    action = TransactionItemAction::INSTALL;
    reason = TransactionItemReason::USER;
    trans.addItem(comps_group_core, repoid, action, reason);

    auto comps_environment_minimal = std::make_shared< CompsEnvironmentItem >(conn);
    comps_environment_minimal->setEnvironmentId("minimal");
    comps_environment_minimal->setName("Minimal");
    comps_environment_minimal->setTranslatedName("mmm");
    comps_environment_minimal->addGroup("core", true, CompsPackageType::MANDATORY);
    repoid = "";
    action = TransactionItemAction::INSTALL;
    reason = TransactionItemReason::USER;
    trans.addItem(comps_environment_minimal, repoid, action, reason);

    // STEP 4: save transaction and all associated items
    trans.begin();

    // STEP 5: run RPM transaction; callback: mark completed items
    for (auto i : trans.getItems()) {
        i->setDone(true);
        i->save();
    }

    // STEP 6
    // mark completed transaction
    trans.finish(true);
    CPPUNIT_ASSERT(trans.getDone() == true);

    // VERIFY
    // verify that data is available via public API
    auto trans2 = libdnf::Transaction(conn, trans.getId());
    CPPUNIT_ASSERT(trans2.getDone() == true);

    CPPUNIT_ASSERT(trans2.getItems().size() == 5);

    for (auto i : trans2.getItems()) {
        if (i->getId() == 1) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::INSTALL);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::GROUP);
            CPPUNIT_ASSERT(i->getRepoid() == "base");
        } else if (i->getId() == 2) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::OBSOLETE);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::USER);
            CPPUNIT_ASSERT(i->getRepoid() == "base");
        } else if (i->getId() == 3) {
            CPPUNIT_ASSERT(i->getAction() == TransactionItemAction::OBSOLETED);
            CPPUNIT_ASSERT(i->getReason() == TransactionItemReason::USER);
            CPPUNIT_ASSERT(i->getRepoid() == "f20");
        }

        // CPPUNIT_ASSERT(i->getItem()->getItemType() == "rpm");
        CPPUNIT_ASSERT(i->getDone() == true);
        // std::cout << "TransactionItem: " << i->getItem()->toStr() << std::endl;
        if (i->getItem()->getItemType() == ItemType::GROUP) {
            auto grp = std::dynamic_pointer_cast< CompsGroupItem >(i->getItem());
            CPPUNIT_ASSERT(grp->getPackages().size() == 1);
            for (auto i : grp->getPackages()) {
                // std::cout << "  CompsGroupPackage: " << i->getName() << std::endl;
            }
        }
        if (i->getItem()->getItemType() == ItemType::ENVIRONMENT) {
            auto env = std::dynamic_pointer_cast< CompsEnvironmentItem >(i->getItem());
            CPPUNIT_ASSERT(env->getGroups().size() == 1);
            for (auto i : env->getGroups()) {
                // std::cout << "  CompsEnvironmentGroup: @" << i->getGroupId() << std::endl;
            }
        }
    }
}