#include <sstream>
#include <streambuf>
+#define ZYPP_USE_RESOLVER_INTERNALS
+
#include "zypp/solver/detail/Testcase.h"
#include "zypp/base/Logger.h"
#include "zypp/base/LogControl.h"
#include "zypp/target/modalias/Modalias.h"
#include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/solver/detail/Resolver.h"
#include "zypp/solver/detail/SystemCheck.h"
/////////////////////////////////////////////////////////////////////////
return str.str();
}
-inline string helixXML( const Resolvable::constPtr &obj, Dep deptag_r )
+inline string helixXML( const PoolItem & obj, Dep deptag_r )
{
stringstream out;
- Capabilities caps( obj->dep(deptag_r) );
+ Capabilities caps( obj[deptag_r] );
if ( ! caps.empty() )
out << TAB << xml_tag_enclose(helixXML(caps), deptag_r.asString()) << endl;
return out.str();
}
-std::string helixXML( const PoolItem &item )
+std::string helixXML( const PoolItem & item )
{
- const Resolvable::constPtr resolvable = item.resolvable();
stringstream str;
- str << "<" << toLower (resolvable->kind().asString()) << ">" << endl;
- str << TAB << xml_tag_enclose (resolvable->name(), "name", true) << endl;
- str << TAB << xml_tag_enclose (item->vendor(), "vendor", true) << endl;
- str << TAB << xml_tag_enclose (item->buildtime().asSeconds(), "buildtime", true) << endl;
- if ( isKind<Package>(resolvable) ) {
+ str << "<" << item.kind() << ">" << endl;
+ str << TAB << xml_tag_enclose( item.name(), "name", true ) << endl;
+ str << TAB << xml_tag_enclose( item.vendor().asString(), "vendor", true ) << endl;
+ str << TAB << xml_tag_enclose( item.buildtime().asSeconds(), "buildtime", true ) << endl;
+ if ( isKind<Package>( item ) ) {
str << TAB << "<history>" << endl << TAB << "<update>" << endl;
- str << TAB2 << helixXML (resolvable->arch()) << endl;
- str << TAB2 << helixXML (resolvable->edition()) << endl;
+ str << TAB2 << helixXML( item.arch() ) << endl;
+ str << TAB2 << helixXML( item.edition() ) << endl;
str << TAB << "</update>" << endl << TAB << "</history>" << endl;
} else {
- str << TAB << helixXML (resolvable->arch()) << endl;
- str << TAB << helixXML (resolvable->edition()) << endl;
+ str << TAB << helixXML( item.arch() ) << endl;
+ str << TAB << helixXML( item.edition() ) << endl;
}
- str << helixXML( resolvable, Dep::PROVIDES);
- str << helixXML( resolvable, Dep::PREREQUIRES);
- str << helixXML( resolvable, Dep::CONFLICTS);
- str << helixXML( resolvable, Dep::OBSOLETES);
- str << helixXML( resolvable, Dep::REQUIRES);
- str << helixXML( resolvable, Dep::RECOMMENDS);
- str << helixXML( resolvable, Dep::ENHANCES);
- str << helixXML( resolvable, Dep::SUPPLEMENTS);
- str << helixXML( resolvable, Dep::SUGGESTS);
-
- str << "</" << toLower (resolvable->kind().asString()) << ">" << endl;
+ str << helixXML( item, Dep::PROVIDES );
+ str << helixXML( item, Dep::PREREQUIRES );
+ str << helixXML( item, Dep::CONFLICTS );
+ str << helixXML( item, Dep::OBSOLETES );
+ str << helixXML( item, Dep::REQUIRES );
+ str << helixXML( item, Dep::RECOMMENDS );
+ str << helixXML( item, Dep::ENHANCES );
+ str << helixXML( item, Dep::SUPPLEMENTS );
+ str << helixXML( item, Dep::SUGGESTS );
+
+ str << "</" << item.kind() << ">" << endl;
return str.str();
}
private:
std::string dumpFile; // Path of the generated testcase
std::ofstream *file;
- bool _inSetup;
public:
HelixControl (const std::string & controlPath,
const RepositoryTable & sourceTable,
const Arch & systemArchitecture,
- const LocaleSet &languages,
const target::Modalias::ModaliasList & modaliasList,
const std::set<std::string> & multiversionSpec,
- const std::string & systemPath);
+ const std::string & systemPath,
+ const bool forceResolve,
+ const bool onlyRequires,
+ const bool ignorealreadyrecommended);
HelixControl ();
~HelixControl ();
- void closeSetup()
- {
- if ( _inSetup )
- {
- *file << "</setup>" << endl << "<trial>" << endl;
- _inSetup = false;
- }
- }
-
- void addTagIf( const std::string & tag_r, bool yesno_r = true )
- {
- if ( yesno_r )
- *file << (_inSetup ? TAB : "") << "<" << tag_r << "/>" << endl;
- }
-
- void installResolvable (const ResObject::constPtr &resObject,
- const ResStatus &status);
- void lockResolvable (const ResObject::constPtr &resObject,
- const ResStatus &status);
- void keepResolvable (const ResObject::constPtr &resObject,
- const ResStatus &status);
- void deleteResolvable (const ResObject::constPtr &resObject,
- const ResStatus &status);
+ void installResolvable( const PoolItem & pi_r );
+ void lockResolvable( const PoolItem & pi_r );
+ void keepResolvable( const PoolItem & pi_r );
+ void deleteResolvable( const PoolItem & pi_r );
void addDependencies (const CapabilitySet &capRequire, const CapabilitySet &capConflict);
void addUpgradeRepos( const std::set<Repository> & upgradeRepos_r );
+ void distupgrade ();
+ void verifySystem ();
+ void update ();
+
std::string filename () { return dumpFile; }
};
HelixControl::HelixControl(const std::string & controlPath,
const RepositoryTable & repoTable,
const Arch & systemArchitecture,
- const LocaleSet &languages,
const target::Modalias::ModaliasList & modaliasList,
const std::set<std::string> & multiversionSpec,
- const std::string & systemPath)
+ const std::string & systemPath,
+ const bool forceResolve,
+ const bool onlyRequires,
+ const bool ignorealreadyrecommended)
:dumpFile (controlPath)
- ,_inSetup( true )
{
file = new ofstream(controlPath.c_str());
if (!file) {
<< "\" />" << endl << endl;
}
- for (LocaleSet::const_iterator iter = languages.begin(); iter != languages.end(); iter++) {
- *file << TAB << "<locale name=\"" << iter->code()
- << "\" />" << endl;
+ // HACK: directly access sat::pool
+ const sat::Pool & satpool( sat::Pool::instance() );
+
+ // RequestedLocales
+ const LocaleSet & addedLocales( satpool.getAddedRequestedLocales() );
+ const LocaleSet & removedLocales( satpool.getRemovedRequestedLocales() );
+ const LocaleSet & requestedLocales( satpool.getRequestedLocales() );
+
+ for ( Locale l : requestedLocales )
+ {
+ const char * fate = ( addedLocales.count(l) ? "\" fate=\"added" : "" );
+ *file << TAB << "<locale name=\"" << l << fate << "\" />" << endl;
+ }
+ for ( Locale l : removedLocales )
+ {
+ *file << TAB << "<locale name=\"" << l << "\" fate=\"removed\" />" << endl;
+ }
+
+ // AutoInstalled
+ for ( IdString::IdType n : satpool.autoInstalled() )
+ {
+ *file << TAB << "<autoinst name=\"" << IdString(n) << "\" />" << endl;
}
+
+
for_( it, modaliasList.begin(), modaliasList.end() ) {
- *file << TAB << "<modalias name=\"" << xml_escape(*it)
+ *file << TAB << "<modalias name=\"" << *it
<< "\" />" << endl;
}
<< "\" />" << endl;
}
- // setup continued outside....
+ if (forceResolve)
+ *file << TAB << "<forceResolve/>" << endl;
+ if (onlyRequires)
+ *file << TAB << "<onlyRequires/>" << endl;
+ if (ignorealreadyrecommended)
+ *file << TAB << "<ignorealreadyrecommended/>" << endl;
+
+ *file << "</setup>" << endl
+ << "<trial>" << endl;
}
HelixControl::HelixControl()
HelixControl::~HelixControl()
{
- closeSetup(); // in case it is still open
*file << "</trial>" << endl
<< "</test>" << endl;
delete(file);
}
-void HelixControl::installResolvable(const ResObject::constPtr &resObject,
- const ResStatus &status)
+void HelixControl::installResolvable( const PoolItem & pi_r )
{
- *file << "<install channel=\"" << resObject->repoInfo().alias() << "\" kind=\"" << toLower (resObject->kind().asString()) << "\""
- << " name=\"" << resObject->name() << "\"" << " arch=\"" << resObject->arch().asString() << "\""
- << " version=\"" << resObject->edition().version() << "\"" << " release=\"" << resObject->edition().release() << "\""
- << " status=\"" << status << "\""
+ *file << "<install channel=\"" << pi_r.repoInfo().alias() << "\""
+ << " kind=\"" << pi_r.kind() << "\""
+ << " name=\"" << pi_r.name() << "\""
+ << " arch=\"" << pi_r.arch() << "\""
+ << " version=\"" << pi_r.edition().version() << "\""
+ << " release=\"" << pi_r.edition().release() << "\""
+ << " status=\"" << pi_r.status() << "\""
<< "/>" << endl;
}
-void HelixControl::lockResolvable(const ResObject::constPtr &resObject,
- const ResStatus &status)
+void HelixControl::lockResolvable( const PoolItem & pi_r )
{
- *file << "<lock channel=\"" << resObject->repoInfo().alias() << "\" kind=\"" << toLower (resObject->kind().asString()) << "\""
- << " name=\"" << resObject->name() << "\"" << " arch=\"" << resObject->arch().asString() << "\""
- << " version=\"" << resObject->edition().version() << "\"" << " release=\"" << resObject->edition().release() << "\""
- << " status=\"" << status << "\""
+ *file << "<lock channel=\"" << pi_r.repoInfo().alias() << "\""
+ << " kind=\"" << pi_r.kind() << "\""
+ << " name=\"" << pi_r.name() << "\""
+ << " arch=\"" << pi_r.arch() << "\""
+ << " version=\"" << pi_r.edition().version() << "\""
+ << " release=\"" << pi_r.edition().release() << "\""
+ << " status=\"" << pi_r.status() << "\""
<< "/>" << endl;
}
-void HelixControl::keepResolvable(const ResObject::constPtr &resObject,
- const ResStatus &status)
+void HelixControl::keepResolvable( const PoolItem & pi_r )
{
- *file << "<keep channel=\"" << resObject->repoInfo().alias() << "\" kind=\"" << toLower (resObject->kind().asString()) << "\""
- << " name=\"" << resObject->name() << "\"" << " arch=\"" << resObject->arch().asString() << "\""
- << " version=\"" << resObject->edition().version() << "\"" << " release=\"" << resObject->edition().release() << "\""
- << " status=\"" << status << "\""
+ *file << "<keep channel=\"" << pi_r.repoInfo().alias() << "\""
+ << " kind=\"" << pi_r.kind() << "\""
+ << " name=\"" << pi_r.name() << "\""
+ << " arch=\"" << pi_r.arch() << "\""
+ << " version=\"" << pi_r.edition().version() << "\""
+ << " release=\"" << pi_r.edition().release() << "\""
+ << " status=\"" << pi_r.status() << "\""
<< "/>" << endl;
}
-void HelixControl::deleteResolvable(const ResObject::constPtr &resObject,
- const ResStatus &status)
+void HelixControl::deleteResolvable( const PoolItem & pi_r )
{
- *file << "<uninstall " << " kind=\"" << toLower (resObject->kind().asString()) << "\""
- << " name=\"" << resObject->name() << "\""
- << " status=\"" << status << "\""
+ *file << "<uninstall kind=\"" << pi_r.kind() << "\""
+ << " name=\"" << pi_r.name() << "\""
+ << " status=\"" << pi_r.status() << "\""
<< "/>" << endl;
}
}
}
+void HelixControl::distupgrade()
+{
+ *file << "<distupgrade/>" << endl;
+}
+
+void HelixControl::verifySystem()
+{
+ *file << "<verify/>" << endl;
+}
+
+void HelixControl::update()
+{
+ *file << "<update/>" << endl;
+}
+
//---------------------------------------------------------------------------
Testcase::Testcase()
if (dumpPool)
system = new HelixResolvable(dumpPath + "/solver-system.xml.gz");
- for ( ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it )
+ for ( const PoolItem & pi : pool )
{
- Resolvable::constPtr res = it->resolvable();
-
- if ( system && it->status().isInstalled() ) {
+ if ( system && pi.status().isInstalled() ) {
// system channel
- system->addResolvable (*it);
+ system->addResolvable( pi );
} else {
// repo channels
- Repository repo = it->resolvable()->satSolvable().repository();
+ Repository repo = pi.repository();
if (dumpPool) {
if (repoTable.find (repo) == repoTable.end()) {
repoTable[repo] = new HelixResolvable(dumpPath + "/"
+ str::numstring((long)repo.id())
+ "-package.xml.gz");
}
- repoTable[repo]->addResolvable (*it);
+ repoTable[repo]->addResolvable( pi );
}
}
- if ( it->status().isToBeInstalled()
- && !(it->status().isBySolver())) {
- items_to_install.push_back (*it);
+ if ( pi.status().isToBeInstalled()
+ && !(pi.status().isBySolver())) {
+ items_to_install.push_back( pi );
}
- if ( it->status().isKept()
- && !(it->status().isBySolver())) {
- items_keep.push_back (*it);
+ if ( pi.status().isKept()
+ && !(pi.status().isBySolver())) {
+ items_keep.push_back( pi );
}
- if ( it->status().isToBeUninstalled()
- && !(it->status().isBySolver())) {
- items_to_remove.push_back (*it);
+ if ( pi.status().isToBeUninstalled()
+ && !(pi.status().isBySolver())) {
+ items_to_remove.push_back( pi );
}
- if ( it->status().isLocked()
- && !(it->status().isBySolver())) {
- items_locked.push_back (*it);
+ if ( pi.status().isLocked()
+ && !(pi.status().isBySolver())) {
+ items_locked.push_back( pi );
}
}
HelixControl control (dumpPath + "/solver-test.xml",
repoTable,
ZConfig::instance().systemArchitecture(),
- pool.getRequestedLocales(),
target::Modalias::instance().modaliasList(),
ZConfig::instance().multiversionSpec(),
- "solver-system.xml.gz");
+ "solver-system.xml.gz",
+ resolver.forceResolve(),
+ resolver.onlyRequires(),
+ resolver.ignoreAlreadyRecommended() );
- // In <setup>: resolver flags,...
- control.addTagIf( "ignorealreadyrecommended", resolver.ignoreAlreadyRecommended() );
- control.addTagIf( "onlyRequires", resolver.onlyRequires() );
- control.addTagIf( "forceResolve", resolver.forceResolve() );
+ for ( const PoolItem & pi : items_to_install )
+ { control.installResolvable( pi ); }
- control.addTagIf( "cleandepsOnRemove", resolver.cleandepsOnRemove() );
+ for ( const PoolItem & pi : items_locked )
+ { control.lockResolvable( pi ); }
- control.addTagIf( "allowVendorChange", resolver.allowVendorChange() );
+ for ( const PoolItem & pi : items_keep )
+ { control.keepResolvable( pi ); }
- control.addTagIf( "dupAllowDowngrade", resolver.dupAllowDowngrade() );
- control.addTagIf( "dupAllowNameChange", resolver.dupAllowNameChange() );
- control.addTagIf( "dupAllowArchChange", resolver.dupAllowArchChange() );
- control.addTagIf( "dupAllowVendorChange", resolver.dupAllowVendorChange() );
-
- control.closeSetup();
- // Entering <trial>...
-
- for (PoolItemList::const_iterator iter = items_to_install.begin(); iter != items_to_install.end(); iter++) {
- control.installResolvable (iter->resolvable(), iter->status());
- }
-
- for (PoolItemList::const_iterator iter = items_locked.begin(); iter != items_locked.end(); iter++) {
- control.lockResolvable (iter->resolvable(), iter->status());
- }
-
- for (PoolItemList::const_iterator iter = items_keep.begin(); iter != items_keep.end(); iter++) {
- control.keepResolvable (iter->resolvable(), iter->status());
- }
-
- for (PoolItemList::const_iterator iter = items_to_remove.begin(); iter != items_to_remove.end(); iter++) {
- control.deleteResolvable (iter->resolvable(), iter->status());
- }
+ for ( const PoolItem & pi : items_to_remove )
+ { control.deleteResolvable( pi ); }
control.addDependencies (resolver.extraRequires(), resolver.extraConflicts());
control.addDependencies (SystemCheck::instance().requiredSystemCap(),
SystemCheck::instance().conflictSystemCap());
control.addUpgradeRepos( resolver.upgradeRepos() );
- control.addTagIf( "distupgrade", resolver.isUpgradeMode() );
- control.addTagIf( "update", resolver.isUpdateMode() );
- control.addTagIf( "verify", resolver.isVerifyingMode() );
+ if (resolver.isUpgradeMode())
+ control.distupgrade ();
+ if (resolver.isUpdateMode())
+ control.update();
+ if (resolver.isVerifyingMode())
+ control.verifySystem();
return true;
}