Skip to content

Commit

Permalink
Merge branch '1.x' into 2.x
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nicolas-grekas committed Jun 3, 2022
2 parents dcbe58c + c36d11d commit f15c99e
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 167 deletions.
36 changes: 0 additions & 36 deletions src/Command/RemoveCommand.php

This file was deleted.

85 changes: 0 additions & 85 deletions src/Command/RequireCommand.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Command/UpdateCommand.php

This file was deleted.

30 changes: 21 additions & 9 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ class_exists(__NAMESPACE__.str_replace('/', '\\', substr($file, \strlen(__DIR__)
}

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

$app->add(new Command\RequireCommand($resolver, \Closure::fromCallable([$this, 'updateComposerLock'])));
$app->add(new Command\UpdateCommand($resolver));
$app->add(new Command\RemoveCommand($resolver));
$app->add(new Command\RecipesCommand($this, $this->lock, $rfs));
$app->add(new Command\InstallRecipesCommand($this, $this->options->get('root-dir'), $this->options->get('runtime')['dotenv_path'] ?? '.env'));
$app->add(new Command\UpdateRecipesCommand($this, $this->downloader, $rfs, $this->configurator, $this->options->get('root-dir')));
Expand All @@ -208,6 +204,14 @@ public function configureInstaller()
foreach ($backtrace as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Installer) {
$this->installer = $trace['object']->setSuggestedPackagesReporter(new SuggestedPackagesReporter(new NullIO()));

$updateAllowList = \Closure::bind(function () {
return $this->updateWhitelist ?? $this->updateAllowList;
}, $this->installer, $this->installer)();

if (['php' => 0] === $updateAllowList) {
$this->dryRun = true; // prevent recipes from being uninstalled when removing a pack
}
}

if (isset($trace['object']) && $trace['object'] instanceof GlobalCommand) {
Expand Down Expand Up @@ -313,6 +317,9 @@ public function update(Event $event, $operations = [])
if (!isset($json['flex-'.$type])) {
continue;
}

$this->io->writeError(sprintf('<warning>Using section "flex-%s" in composer.json is deprecated, use "%1$s" instead.</>', $type));

foreach ($json['flex-'.$type] as $package => $constraint) {
if ($symfonyVersion && '*' === $constraint && isset($versions['splits'][$package])) {
// replace unbounded constraints for symfony/* packages by extra.symfony.require
Expand Down Expand Up @@ -538,6 +545,7 @@ public function fetchRecipes(array $operations, bool $reset): array
$recipes = [
'symfony/framework-bundle' => null,
];
$packRecipes = [];
$metaRecipes = [];

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

if (isset($manifests[$name])) {
if ('metapackage' === $package->getType()) {
$metaRecipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
$recipe = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);

if ('symfony-pack' === $package->getType()) {
$packRecipes[$name] = $recipe;
} elseif ('metapackage' === $package->getType()) {
$metaRecipes[$name] = $recipe;
} elseif ('symfony/flex' === $name) {
$flexRecipe = [$name => new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? [])];
$flexRecipe = [$name => $recipe];
} else {
$recipes[$name] = new Recipe($package, $name, $job, $manifests[$name], $locks[$name] ?? []);
$recipes[$name] = $recipe;
}
}

Expand All @@ -618,7 +630,7 @@ public function fetchRecipes(array $operations, bool $reset): array
}
}

return array_merge($flexRecipe, $metaRecipes, array_filter($recipes));
return array_merge($flexRecipe, $packRecipes, $metaRecipes, array_filter($recipes));
}

public function truncatePackages(PrePoolCreateEvent $event)
Expand Down
4 changes: 4 additions & 0 deletions src/ScriptExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ private function expandPhpScript(string $cmd): string
$arguments[] = '--php-ini='.$ini;
}

if ($memoryLimit = (string) getenv('COMPOSER_MEMORY_LIMIT')) {
$arguments[] = "-d memory_limit={$memoryLimit}";
}

$phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments));

return ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$cmd;
Expand Down
5 changes: 4 additions & 1 deletion src/SymfonyBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ private function isBundleClass(string $class, string $path, bool $isPsr4): bool
}

// heuristic that should work in almost all cases
return false !== strpos(file_get_contents($classPath), 'Symfony\Component\HttpKernel\Bundle\Bundle');
$classContents = file_get_contents($classPath);

return (false !== strpos($classContents, 'Symfony\Component\HttpKernel\Bundle\Bundle'))
|| (false !== strpos($classContents, 'Symfony\Component\HttpKernel\Bundle\AbstractBundle'));
}
}
2 changes: 2 additions & 0 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function testFetchRecipesOrder()
['name' => 'symfony/flex', 'type' => 'composer-plugin'],
['name' => 'symfony/framework-bundle', 'type' => 'library'],
['name' => 'symfony/webapp-meta', 'type' => 'metapackage'],
['name' => 'symfony/webapp-pack', 'type' => 'symfony-pack'],
];

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

$this->assertSame([
'symfony/flex',
'symfony/webapp-pack',
'symfony/webapp-meta',
'symfony/framework-bundle',
'symfony/console',
Expand Down
58 changes: 58 additions & 0 deletions tests/ScriptExecutorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

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

namespace Symfony\Flex\Tests;

use Composer\Composer;
use Composer\IO\NullIO;
use Composer\Util\ProcessExecutor;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Flex\Options;
use Symfony\Flex\ScriptExecutor;

final class ScriptExecutorTest extends TestCase
{
/**
* @backupGlobals enabled
*/
public function testMemoryLimit(): void
{
$command = './command.php';
$memoryLimit = '32M';
putenv("COMPOSER_MEMORY_LIMIT={$memoryLimit}");
$executorMock = $this->createMock(ProcessExecutor::class);
$scriptExecutor = new ScriptExecutor(new Composer(), new NullIO(), new Options(), $executorMock);

$phpFinder = new PhpExecutableFinder();
if (!$php = $phpFinder->find(false)) {
throw new \RuntimeException('The PHP executable could not be found, add it to your PATH and try again.');
}

$arguments = $phpFinder->findArguments();
$ini = php_ini_loaded_file();
$arguments[] = "--php-ini={$ini}";
$arguments[] = "-d memory_limit={$memoryLimit}";

$phpArgs = implode(' ', array_map([ProcessExecutor::class, 'escape'], $arguments));

$expectedCommand = ProcessExecutor::escape($php).($phpArgs ? ' '.$phpArgs : '').' '.$command;

$executorMock
->method('execute')
->with($expectedCommand)
->willReturn(0)
;
$this->expectNotToPerformAssertions();

$scriptExecutor->execute('php-script', $command);
}
}

0 comments on commit f15c99e

Please sign in to comment.