Issue #3080649 by greg.1.anderson, larowlan, BinaryBlock, alexpott, danielnv18, Mile23: Drupal core scaffolding : path to vendor directory in generated autoload.php file is incorrect
parent
73972cc6a1
commit
a68ff42323
|
|
@ -38,12 +38,11 @@ final class GenerateAutoloadReferenceFile {
|
||||||
*/
|
*/
|
||||||
public static function generateAutoload(IOInterface $io, $package_name, $web_root, $vendor) {
|
public static function generateAutoload(IOInterface $io, $package_name, $web_root, $vendor) {
|
||||||
$autoload_path = static::autoloadPath($package_name, $web_root);
|
$autoload_path = static::autoloadPath($package_name, $web_root);
|
||||||
$location = dirname($autoload_path->fullPath());
|
|
||||||
// Calculate the relative path from the webroot (location of the project
|
// Calculate the relative path from the webroot (location of the project
|
||||||
// autoload.php) to the vendor directory.
|
// autoload.php) to the vendor directory.
|
||||||
$fs = new Filesystem();
|
$fs = new Filesystem();
|
||||||
$relative_vendor_path = $fs->findShortestPath(realpath($location), $vendor);
|
$relative_autoload_path = $fs->findShortestPath($autoload_path->fullPath(), "$vendor/autoload.php");
|
||||||
file_put_contents($autoload_path->fullPath(), static::autoLoadContents($relative_vendor_path));
|
file_put_contents($autoload_path->fullPath(), static::autoLoadContents($relative_autoload_path));
|
||||||
return new ScaffoldResult($autoload_path, TRUE);
|
return new ScaffoldResult($autoload_path, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -91,14 +90,14 @@ final class GenerateAutoloadReferenceFile {
|
||||||
/**
|
/**
|
||||||
* Builds the contents of the autoload file.
|
* Builds the contents of the autoload file.
|
||||||
*
|
*
|
||||||
* @param string $vendor_path
|
* @param string $relative_autoload_path
|
||||||
* The relative path to vendor.
|
* The relative path to the autoloader in vendor.
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
* Return the contents for the autoload.php.
|
* Return the contents for the autoload.php.
|
||||||
*/
|
*/
|
||||||
protected static function autoLoadContents($vendor_path) {
|
protected static function autoLoadContents($relative_autoload_path) {
|
||||||
$vendor_path = rtrim($vendor_path, '/');
|
$relative_autoload_path = preg_replace('#^\./#', '', $relative_autoload_path);
|
||||||
return <<<EOF
|
return <<<EOF
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
@ -115,7 +114,7 @@ final class GenerateAutoloadReferenceFile {
|
||||||
* @see core/modules/statistics/statistics.php
|
* @see core/modules/statistics/statistics.php
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return require __DIR__ . '/{$vendor_path}/autoload.php';
|
return require __DIR__ . '/{$relative_autoload_path}';
|
||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Drupal\Composer\Plugin\Scaffold;
|
namespace Drupal\Composer\Plugin\Scaffold;
|
||||||
|
|
||||||
|
use Composer\Util\Filesystem;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage the path to a file to scaffold.
|
* Manage the path to a file to scaffold.
|
||||||
*
|
*
|
||||||
|
|
@ -61,6 +63,14 @@ class ScaffoldFilePath {
|
||||||
$this->packageName = $package_name;
|
$this->packageName = $package_name;
|
||||||
$this->relativePath = $rel_path;
|
$this->relativePath = $rel_path;
|
||||||
$this->fullPath = $full_path;
|
$this->fullPath = $full_path;
|
||||||
|
|
||||||
|
// Ensure that the full path really is a full path. We do not use
|
||||||
|
// 'realpath' here because the file specified by the full path might
|
||||||
|
// not exist yet.
|
||||||
|
$fs = new Filesystem();
|
||||||
|
if (!$fs->isAbsolutePath($this->fullPath)) {
|
||||||
|
$this->fullPath = getcwd() . '/' . $this->fullPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -194,6 +194,7 @@ class ScaffoldTest extends TestCase {
|
||||||
$result = $this->scaffoldSut($fixture_name, FALSE, FALSE);
|
$result = $this->scaffoldSut($fixture_name, FALSE, FALSE);
|
||||||
$this->assertContains('The allowed package fixtures/empty-fixture does not provide a file mapping for Composer Scaffold', $result->scaffoldOutput());
|
$this->assertContains('The allowed package fixtures/empty-fixture does not provide a file mapping for Composer Scaffold', $result->scaffoldOutput());
|
||||||
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), FALSE);
|
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), FALSE);
|
||||||
|
$this->assertAutoloadFileCorrect($result->docroot());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scaffoldOverridingSettingsExcludingHtaccessValues() {
|
public function scaffoldOverridingSettingsExcludingHtaccessValues() {
|
||||||
|
|
@ -229,6 +230,7 @@ class ScaffoldTest extends TestCase {
|
||||||
$result = $this->scaffoldSut($fixture_name, $is_link, $relocated_docroot);
|
$result = $this->scaffoldSut($fixture_name, $is_link, $relocated_docroot);
|
||||||
|
|
||||||
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), $is_link);
|
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), $is_link);
|
||||||
|
$this->assertAutoloadFileCorrect($result->docroot(), $relocated_docroot);
|
||||||
$this->assertDefaultSettingsFromScaffoldOverride($result->docroot(), $is_link);
|
$this->assertDefaultSettingsFromScaffoldOverride($result->docroot(), $is_link);
|
||||||
$this->assertHtaccessExcluded($result->docroot());
|
$this->assertHtaccessExcluded($result->docroot());
|
||||||
}
|
}
|
||||||
|
|
@ -248,6 +250,7 @@ class ScaffoldTest extends TestCase {
|
||||||
$this->assertScaffoldedFile($result->docroot() . '/keep-me.txt', FALSE, 'File in drupal-drupal-test-overwrite that is not replaced');
|
$this->assertScaffoldedFile($result->docroot() . '/keep-me.txt', FALSE, 'File in drupal-drupal-test-overwrite that is not replaced');
|
||||||
$this->assertScaffoldedFile($result->docroot() . '/make-me.txt', FALSE, 'from assets that replaces file');
|
$this->assertScaffoldedFile($result->docroot() . '/make-me.txt', FALSE, 'from assets that replaces file');
|
||||||
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), FALSE);
|
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), FALSE);
|
||||||
|
$this->assertAutoloadFileCorrect($result->docroot());
|
||||||
$this->assertScaffoldedFile($result->docroot() . '/robots.txt', FALSE, $fixture_name);
|
$this->assertScaffoldedFile($result->docroot() . '/robots.txt', FALSE, $fixture_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,6 +325,7 @@ class ScaffoldTest extends TestCase {
|
||||||
|
|
||||||
$this->assertScaffoldedFile($result->docroot() . '/robots.txt', FALSE, $robots_txt_contents);
|
$this->assertScaffoldedFile($result->docroot() . '/robots.txt', FALSE, $robots_txt_contents);
|
||||||
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), $is_link);
|
$this->assertCommonDrupalAssetsWereScaffolded($result->docroot(), $is_link);
|
||||||
|
$this->assertAutoloadFileCorrect($result->docroot());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -361,9 +365,7 @@ class ScaffoldTest extends TestCase {
|
||||||
* Whether or not symlinking is used.
|
* Whether or not symlinking is used.
|
||||||
*/
|
*/
|
||||||
protected function assertCommonDrupalAssetsWereScaffolded($docroot, $is_link) {
|
protected function assertCommonDrupalAssetsWereScaffolded($docroot, $is_link) {
|
||||||
// Ensure that the autoload.php file was written.
|
// Assert scaffold files are written in the correct locations.
|
||||||
$this->assertFileExists($docroot . '/autoload.php');
|
|
||||||
// Assert other scaffold files are written in the correct locations.
|
|
||||||
$this->assertScaffoldedFile($docroot . '/.csslintrc', $is_link, 'Test version of .csslintrc from drupal/core.');
|
$this->assertScaffoldedFile($docroot . '/.csslintrc', $is_link, 'Test version of .csslintrc from drupal/core.');
|
||||||
$this->assertScaffoldedFile($docroot . '/.editorconfig', $is_link, 'Test version of .editorconfig from drupal/core.');
|
$this->assertScaffoldedFile($docroot . '/.editorconfig', $is_link, 'Test version of .editorconfig from drupal/core.');
|
||||||
$this->assertScaffoldedFile($docroot . '/.eslintignore', $is_link, 'Test version of .eslintignore from drupal/core.');
|
$this->assertScaffoldedFile($docroot . '/.eslintignore', $is_link, 'Test version of .eslintignore from drupal/core.');
|
||||||
|
|
@ -378,4 +380,27 @@ class ScaffoldTest extends TestCase {
|
||||||
$this->assertScaffoldedFile($docroot . '/web.config', $is_link, 'Test version of web.config from drupal/core.');
|
$this->assertScaffoldedFile($docroot . '/web.config', $is_link, 'Test version of web.config from drupal/core.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assert that the autoload file was scaffolded and contains correct path.
|
||||||
|
*
|
||||||
|
* @param string $docroot
|
||||||
|
* Location of the doc root, where autoload.php should be written.
|
||||||
|
* @param bool $relocated_docroot
|
||||||
|
* Whether the document root is relocated or now.
|
||||||
|
*/
|
||||||
|
protected function assertAutoloadFileCorrect($docroot, $relocated_docroot = FALSE) {
|
||||||
|
$autoload_path = $docroot . '/autoload.php';
|
||||||
|
|
||||||
|
// Ensure that the autoload.php file was written.
|
||||||
|
$this->assertFileExists($autoload_path);
|
||||||
|
$contents = file_get_contents($autoload_path);
|
||||||
|
|
||||||
|
$expected = "return require __DIR__ . '/vendor/autoload.php';";
|
||||||
|
if ($relocated_docroot) {
|
||||||
|
$expected = "return require __DIR__ . '/../vendor/autoload.php';";
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertContains($expected, $contents);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue