Skip to content

Commit b1fb5d5

Browse files
bug #871 Read recipe conflicts from index.json (nicolas-grekas)
This PR was merged into the 1.x branch. Discussion ---------- Read recipe conflicts from index.json Allowed by symfony-tools/recipes-checker@86f5d7f Commits ------- a264ffc Read recipe conflicts from index.json
2 parents c5f09a2 + a264ffc commit b1fb5d5

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Downloader.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ class Downloader
4646
private $degradedMode = false;
4747
private $endpoints;
4848
private $index;
49+
private $conflicts;
4950
private $legacyEndpoint;
5051
private $caFile;
5152
private $enabled = true;
53+
private $composer;
5254

5355
public function __construct(Composer $composer, IoInterface $io, $rfs)
5456
{
@@ -91,6 +93,7 @@ public function __construct(Composer $composer, IoInterface $io, $rfs)
9193
$this->rfs = $rfs;
9294
$this->cache = new ComposerCache($io, $config->get('cache-repo-dir').'/flex');
9395
$this->sess = bin2hex(random_bytes(16));
96+
$this->composer = $composer;
9497
}
9598

9699
public function getSessionId(): string
@@ -136,6 +139,22 @@ public function getRecipes(array $operations): array
136139
{
137140
$this->initialize();
138141

142+
if ($this->conflicts) {
143+
$lockedRepository = $this->composer->getLocker()->getLockedRepository();
144+
foreach ($this->conflicts as $conflicts) {
145+
foreach ($conflicts as $package => $versions) {
146+
foreach ($versions as $version => $conflicts) {
147+
foreach ($conflicts as $conflictingPackage => $constraint) {
148+
if ($lockedRepository->findPackage($conflictingPackage, $constraint)) {
149+
unset($this->index[$package][$version]);
150+
}
151+
}
152+
}
153+
}
154+
}
155+
$this->conflicts = [];
156+
}
157+
139158
$data = [];
140159
$urls = [];
141160
$chunk = '';
@@ -210,6 +229,10 @@ public function getRecipes(array $operations): array
210229
continue;
211230
}
212231

232+
if (\is_array($recipeVersions)) {
233+
$data['conflicts'][$package->getName()] = true;
234+
}
235+
213236
if (null !== $this->endpoints) {
214237
$data['locks'][$package->getName()]['version'] = $version;
215238
continue;
@@ -434,11 +457,14 @@ private function initialize()
434457
foreach ($config['recipes'] ?? [] as $package => $versions) {
435458
$this->index[$package] = $this->index[$package] ?? array_fill_keys($versions, $endpoint);
436459
}
460+
$this->conflicts[] = $config['recipe-conflicts'] ?? [];
437461
self::$versions += $config['versions'] ?? [];
438462
self::$aliases += $config['aliases'] ?? [];
439-
unset($config['recipes'], $config['versions'], $config['aliases']);
463+
unset($config['recipes'], $config['recipe-conflicts'], $config['versions'], $config['aliases']);
440464
$this->endpoints[$endpoint] = $config;
441465
}
466+
467+
return false;
442468
}
443469

444470
private static function generateCacheKey(string $url): string

src/Flex.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,11 @@ public function fetchRecipes(array $operations, bool $reset): array
754754
$name = $package->getName();
755755
$job = method_exists($operation, 'getOperationType') ? $operation->getOperationType() : $operation->getJobType();
756756

757+
if (!isset($manifests[$name]) && isset($data['conflicts'][$name])) {
758+
$this->io->writeError(sprintf(' - Skipping recipe for %s: all versions of the recipe conflict with your package versions.', $name), true, IOInterface::VERBOSE);
759+
continue;
760+
}
761+
757762
while ($this->doesRecipeConflict($manifests[$name] ?? [], $operation)) {
758763
$this->downloader->removeRecipeFromIndex($name, $manifests[$name]['version']);
759764
$newData = $this->downloader->getRecipes([$operation]);
@@ -987,7 +992,7 @@ private function reinstall(Event $event, bool $update)
987992
{
988993
$event->stopPropagation();
989994

990-
$ed = $composer->getEventDispatcher();
995+
$ed = $this->composer->getEventDispatcher();
991996
$disableScripts = !method_exists($ed, 'setRunScripts') || !((array) $ed)["\0*\0runScripts"];
992997
$composer = Factory::create($this->io, null, false, $disableScripts);
993998

0 commit comments

Comments
 (0)