Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #547 from cweagans/dependency-patches
Dependency patch resolution
- Loading branch information
Showing
23 changed files
with
271 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains \cweagans\Composer\Resolvers\Dependencies. | ||
*/ | ||
|
||
namespace cweagans\Composer\Resolver; | ||
|
||
use cweagans\Composer\Patch; | ||
use cweagans\Composer\PatchCollection; | ||
|
||
class Dependencies extends ResolverBase | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function resolve(PatchCollection $collection): void | ||
{ | ||
$locker = $this->composer->getLocker(); | ||
if (!$locker->isLocked()) { | ||
$this->io->write(' - <info>Composer lock file does not exist.</info>'); | ||
$this->io->write(' - <info>Patches defined in dependencies will not be resolved.</info>'); | ||
return; | ||
} | ||
|
||
$this->io->write(' - <info>Resolving patches from dependencies.</info>'); | ||
|
||
$ignored_dependencies = $this->plugin->getConfig('ignore-dependency-patches'); | ||
|
||
$lockdata = $locker->getLockData(); | ||
foreach ($lockdata['packages'] as $p) { | ||
// If we're supposed to skip gathering patches from a dependency, do that. | ||
if (in_array($p['name'], $ignored_dependencies)) { | ||
continue; | ||
} | ||
|
||
// Find patches in the composer.json for dependencies. | ||
if (!isset($p['extra']) || !isset($p['extra']['patches'])) { | ||
continue; | ||
} | ||
foreach ($this->findPatchesInJson($p['extra']['patches']) as $package => $patches) { | ||
foreach ($patches as $patch) { | ||
$patch->extra['provenance'] = "dependency:" . $package; | ||
|
||
/** @var Patch $patch */ | ||
$collection->addPatch($patch); | ||
} | ||
} | ||
|
||
// TODO: Also find patches in a configured patches.json for the dependency. | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
{ | ||
"name": "cweagans/dep-test-package", | ||
"description": "Project for use in cweagans/composer-patches acceptance tests.", | ||
"type": "project", | ||
"license": "BSD-2-Clause", | ||
"require": { | ||
"drupal/drupal": "8.2.0" | ||
}, | ||
"extra": { | ||
"patches": { | ||
"drupal/drupal": { | ||
"Add a startup config for the PHP web server": "https://www.drupal.org/files/issues/add_a_startup-1543858-58.patch" | ||
} | ||
} | ||
"name": "cweagans/dep-test-package", | ||
"description": "Project for use in cweagans/composer-patches acceptance tests.", | ||
"type": "project", | ||
"license": "BSD-3-Clause", | ||
"extra": { | ||
"patches": { | ||
"cweagans/composer-patches-testrepo": { | ||
"Add a file": "https://patch-diff.githubusercontent.com/raw/cweagans/composer-patches-testrepo/pull/1.patch" | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/_data/fixtures/dependency-patches-duplicate-patch/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "cweagans/composer-patches-test-project", | ||
"description": "Project for use in cweagans/composer-patches acceptance tests.", | ||
"type": "project", | ||
"license": "BSD-3-Clause", | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "../../../../" | ||
}, | ||
{ | ||
"type": "path", | ||
"url": "../../dep-test-package" | ||
} | ||
], | ||
"require": { | ||
"cweagans/composer-patches": "*@dev", | ||
"cweagans/composer-patches-testrepo": "~1.0", | ||
"cweagans/dep-test-package": "*@dev" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"cweagans/composer-patches": true | ||
} | ||
}, | ||
"extra": { | ||
"patches": { | ||
"cweagans/composer-patches-testrepo": { | ||
"Add a file": "https://patch-diff.githubusercontent.com/raw/cweagans/composer-patches-testrepo/pull/1.patch" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "cweagans/composer-patches-test-project", | ||
"description": "Project for use in cweagans/composer-patches acceptance tests.", | ||
"type": "project", | ||
"license": "BSD-3-Clause", | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "../../../../" | ||
}, | ||
{ | ||
"type": "path", | ||
"url": "../../dep-test-package" | ||
} | ||
], | ||
"require": { | ||
"cweagans/composer-patches": "*@dev", | ||
"cweagans/composer-patches-testrepo": "~1.0", | ||
"cweagans/dep-test-package": "*@dev" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"cweagans/composer-patches": true | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/_data/fixtures/disable-dependency-patches/composer.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "cweagans/composer-patches-test-project", | ||
"description": "Project for use in cweagans/composer-patches acceptance tests.", | ||
"type": "project", | ||
"license": "BSD-3-Clause", | ||
"repositories": [ | ||
{ | ||
"type": "path", | ||
"url": "../../../../" | ||
}, | ||
{ | ||
"type": "path", | ||
"url": "../../dep-test-package" | ||
} | ||
], | ||
"require": { | ||
"cweagans/composer-patches": "*@dev", | ||
"cweagans/composer-patches-testrepo": "~1.0", | ||
"cweagans/dep-test-package": "*@dev" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"cweagans/composer-patches": true | ||
} | ||
}, | ||
"extra": { | ||
"composer-patches": { | ||
"disable-resolvers": [ | ||
"\\cweagans\\Composer\\Resolver\\Dependencies" | ||
] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.