Skip to content

Commit f15c99e

Browse files
Merge branch '1.x' into 2.x
* 1.x: Deprecate "flex-require" sections Propagate COMPOSER_MEMORY_LIMIT to script executor Remove overriding native composer commands Prevent recipes bound to packs from being uninstalled when unpacking check for AbstractBundle
2 parents dcbe58c + c36d11d commit f15c99e

8 files changed

+89
-167
lines changed

src/Command/RemoveCommand.php

-36
This file was deleted.

src/Command/RequireCommand.php

-85
This file was deleted.

src/Command/UpdateCommand.php

-36
This file was deleted.

src/Flex.php

+21-9
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
172172
}
173173

174174
if (isset(self::$aliasResolveCommands[$command])) {
175-
// early resolve for BC with Composer 1.0
176175
if ($input->hasArgument('packages')) {
177176
$input->setArgument('packages', $resolver->resolve($input->getArgument('packages'), self::$aliasResolveCommands[$command]));
178177
}
@@ -185,9 +184,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
185184
BasePackage::$stabilities['dev'] = 1 + BasePackage::STABILITY_STABLE;
186185
}
187186

188-
$app->add(new Command\RequireCommand($resolver, \Closure::fromCallable([$this, 'updateComposerLock'])));
189-
$app->add(new Command\UpdateCommand($resolver));
190-
$app->add(new Command\RemoveCommand($resolver));
191187
$app->add(new Command\RecipesCommand($this, $this->lock, $rfs));
192188
$app->add(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env'));
193189
$app->add(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir')));
@@ -208,6 +204,14 @@ public function configureInstaller()
208204
foreach ($backtrace as $trace) {
209205
if (isset($trace['object']) && $trace['object'] instanceof Installer) {
210206
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));
207+
208+
$updateAllowList = \Closure::bind(function () {
209+
return $this->updateWhitelist ?? $this->updateAllowList;
210+
}, $this->installer, $this->installer)();
211+
212+
if (['php' => 0] === $updateAllowList) {
213+
$this->dryRun = true; // prevent recipes from being uninstalled when removing a pack
214+
}
211215
}
212216

213217
if (isset($trace['object']) && $trace['object'] instanceof GlobalCommand) {
@@ -313,6 +317,9 @@ public function update(Event $event, $operations = [])
313317
if (!isset($json['flex-'.$type])) {
314318
continue;
315319
}
320+
321+
$this->io->writeError(sprintf('<warning>Using section "flex-%s" in composer.json is deprecated, use "%1$s" instead.</>', $type));
322+
316323
foreach ($json['flex-'.$type] as $package => $constraint) {
317324
if ($symfonyVersion && '*' === $constraint && isset($versions['splits'][$package])) {
318325
// replace unbounded constraints for symfony/* packages by extra.symfony.require
@@ -538,6 +545,7 @@ public function fetchRecipes(array $operations, bool $reset): array
538545
$recipes = [
539546
'symfony/framework-bundle' => null,
540547
];
548+
$packRecipes = [];
541549
$metaRecipes = [];
542550

543551
foreach ($operations as $operation) {
@@ -587,12 +595,16 @@ public function fetchRecipes(array $operations, bool $reset): array
587595
}
588596

589597
if (isset($manifests[$name])) {
590-
if ('metapackage' === $package->getType()) {
591-
$metaRecipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
598+
$recipe = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
599+
600+
if ('symfony-pack' === $package->getType()) {
601+
$packRecipes[$name] = $recipe;
602+
} elseif ('metapackage' === $package->getType()) {
603+
$metaRecipes[$name] = $recipe;
592604
} elseif ('symfony/flex' === $name) {
593-
$flexRecipe = [$name => new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? [])];
605+
$flexRecipe = [$name => $recipe];
594606
} else {
595-
$recipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
607+
$recipes[$name] = $recipe;
596608
}
597609
}
598610

@@ -618,7 +630,7 @@ public function fetchRecipes(array $operations, bool $reset): array
618630
}
619631
}
620632

621-
return array_merge($flexRecipe, $metaRecipes, array_filter($recipes));
633+
return array_merge($flexRecipe, $packRecipes, $metaRecipes, array_filter($recipes));
622634
}
623635

624636
public function truncatePackages(PrePoolCreateEvent $event)

src/ScriptExecutor.php

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ private function expandPhpScript(string $cmd): string
127127
$arguments[] = '--php-ini='.$ini;
128128
}
129129

