Skip to content

Commit

Permalink
Import initial partial port of the libzypp satsolver.
Browse files Browse the repository at this point in the history
  • Loading branch information
naderman committed Apr 5, 2011
1 parent ea13ad7 commit 933cc61
Show file tree
Hide file tree
Showing 23 changed files with 3,149 additions and 0 deletions.
39 changes: 39 additions & 0 deletions PORTING_INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
* add rule
* p = direct literal; always < 0 for installed rpm rules
* d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
*
*
* A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
*
* p < 0 : pkg id of A
* d > 0 : Offset in whatprovidesdata (list of providers of b)
*
* A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
* p < 0 : pkg id of A
* d < 0 : Id of solvable (e.g. B1)
*
* d == 0: unary rule, assertion => (A) or (-A)
*
* Install: p > 0, d = 0 (A) user requested install
* Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
* Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
* Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
* Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
* also used for obsoletes
* ?: p > 0, d < 0 (A|-B)
* No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
*
* resulting watches:
* ------------------
* Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
* Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
* every other : w1 = p, w2 = whatprovidesdata[d];
* Disabled rule: w1 = 0
*
* always returns a rule for non-rpm rules



p > 0, d = 0, (A), w1 = p, w2 = 0
p < 0, d = 0, (-A), w1 = p, w2 = 0
p !=0, d = 0, (p|q), w1 = p, w2 = q
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Composer Test Suite">
<directory>./tests/Composer/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src/Composer/</directory>
</whitelist>
</filter>
</phpunit>
62 changes: 62 additions & 0 deletions src/Composer/DependencyResolver/ArrayRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Composer\DependencyResolver;

/**
* A repository implementation that simply stores packages in an array
*
* @author Nils Adermann <[email protected]>
*/
class ArrayRepository implements RepositoryInterface
{
protected $packages = array();

/**
* Adds a new package to the repository
*
* @param Package $package
*/
public function addPackage(Package $package)
{
$this->packages[$package->getId()] = $package;
}

/**
* Returns all contained packages
*
* @return array All packages
*/
public function getPackages()
{
return $this->packages;
}

/**
* Checks if a package is contained in this repository
*
* @return bool
*/
public function contains(Package $package)
{
return isset($this->packages[$package->getId()]);
}

/**
* Returns the number of packages in this repository
*
* @return int Number of packages
*/
public function count()
{
return count($this->packages);
}
}
63 changes: 63 additions & 0 deletions src/Composer/DependencyResolver/DefaultPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Composer\DependencyResolver;

/**
* @author Nils Adermann <[email protected]>
*/
class DefaultPolicy implements PolicyInterface
{
public function allowUninstall()
{
return false;
}

public function allowDowngrade()
{
return false;
}

public function versionCompare(Package $a, Package $b, $operator)
{
return version_compare($a->getVersion(), $b->getVersion(), $operator);
}

public function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll = false)
{
$packages = array();

foreach ($pool->whatProvides($package->getName()) as $candidate) {
// skip old packages unless downgrades are an option
if (!$allowAll && !$this->allowDowngrade() && $this->versionCompare($package, $candidate, '>')) {
continue;
}

if ($candidate != $package) {
$packages[] = $candidate;
}
}

return $packages;
}

public function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package)
{
// todo: package blacklist?
return true;
}

public function selectPreferedPackages(array $literals)
{
// todo: prefer installed, recommended, highest priority repository, ...
return array($literals[0]);
}
}
61 changes: 61 additions & 0 deletions src/Composer/DependencyResolver/Literal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Composer\DependencyResolver;

/**
* @author Nils Adermann <[email protected]>
*/
class Literal
{
protected $wanted;

public function __construct(Package $package, $wanted)
{
$this->package = $package;
$this->wanted = $wanted;
}

public function isWanted()
{
return $this->wanted;
}

public function getPackage()
{
return $this->package;
}

public function getPackageId()
{
return $this->package->getId();
}

public function getId()
{
return (($this->wanted) ? 1 : -1) * $this->package->getId();
}

public function __toString()
{
return ($this->isWanted() ? '+' : '-').$this->getPackage();
}

public function inverted()
{
return new Literal($this->getPackage(), !$this->isWanted());
}

public function equals(Literal $b)
{
return $this->getId() === $b->getId();
}
}
Loading

0 comments on commit 933cc61

Please sign in to comment.