Skip to content

Commit

Permalink
merge in fixes from release/3
Browse files Browse the repository at this point in the history
  • Loading branch information
allanpaiste committed Feb 24, 2021
2 parents 578d4f7 + 7cb3b4d commit a5a9ffa
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 34 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

_This file has been auto-generated from the contents of changelog.json_

## 4.22.2

changes in this release forward-ported from 3.53.2

### Fix

* patches applied before packages properly re-installed with Composer V2 (missed the fact that installations, like downloads are now done in asynchronous manner) [issues/70]

Links: [src](https://github.com/vaimo/composer-patches/tree/4.22.2) [diff](https://github.com/vaimo/composer-patches/compare/4.22.1...4.22.2)

## 4.22.1 (2021-02-20)

changes in this release forward-ported from 3.53.1
Expand Down Expand Up @@ -736,7 +746,15 @@ Links: [src](https://github.com/vaimo/composer-patches/tree/4.1.0) [diff](https:
* allow patch failures to be passed over gracefully with COMPOSER_PATCHES_GRACEFUL flag
* allow patch failures to be passed over gracefully with extra/patcher/graceful configuration in root package

Links: [src](https://github.com/vaimo/composer-patches/tree/4.0.0) [diff](https://github.com/vaimo/composer-patches/compare/3.53.1...4.0.0)
Links: [src](https://github.com/vaimo/composer-patches/tree/4.0.0) [diff](https://github.com/vaimo/composer-patches/compare/3.53.2...4.0.0)

## 3.53.2 (2021-02-24)

### Fix

* patches applied before packages properly re-installed with Composer V2 (missed the fact that installations, like downloads are now done in asynchronous manner) [issues/70]

Links: [src](https://github.com/vaimo/composer-patches/tree/3.53.2) [diff](https://github.com/vaimo/composer-patches/compare/3.53.1...3.53.2)

## 3.53.1 (2021-02-20)

Expand Down
32 changes: 25 additions & 7 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -398,15 +398,25 @@ assert() {
local name=$(echo ${assertion}|cut -d',' -f1)
local before=$(echo ${assertion}|cut -d',' -f2)
local after=$(echo ${assertion}|cut -d',' -f3)
local target=$(echo ${assertion}|cut -d',' -f4)

local contents=$(cat vendor/${name}/src/example.txt)
if [ "${target}" = "" ] ; then
target="src/example.txt"
fi

local file_path="vendor/${name}/${target}"
local contents=$(cat ${file_path})

if [ "${invert}" != "" ] && [ "${invert}" != "0" ] ; then
local tmp=${before}
before=${after}
after=${tmp}
fi

if echo "${contents}"|grep -qw "${after}" && [ "${before}" == "" ] ; then
return 0
fi

if echo "${contents}"|grep -qw "^${before}" && [ "${before}" == "${after}" ] ; then
return 0
fi
Expand All @@ -427,29 +437,36 @@ assertion_error() {
local name=$(echo ${assertion}|cut -d',' -f1)
local before=$(echo ${assertion}|cut -d',' -f2)
local after=$(echo ${assertion}|cut -d',' -f3)
local target=$(echo ${assertion}|cut -d',' -f4)

local file=vendor/${name}/src/example.txt
if [ "${target}" = "" ] ; then
target="src/example.txt"
fi

local contents=$(cat ${file})
local file_path="vendor/${name}/${target}"
local contents=$(cat ${file_path})

if [ "${invert}" != "" ] && [ "${invert}" != "0" ] ; then
local tmp=${before}
before=${after}
after=${tmp}
fi

_error "TARGET: ${file}"
_error "TARGET: ${file_path}"
_error "ASSERTION: ${before} => ${after}"
}

reset_packages() {
local installation_root=${1}
local scenarios_root=${1}
local installation_root=${2}

local install_info_path="${installation_root}/vendor/composer/installed.json"

local lock_path="${installation_root}/composer.lock"

if [ -f ${install_info_path} ] ; then
perl -i.org -pe 's|(\s"name":\s")(vaimo/composer-patches-target)(.*)",|\1__\2\3",|g' \
filters=$(grep -r "@package" ${scenarios_root}|sed 's/.*@package\(.*\)/\1/g'|sort|uniq|tr '\n' '|'|tr -d ' '|tr -d '\r')
perl -i.org -pe "s%(\s\"name\":\s\")(${filters}|vaimo/composer-patches-target)(.*)\",%\1__\2\3\",%g" \
${install_info_path}

rm ${install_info_path}.org
Expand Down Expand Up @@ -527,6 +544,7 @@ fi
sandbox_root=$(pwd)

installations=$(ls -1 installations)
scenarios_root=$(pwd)/scenarios
scenarios=$(ls -1 scenarios)

if [ "${PURGE}" == "1" ] ; then
Expand Down Expand Up @@ -585,7 +603,7 @@ fi
continue
fi

reset_packages "${installation_root}"
reset_packages "${scenarios_root}" "${installation_root}"
scenario_root=${sandbox_root}/scenarios/${scenario}

if ! run_tests "${scenario_root}" "${copy_target}" ; then
Expand Down
12 changes: 12 additions & 0 deletions changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"possible to generate change-logs in other formats as well (when needed) and to do automatic releases based on",
"added change-log records. More on how to use it: https://github.com/vaimo/composer-changelogs"
],
"4.22.2": {
"overview": "changes in this release forward-ported from 3.53.2",
"fix": [
"patches applied before packages properly re-installed with Composer V2 (missed the fact that installations, like downloads are now done in asynchronous manner) [issues/70]"
]
},
"4.22.1": {
"overview": "changes in this release forward-ported from 3.53.1",
"fix": [
Expand Down Expand Up @@ -486,6 +492,12 @@
"allow patch failures to be passed over gracefully with extra/patcher/graceful configuration in root package"
]
},
"3.53.2": {
"fix": [
"patches applied before packages properly re-installed with Composer V2 (missed the fact that installations, like downloads are now done in asynchronous manner) [issues/70]"
],
"branch": "release/3"
},
"3.53.1": {
"fix": [
"minor issue addressed with V2-style call being in code without version-check (said call is currently backwards-compatible with V1, but you never know ...)"
Expand Down
9 changes: 4 additions & 5 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,12 @@ System requirements:

Setup:

4. `git checkout devbox .devcontainer Dockerfile docker-compose.yml mutagen.yml bin/phpcs bin/phpcbf`
5. `git reset .devcontainer Dockerfile docker-compose.yml mutagen.yml bin/phpcs bin/phpcbf`
4. `git checkout devbox .devcontainer Dockerfile docker-compose.yml mutagen.yml`
5. `git reset .devcontainer Dockerfile docker-compose.yml mutagen.yml`
6. [open the project with VSCode that has Remote Container extension installed]
7. [use the 'Reopen in Container' option that is given in a prompt that opens]
8. (only on Windows) `mutagen project start`
9. Use 'Terminal > New Terminal' to open a terminal within the IDE.
10. [from the terminal you can install the packages, trigger debugger, etc]
8. `mutagen project start`
9. `docker-compose exec devbox composer install`

Note this setup does come with a pre-bootstrapped xDebugger, you just have to use the Run menu
in VSCode and start listening and trigger a command via the terminal.
33 changes: 32 additions & 1 deletion src/Compatibility/Executor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
namespace Vaimo\ComposerPatches\Compatibility;

use Vaimo\ComposerPatches\Patch\Definition as PatchDefinition;
use Composer\Repository\WritableRepositoryInterface;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\Installer\InstallationManager;

class Executor
{
Expand Down Expand Up @@ -50,12 +53,40 @@ public function assignTmpPathForPatchData(&$patchData, $path)
}
}

public function waitDownloadCompletion($composer)
public function waitDownloadCompletion(\Composer\Composer $composer)
{
if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
return;
}

$composer->getLoop()->getHttpDownloader()->wait();
}

public function waitForCompletion(\Composer\Composer $composer, array $processes)
{
if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
return;
}

$composer->getLoop()->wait($processes);
}

public function processReinstallOperation(
WritableRepositoryInterface $repository,
InstallationManager $installationManager,
InstallOperation $operation
) {
if (version_compare(\Composer\Composer::VERSION, '2.0', '<')) {
return $installationManager->install($repository, $operation);
}

$package = $operation->getPackage();
$installer = $installationManager->getInstaller($package->getType());

return $installer
->download($package)
->then(function () use ($installationManager, $operation, $repository) {
$installationManager->install($repository, $operation);
});
}
}
1 change: 1 addition & 0 deletions src/Factories/PatchesApplierFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public function create(PluginConfig $pluginConfig, ListResolver $listResolver, O
);

return new \Vaimo\ComposerPatches\Repository\PatchesApplier(
$this->composer,
$packageCollector,
$repositoryManager,
$packagePatchApplier,
Expand Down
16 changes: 11 additions & 5 deletions src/Managers/RepositoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class RepositoryManager
*/
private $consoleSilencer;

/**
* @var \Vaimo\ComposerPatches\Compatibility\Executor
*/
private $compExecutor;

/**
* @param \Composer\Installer\InstallationManager $installationManager
* @param \Vaimo\ComposerPatches\Interfaces\PackageResetStrategyInterface $packageResetStrategy
Expand All @@ -40,6 +45,7 @@ public function __construct(
$this->installationManager = $installationManager;
$this->packageResetStrategy = $packageResetStrategy;
$this->consoleSilencer = $consoleSilencer;
$this->compExecutor = new \Vaimo\ComposerPatches\Compatibility\Executor();
}

/**
Expand All @@ -59,11 +65,11 @@ public function resetPackage(WritableRepositoryInterface $repository, PackageInt
);
}

$installer = $this->installationManager;

$this->consoleSilencer->applyToCallback(
function () use ($installer, $repository, $operation) {
$installer->install($repository, $operation);
$compExecutor = $this->compExecutor;
$installationManager = $this->installationManager;
return $this->consoleSilencer->applyToCallback(
function () use ($compExecutor, $installationManager, $repository, $operation) {
return $compExecutor->processReinstallOperation($repository, $installationManager, $operation);
}
);
}
Expand Down
29 changes: 15 additions & 14 deletions src/Repository/PatchesApplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
*/
class PatchesApplier
{
/**
* @var \Composer\Composer
*/
private $composer;

/**
* @var \Vaimo\ComposerPatches\Package\Collector
*/
Expand Down Expand Up @@ -91,16 +97,12 @@ class PatchesApplier
private $outputGenerator;

/**
* @param \Vaimo\ComposerPatches\Package\Collector $packageCollector
* @param \Vaimo\ComposerPatches\Managers\RepositoryManager $repositoryManager
* @param \Vaimo\ComposerPatches\Package\PatchApplier $patchApplier
* @param \Vaimo\ComposerPatches\Repository\PatchesApplier\QueueGenerator $queueGenerator
* @param \Vaimo\ComposerPatches\Managers\PatcherStateManager $patcherStateManager
* @param \Vaimo\ComposerPatches\Package\PatchApplier\InfoLogger $patchInfoLogger
* @param \Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy
* @param \Vaimo\ComposerPatches\Logger $logger
* @var \Vaimo\ComposerPatches\Compatibility\Executor
*/
private $compExecutor;

public function __construct(
\Composer\Composer $composer,
\Vaimo\ComposerPatches\Package\Collector $packageCollector,
\Vaimo\ComposerPatches\Managers\RepositoryManager $repositoryManager,
\Vaimo\ComposerPatches\Package\PatchApplier $patchApplier,
Expand All @@ -110,6 +112,7 @@ public function __construct(
\Vaimo\ComposerPatches\Strategies\OutputStrategy $outputStrategy,
\Vaimo\ComposerPatches\Logger $logger
) {
$this->composer = $composer;
$this->packageCollector = $packageCollector;
$this->repositoryManager = $repositoryManager;
$this->packagePatchApplier = $patchApplier;
Expand All @@ -130,6 +133,7 @@ public function __construct(
$this->statusConfig = new \Vaimo\ComposerPatches\Package\PatchApplier\StatusConfig();
$this->packageUtils = new \Vaimo\ComposerPatches\Utils\PackageUtils();
$this->dataUtils = new \Vaimo\ComposerPatches\Utils\DataUtils();
$this->compExecutor = new \Vaimo\ComposerPatches\Compatibility\Executor();
}

/**
Expand All @@ -147,17 +151,12 @@ public function __construct(
public function apply(Repository $repository, array $patches)
{
$packages = $this->packageCollector->collect($repository);

$packagesUpdated = false;

$repositoryState = $this->repoStateGenerator->generate($repository);

$applyQueue = $this->queueGenerator->generateApplyQueue($patches, $repositoryState);
$removeQueue = $this->queueGenerator->generateRemovalQueue($applyQueue, $repositoryState);
$resetQueue = $this->queueGenerator->generateResetQueue($applyQueue);

$applyQueue = array_map('array_filter', $applyQueue);

$patchQueueFootprints = $this->patchListTransformer->createSimplifiedList($applyQueue);

$labels = array_diff_key(
Expand All @@ -178,6 +177,7 @@ public function apply(Repository $repository, array $patches)
$itemsToReset = $this->dataUtils->extractItems($resetQueue, $patchTargets);

$resetResult = array();
$resets = array();

foreach ($itemsToReset as $targetName) {
$resetTarget = $packages[$targetName];
Expand All @@ -195,9 +195,10 @@ public function apply(Repository $repository, array $patches)
);
}

$this->repositoryManager->resetPackage($repository, $resetTarget);
$resets[] = $this->repositoryManager->resetPackage($repository, $resetTarget);
}

$this->compExecutor->waitForCompletion($this->composer, $resets);
$packagesUpdated = $packagesUpdated || (bool)array_filter($resetResult);

if (!$hasPatches) {
Expand Down
3 changes: 2 additions & 1 deletion test/installations/package-using-file/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"vaimo/patches-file-owner": "1.0.0",
"vaimo/composer-patches-target1": "1.0.0",
"vaimo/composer-patches-target2": "1.2.0",
"vaimo/composer-patches-target3": "1.2.3"
"vaimo/composer-patches-target3": "1.2.3",
"vaimo/topological-sort": "^1.0"
},
"repositories": [
{
Expand Down
3 changes: 3 additions & 0 deletions test/scenarios/apply-real-package-success/.commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
patch:validate

patch:apply
1 change: 1 addition & 0 deletions test/scenarios/apply-real-package-success/.label
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
real (downloaded from packagist) package installed
8 changes: 8 additions & 0 deletions test/scenarios/apply-real-package-success/.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Scanning packages for orphan patches
Validation completed successfully
Processing patches configuration
- Applying patches for vaimo/topological-sort (1)
~ {{PATCHES-OWNER}}: patches/first-change.patch [NEW]
Change: Dependency => The cool thing

Writing patch info to install file
5 changes: 5 additions & 0 deletions test/scenarios/apply-real-package-success/files/patches.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"vaimo/topological-sort": {
"Change: Dependency => The cool thing": "patches/first-change.patch"
}
}
Loading

0 comments on commit a5a9ffa

Please sign in to comment.