Skip to content

Commit

Permalink
Merge branch '2.2' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Apr 1, 2022
2 parents ef12e42 + 95e09d3 commit dce63fd
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 27 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Expand Up @@ -42,6 +42,14 @@
* Fixed symlink creation in linux VM guest filesystems to be recognized by Windows (#10592)
* Performance improvement in pool optimization step (#10585)

### [2.2.11] 2022-04-01

* Added missing config.bitbucket-oauth in composer-schema.json
* Added --2.2 flag to `self-update` to pin the Composer version to the 2.2 LTS range (#10682)
* Updated semver, jsonlint deps for minor fixes
* Fixed generation of autoload crashing if a package has a broken path (#10688)
* Removed dev-master=>dev-main alias from #10372 as it does not work when reloading from lock file and extracting dev deps (#10651)

### [2.2.10] 2022-03-29

* Fixed Bitbucket authorization detection due to API changes (#10657)
Expand Down Expand Up @@ -1461,6 +1469,7 @@
[2.3.0]: https://github.com/composer/composer/compare/2.3.0-RC2...2.3.0
[2.3.0-RC2]: https://github.com/composer/composer/compare/2.3.0-RC1...2.3.0-RC2
[2.3.0-RC1]: https://github.com/composer/composer/compare/2.2.9...2.3.0-RC1
[2.2.11]: https://github.com/composer/composer/compare/2.2.10...2.2.11
[2.2.10]: https://github.com/composer/composer/compare/2.2.9...2.2.10
[2.2.9]: https://github.com/composer/composer/compare/2.2.8...2.2.9
[2.2.8]: https://github.com/composer/composer/compare/2.2.7...2.2.8
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Composer/Autoload/AutoloadGenerator.php
Expand Up @@ -162,6 +162,7 @@ public function setPlatformRequirementFilter(PlatformRequirementFilterInterface
* @param string $suffix
* @return int
* @throws \Seld\JsonLint\ParsingException
* @throws \RuntimeException
*/
public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, string $targetDir, bool $scanPsrPackages = false, string $suffix = '')
{
Expand Down Expand Up @@ -1240,6 +1241,9 @@ function ($matches) use (&$updir): string {
}

$resolvedPath = realpath($installPath . '/' . $updir);
if (false === $resolvedPath) {
continue;
}
$autoloads[] = preg_quote(strtr($resolvedPath, '\\', '/')) . '/' . $path . '($|/)';
continue;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Composer/Command/SelfUpdateCommand.php
Expand Up @@ -59,6 +59,7 @@ protected function configure(): void
new InputOption('snapshot', null, InputOption::VALUE_NONE, 'Force an update to the snapshot channel'),
new InputOption('1', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 1.x versions'),
new InputOption('2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.x versions'),
new InputOption('2.2', null, InputOption::VALUE_NONE, 'Force an update to the stable channel, but only use 2.2.x LTS versions'),
new InputOption('set-channel-only', null, InputOption::VALUE_NONE, 'Only store the channel as the default one and then exit'),
))
->setHelp(
Expand Down Expand Up @@ -181,8 +182,12 @@ class_exists('Composer\Downloader\FilesystemException');
}
}

if ($requestedChannel && is_numeric($requestedChannel) && strpos($latestStable['version'], $requestedChannel) !== 0) {
$io->writeError('<warning>Warning: You forced the install of '.$latestVersion.' via --'.$requestedChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
$effectiveChannel = $requestedChannel === null ? $versionsUtil->getChannel() : $requestedChannel;
if (is_numeric($effectiveChannel) && strpos($latestStable['version'], $effectiveChannel) !== 0) {
$io->writeError('<warning>Warning: You forced the install of '.$latestVersion.' via --'.$effectiveChannel.', but '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
}
if (isset($latest['eol'])) {
$io->writeError('<warning>Warning: Version '.$latestVersion.' is EOL / End of Life. '.$latestStable['version'].' is the latest stable version. Updating to it via composer self-update --stable is recommended.</warning>');
}

if (Preg::isMatch('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
Expand Down
18 changes: 10 additions & 8 deletions src/Composer/SelfUpdate/Versions.php
Expand Up @@ -12,6 +12,7 @@

namespace Composer\SelfUpdate;

use Composer\Pcre\Preg;
use Composer\Util\HttpDownloader;
use Composer\Config;

Expand All @@ -21,16 +22,16 @@
class Versions
{
/** @var string[] */
public static $channels = array('stable', 'preview', 'snapshot', '1', '2');
public static $channels = array('stable', 'preview', 'snapshot', '1', '2', '2.2');

/** @var HttpDownloader */
private $httpDownloader;
/** @var Config */
private $config;
/** @var string */
private $channel;
/** @var array<string, array<int, array{path: string, version: string, min-php: int}>> */
private $versionsData;
/** @var array<string, array<int, array{path: string, version: string, min-php: int, eol?: true}>>|null */
private $versionsData = null;

public function __construct(Config $config, HttpDownloader $httpDownloader)
{
Expand All @@ -50,7 +51,7 @@ public function getChannel(): string
$channelFile = $this->config->get('home').'/update-channel';
if (file_exists($channelFile)) {
$channel = trim(file_get_contents($channelFile));
if (in_array($channel, array('stable', 'preview', 'snapshot'), true)) {
if (in_array($channel, array('stable', 'preview', 'snapshot', '2.2'), true)) {
return $this->channel = $channel;
}
}
Expand All @@ -71,13 +72,14 @@ public function setChannel(string $channel): void

$channelFile = $this->config->get('home').'/update-channel';
$this->channel = $channel;
file_put_contents($channelFile, (is_numeric($channel) ? 'stable' : $channel).PHP_EOL);
// rewrite '2' and '1' channels to stable for future self-updates, but LTS ones like '2.2' remain pinned
file_put_contents($channelFile, (Preg::isMatch('{^\d+$}D', $channel) ? 'stable' : $channel).PHP_EOL);
}

/**
* @param string|null $channel
*
* @return array{path: string, version: string, min-php: int}
* @return array{path: string, version: string, min-php: int, eol?: true}
*/
public function getLatest(?string $channel = null): array
{
Expand All @@ -93,11 +95,11 @@ public function getLatest(?string $channel = null): array
}

/**
* @return array<string, array<int, array{path: string, version: string, min-php: int}>>
* @return array<string, array<int, array{path: string, version: string, min-php: int, eol?: true}>>
*/
private function getVersionsData(): array
{
if (!$this->versionsData) {
if (null === $this->versionsData) {
if ($this->config->get('disable-tls') === true) {
$protocol = 'http';
} else {
Expand Down
101 changes: 90 additions & 11 deletions tests/Composer/Test/Autoload/AutoloadGeneratorTest.php
Expand Up @@ -14,6 +14,7 @@

use Composer\Autoload\AutoloadGenerator;
use Composer\Filter\PlatformRequirementFilter\PlatformRequirementFilterFactory;
use Composer\Package\CompletePackage;
use Composer\Package\Link;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\Constraint;
Expand Down Expand Up @@ -772,8 +773,8 @@ public function testClassMapAutoloadingEmptyDirAndExactFile(): void
include $this->vendorDir.'/composer/autoload_classmap.php'
);
$this->assertAutoloadFiles('classmap5', $this->vendorDir.'/composer', 'classmap');
$this->assertStringNotContainsString('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringNotContainsString('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringNotContainsString('$loader->setClassMapAuthoritative(true);', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringNotContainsString('$loader->setApcuPrefix(', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
}

public function testClassMapAutoloadingAuthoritativeAndApcu(): void
Expand Down Expand Up @@ -821,8 +822,8 @@ public function testClassMapAutoloadingAuthoritativeAndApcu(): void
);
$this->assertAutoloadFiles('classmap8', $this->vendorDir.'/composer', 'classmap');

$this->assertStringContainsString('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setApcuPrefix(', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setClassMapAuthoritative(true);', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setApcuPrefix(', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
}

public function testClassMapAutoloadingAuthoritativeAndApcuPrefix(): void
Expand Down Expand Up @@ -870,8 +871,8 @@ public function testClassMapAutoloadingAuthoritativeAndApcuPrefix(): void
);
$this->assertAutoloadFiles('classmap8', $this->vendorDir.'/composer', 'classmap');

$this->assertStringContainsString('$loader->setClassMapAuthoritative(true);', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setApcuPrefix(\'custom\\\'Prefix\');', file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setClassMapAuthoritative(true);', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString('$loader->setApcuPrefix(\'custom\\\'Prefix\');', (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
}

public function testFilesAutoloadGeneration(): void
Expand Down Expand Up @@ -1433,8 +1434,8 @@ public function testVendorDirExcludedFromWorkingDir(): void
$this->assertStringEqualsFile($vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
$this->assertStringEqualsFile($vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
$this->assertStringEqualsFile($vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
$this->assertStringContainsString("\$vendorDir . '/b/b/bootstrap.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
$this->assertStringContainsString("\$baseDir . '/test.php',\n", file_get_contents($vendorDir.'/composer/autoload_files.php'));
$this->assertStringContainsString("\$vendorDir . '/b/b/bootstrap.php',\n", (string) file_get_contents($vendorDir.'/composer/autoload_files.php'));
$this->assertStringContainsString("\$baseDir . '/test.php',\n", (string) file_get_contents($vendorDir.'/composer/autoload_files.php'));
}

public function testUpLevelRelativePaths(): void
Expand Down Expand Up @@ -1518,7 +1519,85 @@ public function testUpLevelRelativePaths(): void
$this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);
$this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);
$this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_classmap.php', $expectedClassmap);
$this->assertStringContainsString("\$baseDir . '/../test.php',\n", file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
$this->assertStringContainsString("\$baseDir . '/../test.php',\n", (string) file_get_contents($this->vendorDir.'/composer/autoload_files.php'));
}

public function testAutoloadRulesInPackageThatDoesNotExistOnDisk(): void
{
$package = new RootPackage('root/a', '1.0', '1.0');
$package->setRequires(array(
'dep/a' => new Link('root/a', 'dep/a', new MatchAllConstraint(), 'requires'),
));
$dep = new CompletePackage('dep/a', '1.0', '1.0');

$this->repository->expects($this->any())
->method('getCanonicalPackages')
->will($this->returnValue(array($dep)));

$dep->setAutoload(array(
'psr-0' => array('Foo' => './src'),
));
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_19');

$expectedNamespace = <<<'EOF'
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Foo' => array($vendorDir . '/dep/a/src'),
);
EOF;
$this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_namespaces.php', $expectedNamespace);

$dep->setAutoload(array(
'psr-4' => array('Acme\Foo\\' => './src-psr4'),
));
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_19');

$expectedPsr4 = <<<'EOF'
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(__DIR__);
$baseDir = dirname($vendorDir);
return array(
'Acme\\Foo\\' => array($vendorDir . '/dep/a/src-psr4'),
);
EOF;
$this->assertStringEqualsFile($this->vendorDir.'/composer/autoload_psr4.php', $expectedPsr4);

$dep->setAutoload(array(
'classmap' => array('classmap'),
));
try {
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_19');
} catch (\RuntimeException $e) {
$this->assertSame('Could not scan for classes inside "'.$this->vendorDir.'/dep/a/classmap" which does not appear to be a file nor a folder', $e->getMessage());
}

$dep->setAutoload(array(
'files' => array('./test.php'),
));
$this->generator->dump($this->config, $this->repository, $package, $this->im, 'composer', true, '_19');
$this->assertStringContainsString("\$vendorDir . '/dep/a/test.php',\n", (string) file_get_contents($this->vendorDir.'/composer/autoload_files.php'));

$package->setAutoload(array(
'exclude-from-classmap' => array('../excludedroot', 'root/excl'),
));
$dep->setAutoload(array(
'exclude-from-classmap' => array('../../excluded', 'foo/bar'),
));
$map = $this->generator->buildPackageMap($this->im, $package, array($dep));
$parsed = $this->generator->parseAutoloads($map, $package);
$this->assertSame(array(preg_quote(dirname($this->workingDir)).'/excludedroot($|/)', preg_quote($this->workingDir).'/root/excl($|/)'), $parsed['exclude-from-classmap']);
}

public function testEmptyPaths(): void
Expand Down Expand Up @@ -1736,10 +1815,10 @@ public function testGeneratesPlatformCheck(array $requires, ?string $expectedFix

if (null === $expectedFixture) {
$this->assertFalse(file_exists($this->vendorDir . '/composer/platform_check.php'));
$this->assertStringNotContainsString("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringNotContainsString("require __DIR__ . '/platform_check.php';", (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
} else {
$this->assertFileContentEquals(__DIR__ . '/Fixtures/platform/' . $expectedFixture . '.php', $this->vendorDir . '/composer/platform_check.php');
$this->assertStringContainsString("require __DIR__ . '/platform_check.php';", file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
$this->assertStringContainsString("require __DIR__ . '/platform_check.php';", (string) file_get_contents($this->vendorDir.'/composer/autoload_real.php'));
}
}

Expand Down

0 comments on commit dce63fd

Please sign in to comment.