130+
if ($memoryLimit = (string) getenv('COMPOSER_MEMORY_LIMIT')) {
131+
$arguments[] = "-d memory_limit={$memoryLimit}";
132+
}
133+
130134
$phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments));
131135

132136
return ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$cmd;

src/SymfonyBundle.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ private function isBundleClass(string $class, string $path, bool $isPsr4): bool
107107
}
108108

109109
// heuristic that should work in almost all cases
110-
return false !== strpos(file_get_contents($classPath), 'Symfony\Component\HttpKernel\Bundle\Bundle');
110+
$classContents = file_get_contents($classPath);
111+
112+
return (false !== strpos($classContents, 'Symfony\Component\HttpKernel\Bundle\Bundle'))
113+
|| (false !== strpos($classContents, 'Symfony\Component\HttpKernel\Bundle\AbstractBundle'));
111114
}
112115
}

tests/FlexTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public function testFetchRecipesOrder()
187187
['name' => 'symfony/flex', 'type' => 'composer-plugin'],
188188
['name' => 'symfony/framework-bundle', 'type' => 'library'],
189189
['name' => 'symfony/webapp-meta', 'type' => 'metapackage'],
190+
['name' => 'symfony/webapp-pack', 'type' => 'symfony-pack'],
190191
];
191192

192193
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
@@ -209,6 +210,7 @@ public function testFetchRecipesOrder()
209210

210211
$this->assertSame([
211212
'symfony/flex',
213+
'symfony/webapp-pack',
212214
'symfony/webapp-meta',
213215
'symfony/framework-bundle',
214216
'symfony/console',

tests/ScriptExecutorTest.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[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 Symfony\Flex\Tests;
13+
14+
use Composer\Composer;
15+
use Composer\IO\NullIO;
16+
use Composer\Util\ProcessExecutor;
17+
use PHPUnit\Framework\TestCase;
18+
use Symfony\Component\Process\PhpExecutableFinder;
19+
use Symfony\Flex\Options;
20+
use Symfony\Flex\ScriptExecutor;
21+
22+
final class ScriptExecutorTest extends TestCase
23+
{
24+
/**
25+
* @backupGlobals enabled
26+
*/
27+
public function testMemoryLimit(): void
28+
{
29+
$command = './command.php';
30+
$memoryLimit = '32M';
31+
putenv("COMPOSER_MEMORY_LIMIT={$memoryLimit}");
32+
$executorMock = $this->createMock(ProcessExecutor::class);
33+
$scriptExecutor = new ScriptExecutor(new Composer(), new NullIO(), new Options(), $executorMock);
34+
35+
$phpFinder = new PhpExecutableFinder();
36+
if (!$php = $phpFinder->find(false)) {
37+
throw new \RuntimeException('The PHP executable could not be found, add it to your PATH and try again.');
38+
}
39+
40+
$arguments = $phpFinder->findArguments();
41+
$ini = php_ini_loaded_file();
42+
$arguments[] = "--php-ini={$ini}";
43+
$arguments[] = "-d memory_limit={$memoryLimit}";
44+
45+
$phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments));
46+
47+
$expectedCommand = ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$command;
48+
49+
$executorMock
50+
->method('execute')
51+
->with($expectedCommand)
52+
->willReturn(0)
53+
;
54+
$this->expectNotToPerformAssertions();
55+
56+
$scriptExecutor->execute('php-script', $command);
57+
}
58+
}

0 commit comments

Comments
 (0)