Skip to content

Commit 933cc61

Browse files
committed
Import initial partial port of the libzypp satsolver.
1 parent ea13ad7 commit 933cc61

23 files changed

+3149
-0
lines changed

PORTING_INFO

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
* add rule
2+
* p = direct literal; always < 0 for installed rpm rules
3+
* d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
4+
*
5+
*
6+
* A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
7+
*
8+
* p < 0 : pkg id of A
9+
* d > 0 : Offset in whatprovidesdata (list of providers of b)
10+
*
11+
* A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
12+
* p < 0 : pkg id of A
13+
* d < 0 : Id of solvable (e.g. B1)
14+
*
15+
* d == 0: unary rule, assertion => (A) or (-A)
16+
*
17+
* Install: p > 0, d = 0 (A) user requested install
18+
* Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
19+
* Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
20+
* Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
21+
* Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
22+
* also used for obsoletes
23+
* ?: p > 0, d < 0 (A|-B)
24+
* No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
25+
*
26+
* resulting watches:
27+
* ------------------
28+
* Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
29+
* Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
30+
* every other : w1 = p, w2 = whatprovidesdata[d];
31+
* Disabled rule: w1 = 0
32+
*
33+
* always returns a rule for non-rpm rules
34+
35+
36+
37+
p > 0, d = 0, (A), w1 = p, w2 = 0
38+
p < 0, d = 0, (-A), w1 = p, w2 = 0
39+
p !=0, d = 0, (p|q), w1 = p, w2 = q

phpunit.xml.dist

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="tests/bootstrap.php"
13+
>
14+
<testsuites>
15+
<testsuite name="Composer Test Suite">
16+
<directory>./tests/Composer/</directory>
17+
</testsuite>
18+
</testsuites>
19+
20+
<filter>
21+
<whitelist>
22+
<directory>./src/Composer/</directory>
23+
</whitelist>
24+
</filter>
25+
</phpunit>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Composer.
5+
*
6+
* (c) Nils Adermann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Composer\DependencyResolver;
13+
14+
/**
15+
* A repository implementation that simply stores packages in an array
16+
*
17+
* @author Nils Adermann <[email protected]>
18+
*/
19+
class ArrayRepository implements RepositoryInterface
20+
{
21+
protected $packages = array();
22+
23+
/**
24+
* Adds a new package to the repository
25+
*
26+
* @param Package $package
27+
*/
28+
public function addPackage(Package $package)
29+
{
30+
$this->packages[$package->getId()] = $package;
31+
}
32+
33+
/**
34+
* Returns all contained packages
35+
*
36+
* @return array All packages
37+
*/
38+
public function getPackages()
39+
{
40+
return $this->packages;
41+
}
42+
43+
/**
44+
* Checks if a package is contained in this repository
45+
*
46+
* @return bool
47+
*/
48+
public function contains(Package $package)
49+
{
50+
return isset($this->packages[$package->getId()]);
51+
}
52+
53+
/**
54+
* Returns the number of packages in this repository
55+
*
56+
* @return int Number of packages
57+
*/
58+
public function count()
59+
{
60+
return count($this->packages);
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Composer.
5+
*
6+
* (c) Nils Adermann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Composer\DependencyResolver;
13+
14+
/**
15+
* @author Nils Adermann <[email protected]>
16+
*/
17+
class DefaultPolicy implements PolicyInterface
18+
{
19+
public function allowUninstall()
20+
{
21+
return false;
22+
}
23+
24+
public function allowDowngrade()
25+
{
26+
return false;
27+
}
28+
29+
public function versionCompare(Package $a, Package $b, $operator)
30+
{
31+
return version_compare($a->getVersion(), $b->getVersion(), $operator);
32+
}
33+
34+
public function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll = false)
35+
{
36+
$packages = array();
37+
38+
foreach ($pool->whatProvides($package->getName()) as $candidate) {
39+
// skip old packages unless downgrades are an option
40+
if (!$allowAll && !$this->allowDowngrade() && $this->versionCompare($package, $candidate, '>')) {
41+
continue;
42+
}
43+
44+
if ($candidate != $package) {
45+
$packages[] = $candidate;
46+
}
47+
}
48+
49+
return $packages;
50+
}
51+
52+
public function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package)
53+
{
54+
// todo: package blacklist?
55+
return true;
56+
}
57+
58+
public function selectPreferedPackages(array $literals)
59+
{
60+
// todo: prefer installed, recommended, highest priority repository, ...
61+
return array($literals[0]);
62+
}
63+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Composer.
5+
*
6+
* (c) Nils Adermann <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Composer\DependencyResolver;
13+
14+
/**
15+
* @author Nils Adermann <[email protected]>
16+
*/
17+
class Literal
18+
{
19+
protected $wanted;
20+
21+
public function __construct(Package $package, $wanted)
22+
{
23+
$this->package = $package;
24+
$this->wanted = $wanted;
25+
}
26+
27+
public function isWanted()
28+
{
29+
return $this->wanted;
30+
}
31+
32+
public function getPackage()
33+
{
34+
return $this->package;
35+
}
36+
37+
public function getPackageId()
38+
{
39+
return $this->package->getId();
40+
}
41+
42+
public function getId()
43+
{
44+
return (($this->wanted) ? 1 : -1) * $this->package->getId();
45+
}
46+
47+
public function __toString()
48+
{
49+
return ($this->isWanted() ? '+' : '-').$this->getPackage();
50+
}
51+
52+
public function inverted()
53+
{
54+
return new Literal($this->getPackage(), !$this->isWanted());
55+
}
56+
57+
public function equals(Literal $b)
58+
{
59+
return $this->getId() === $b->getId();
60+
}
61+
}

0 commit comments

Comments
 (0)