pkgman resolve-dependencies: Verify result
* Make sure that the computed dependencies don't themselves depend on the specified package. * Print only the actual dependencies, not the specified package.
This commit is contained in:
@@ -196,6 +196,47 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
verify_result(const BSolverResult& result, BSolverPackage* specifiedPackage)
|
||||||
|
{
|
||||||
|
// create the solver
|
||||||
|
BSolver* solver;
|
||||||
|
status_t error = BSolver::Create(solver);
|
||||||
|
if (error != B_OK)
|
||||||
|
DIE(error, "failed to create solver");
|
||||||
|
|
||||||
|
// Add an installation repository and add all of the result packages save
|
||||||
|
// the specified package.
|
||||||
|
BSolverRepository installation;
|
||||||
|
RepositoryBuilder installationBuilder(installation, "installation");
|
||||||
|
|
||||||
|
for (int32 i = 0; const BSolverResultElement* element = result.ElementAt(i);
|
||||||
|
i++) {
|
||||||
|
BSolverPackage* package = element->Package();
|
||||||
|
if (package != specifiedPackage)
|
||||||
|
installationBuilder.AddPackage(package->Info());
|
||||||
|
}
|
||||||
|
installationBuilder.AddToSolver(solver, true);
|
||||||
|
|
||||||
|
// resolve
|
||||||
|
error = solver->VerifyInstallation();
|
||||||
|
if (error != B_OK)
|
||||||
|
DIE(error, "failed to verify computed package dependencies");
|
||||||
|
|
||||||
|
if (solver->HasProblems()) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"Encountered problems verifying computed package dependencies:\n");
|
||||||
|
|
||||||
|
int32 problemCount = solver->CountProblems();
|
||||||
|
for (int32 i = 0; i < problemCount; i++) {
|
||||||
|
printf(" %" B_PRId32 ": %s\n", i + 1,
|
||||||
|
solver->ProblemAt(i)->ToString().String());
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
command_resolve_dependencies(int argc, const char* const* argv)
|
command_resolve_dependencies(int argc, const char* const* argv)
|
||||||
{
|
{
|
||||||
@@ -266,13 +307,14 @@ command_resolve_dependencies(int argc, const char* const* argv)
|
|||||||
RepositoryBuilder(dummyRepository, "dummy", "specified package")
|
RepositoryBuilder(dummyRepository, "dummy", "specified package")
|
||||||
.AddPackage(packagePath)
|
.AddPackage(packagePath)
|
||||||
.AddToSolver(solver);
|
.AddToSolver(solver);
|
||||||
BSolverPackage* package = dummyRepository.PackageAt(0);
|
BSolverPackage* specifiedPackage = dummyRepository.PackageAt(0);
|
||||||
|
|
||||||
// resolve
|
// resolve
|
||||||
BSolverPackageSpecifierList packagesToInstall;
|
BSolverPackageSpecifierList packagesToInstall;
|
||||||
if (!packagesToInstall.AppendSpecifier(
|
if (!packagesToInstall.AppendSpecifier(
|
||||||
BSolverPackageSpecifier(&dummyRepository,
|
BSolverPackageSpecifier(&dummyRepository,
|
||||||
BPackageResolvableExpression(package->Info().Name())))) {
|
BPackageResolvableExpression(
|
||||||
|
specifiedPackage->Info().Name())))) {
|
||||||
DIE(B_NO_MEMORY, "failed to add specified package");
|
DIE(B_NO_MEMORY, "failed to add specified package");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,14 +339,22 @@ command_resolve_dependencies(int argc, const char* const* argv)
|
|||||||
if (error != B_OK)
|
if (error != B_OK)
|
||||||
DIE(error, "failed to resolve package dependencies");
|
DIE(error, "failed to resolve package dependencies");
|
||||||
|
|
||||||
|
// Verify that the resolved packages don't depend on the specified package.
|
||||||
|
verify_result(result, specifiedPackage);
|
||||||
|
|
||||||
// print packages
|
// print packages
|
||||||
for (int32 i = 0; const BSolverResultElement* element = result.ElementAt(i);
|
for (int32 i = 0; const BSolverResultElement* element = result.ElementAt(i);
|
||||||
i++) {
|
i++) {
|
||||||
|
BSolverPackage* package = element->Package();
|
||||||
|
|
||||||
// TODO: Print the path to the package/package info!
|
// TODO: Print the path to the package/package info!
|
||||||
|
// skip the specified package
|
||||||
|
if (package == specifiedPackage)
|
||||||
|
continue;
|
||||||
|
|
||||||
printf("%s-%s\n",
|
printf("%s-%s\n",
|
||||||
element->Package()->Info().Name().String(),
|
package->Info().Name().String(),
|
||||||
element->Package()->Info().Version().ToString().String());
|
package->Info().Version().ToString().String());
|
||||||
// TODO: Filter out the given package!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user