Skip to content

Escape disabled modules in code compilation - setup:di:compile #39723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: 2.4-develop
Choose a base branch
from
65 changes: 38 additions & 27 deletions setup/src/Magento/Setup/Console/Command/DiCompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@

namespace Magento\Setup\Console\Command;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\Filesystem\Io\File;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Magento\Framework\Filesystem;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Interception\Cache\CompiledConfig;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ObjectManager\ConfigWriterInterface;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Framework\Console\Cli;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Framework\Filesystem\Io\File;
use Magento\Setup\Model\ObjectManagerProvider;
use Magento\Setup\Module\Di\App\Task\Manager;
use Magento\Setup\Module\Di\App\Task\OperationFactory;
use Magento\Setup\Module\Di\App\Task\OperationException;
use Magento\Setup\Module\Di\App\Task\OperationFactory;
use Magento\Setup\Module\Di\App\Task\OperationInterface;
use Magento\Setup\Module\Di\Code\Generator\PluginList;
use Magento\Setup\Module\Di\Code\Reader\ClassesScanner;
use Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim;
use Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution;
use Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving;
use Magento\Setup\Module\Di\Compiler\Config\ModificationChain;
use Magento\Setup\Module\Di\Compiler\Log\Writer\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Magento\Framework\Console\Cli;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Command to run compile in single-tenant mode
Expand Down Expand Up @@ -156,20 +165,26 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$modulePaths = $this->componentRegistrar->getPaths(ComponentRegistrar::MODULE);
$moduleStatuses = $this->deploymentConfig->get(ConfigOptionsListConstants::KEY_MODULES);

$modulePathsEnabled = array_filter($modulePaths, function ($path, $module) use ($moduleStatuses) {
return ($moduleStatuses[$module] ?? 0) === 1;
}, ARRAY_FILTER_USE_BOTH);

$libraryPaths = $this->componentRegistrar->getPaths(ComponentRegistrar::LIBRARY);
$setupPath = $this->directoryList->getPath(DirectoryList::SETUP);
$generationPath = $this->directoryList->getPath(DirectoryList::GENERATED_CODE);

$this->objectManager->get(\Magento\Framework\App\Cache::class)->clean();
$compiledPathsList = [
'application' => $modulePaths,
'application' => $modulePathsEnabled,
'library' => $libraryPaths,
'setup' => $setupPath,
'generated_helpers' => $generationPath
];

$this->excludedPathsList = [
'application' => $this->getExcludedModulePaths($modulePaths),
'application' => $this->getExcludedModulePaths($modulePathsEnabled),
'framework' => $this->getExcludedLibraryPaths($libraryPaths),
'setup' => $this->getExcludedSetupPaths($setupPath),
];
Expand Down Expand Up @@ -207,11 +222,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
$progressBar->display();

$this->taskManager->process(
function (OperationInterface $operation) use ($progressBar) {
function (OperationInterface $operation) use ($progressBar): void {
$progressBar->setMessage($operation->getName() . '...');
$progressBar->display();
},
function (OperationInterface $operation) use ($progressBar) {
function (OperationInterface $operation) use ($progressBar): void {
$progressBar->advance();
}
);
Expand Down Expand Up @@ -327,39 +342,35 @@ private function configureObjectManager(OutputInterface $output)
{
$this->objectManager->configure(
[
'preferences' => [\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class =>
\Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem::class,
], \Magento\Setup\Module\Di\Compiler\Config\ModificationChain::class => [
'preferences' => [ConfigWriterInterface::class => ObjectManager\ConfigWriter\Filesystem::class,
], ModificationChain::class => [
'arguments' => [
'modificationsList' => [
'BackslashTrim' => [
'instance' =>
\Magento\Setup\Module\Di\Compiler\Config\Chain\BackslashTrim::class
'instance' => BackslashTrim::class
],
'PreferencesResolving' => [
'instance' =>
\Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
'instance' => PreferencesResolving::class
],
'InterceptorSubstitution' => [
'instance' =>
\Magento\Setup\Module\Di\Compiler\Config\Chain\InterceptorSubstitution::class
'instance' => InterceptorSubstitution::class
],
'InterceptionPreferencesResolving' => [
'instance' => \Magento\Setup\Module\Di\Compiler\Config\Chain\PreferencesResolving::class
'instance' => PreferencesResolving::class
],
]
]
], \Magento\Setup\Module\Di\Code\Generator\PluginList::class => [
], PluginList::class => [
'arguments' => [
'cache' => [
'instance' => \Magento\Framework\App\Interception\Cache\CompiledConfig::class
'instance' => CompiledConfig::class
]
]
], \Magento\Setup\Module\Di\Code\Reader\ClassesScanner::class => [
], ClassesScanner::class => [
'arguments' => [
'excludePatterns' => $this->excludedPathsList
]
], \Magento\Setup\Module\Di\Compiler\Log\Writer\Console::class => [
], Console::class => [
'arguments' => [
'output' => $output,
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2015 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -168,10 +168,17 @@ public function testExecute()
$writeDirectory->expects($this->atLeastOnce())->method('delete');
$this->filesystemMock->expects($this->atLeastOnce())->method('getDirectoryWrite')->willReturn($writeDirectory);

$this->deploymentConfigMock->expects($this->once())
$this->deploymentConfigMock->expects($this->exactly(2))
->method('get')
->with(ConfigOptionsListConstants::KEY_MODULES)
->willReturn(['Magento_Catalog' => 1]);
->willReturn(
[
'Magento_Catalog' => 1,
'Module_Test' => 0
]
);
$this->componentRegistrarMock->expects($this->exactly(2))->method('getPaths');

$progressBar = new ProgressBar($this->outputMock);

$this->objectManagerMock->expects($this->once())->method('configure');
Expand All @@ -181,25 +188,21 @@ public function testExecute()
->with(ProgressBar::class)
->willReturn($progressBar);

$operations = [
OperationFactory::REPOSITORY_GENERATOR,
OperationFactory::DATA_ATTRIBUTES_GENERATOR,
OperationFactory::APPLICATION_CODE_GENERATOR,
OperationFactory::INTERCEPTION,
OperationFactory::AREA_CONFIG_GENERATOR,
OperationFactory::INTERCEPTION_CACHE,
OperationFactory::APPLICATION_ACTION_LIST_GENERATOR,
OperationFactory::PLUGIN_LIST_GENERATOR,
];
$this->managerMock->expects($this->exactly(9))->method('addOperation')
->willReturnCallback(function ($arg1, $arg2) {
->willReturnCallback(function ($arg1, $arg2) use ($operations) {
if ($arg1 == OperationFactory::PROXY_GENERATOR && empty($arg2)) {
return null;
} elseif ($arg1 == OperationFactory::REPOSITORY_GENERATOR) {
return null;
} elseif ($arg1 == OperationFactory::DATA_ATTRIBUTES_GENERATOR) {
return null;
} elseif ($arg1 == OperationFactory::APPLICATION_CODE_GENERATOR) {
return null;
} elseif ($arg1 == OperationFactory::INTERCEPTION) {
return null;
} elseif ($arg1 == OperationFactory::AREA_CONFIG_GENERATOR) {
return null;
} elseif ($arg1 == OperationFactory::INTERCEPTION_CACHE) {
return null;
} elseif ($arg1 == OperationFactory::APPLICATION_ACTION_LIST_GENERATOR) {
return null;
} elseif ($arg1 == OperationFactory::PLUGIN_LIST_GENERATOR) {
} elseif (in_array($arg1, $operations)) {
return null;
}
});
Expand Down