Skip to content

Adding in customisable exclude paths in setup:di:compile #20485

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

Closed

Conversation

PivitParkour94
Copy link

Description (*)

There has been lots of demand for extending the di compilation exclude paths (either via CLI options or events) so I decided to add in an event setup_di_compile_excluded_patterns that can be observed and added to from within a third-party module.

Fixed Issues (if relevant)

  1. [M2.1] - No CLI option to exclude patterns on setup:di:compile and other inflexibilities #5676: [M2.1] - No CLI option to exclude patterns on setup:di:compile and other inflexibilities

Manual testing scenarios (*)

  1. Create a module that normally breaks setup:di:compile
  2. Add an observer for the 'setup_di_compile_excluded_patterns' event that adds an exclusion path for the file that is breaking the compilation
  3. Run bin/magento setup:di:compile and see it compiles as expected despite the bad code in the module file.

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

Notes

There are a bunch of commits on here, but as you can tell from the diff, those proposed changes that were rejected previously have been reverted. This simply updates the setup:di:compile to give the ability to exclude custom paths via an observer.

Nathaniel Rogers and others added 8 commits August 29, 2018 11:23
Attempt to make the debugging a little easier when the system configuration is incorrect.
Needed to add the App state class and the Logger to determine how much logging is used and how to get the error to the end developer or user.
Updated the PHPUnit test to have logger and state mocks. Included a Unit test for confirming the exception message in developer mode.
… or import the class at the top, but it isn't common to see in core code.
…1-No-CLI-option-to-exclude-patterns-on-setup-di-compile-and/idi-p/48447

Added event dispatch with excluded patterns so observers can exclude specific custom paths when running setup:di:compile.
Ideally, because this forces the vendors to acknowledge that the compilation isn't working, they will be prompted to fix the actual issue instead of simply excluding the problem.
Updating 2.3-develop branch with magento2/2.3-develop branch
@magento-engcom-team
Copy link
Contributor

Hi @PivitParkour94. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@orlangur
Copy link
Contributor

orlangur commented Apr 4, 2019

Current implementation excludes tests

$excludedModulePaths = [];
foreach ($modulePaths as $appCodePath) {
$excludedModulePaths[] = '#^' . $appCodePath . '/Test#';
}
$excludedLibraryPaths = [];
foreach ($libraryPaths as $libraryPath) {
$excludedLibraryPaths[] = '#^' . $libraryPath . '/([\\w]+/)?Test#';
}
$this->excludedPathsList = [
'application' => $excludedModulePaths,
'framework' => $excludedLibraryPaths
];
and is just fine until there is an evidence something else needs to be excluded from compilation.

@orlangur orlangur closed this Apr 4, 2019
@m2-assistant
Copy link

m2-assistant bot commented Apr 4, 2019

Hi @PivitParkour94, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@jwundrak
Copy link

@orlangur We have in some modules a directory "Example", that contains some standalone php files. They are also to check some connectivity. One example: Simple SOAP-Queries. On each setup:di:compile, all of the files are executed.
Ok, this is no "evidence", that this pull request is really needed, but this is my case. Maybe @PivitParkour94 can share us his use case.

Cause we can not use plugins here and a di.xml-argument passing excludePatterns is override by DiCompileCommand:: configureObjectManager and there is no other possibility, to customize the patterns. Adding this event is smart, of course if only <0,1% of developers need this (e.g. there are some questions on magento-stackexchange).

Also there was such an option #986

@jwundrak jwundrak reopened this May 30, 2019
@m2-assistant
Copy link

m2-assistant bot commented May 30, 2019

Hi @PivitParkour94. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@ghost ghost unassigned orlangur May 30, 2019
@orlangur orlangur self-assigned this Jun 5, 2019
@orlangur
Copy link
Contributor

orlangur commented Jun 5, 2019

We have in some modules a directory "Example", that contains some standalone php files. They are also to check some connectivity

@jwundrak why not put them in Test directory? You shouldn't add any junk to your modules in the first place.

@jwundrak
Copy link

jwundrak commented Jun 5, 2019

We have in some modules a directory "Example", that contains some standalone php files. They are also to check some connectivity

@jwundrak why not put them in Test directory? You shouldn't add any junk to your modules in the first place.

Sure, an option. I have noticed, you don't want this option and that is ok.
We use custom patterns now with a plugin. For people, that want to do this also, is here a gist.

Thanks for answer. I close this request again.

@jwundrak jwundrak closed this Jun 5, 2019
@m2-assistant
Copy link

m2-assistant bot commented Jun 5, 2019

Hi @PivitParkour94, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@orlangur
Copy link
Contributor

orlangur commented Jun 5, 2019

Thanks for understanding @jwundrak. Main problem I see is that with such option we can unintentionally affect classes in some other module rather the one we want to exclude from compilation.

@PivitParkour94
Copy link
Author

... Maybe @PivitParkour94 can share us his use case.

@jwundrak I've given up trying to help make Magento open source better for developers. It is clear that Magento is focusing on the Commerce market and I wouldn't be surprised if the Open Source dev is frustratingly difficult intentionally, to help incentivise the upgrade to Commerce.

Such is life, I suppose.

@PivitParkour94 PivitParkour94 deleted the 2.3-develop branch June 18, 2019 05:10
@orlangur
Copy link
Contributor

@PivitParkour94 could you please be more specific? This particular decision makes Magento BETTER for developers. You need to do things properly instead of adding some hacks/flags/exclusions here and there.

@PivitParkour94
Copy link
Author

PivitParkour94 commented Jun 18, 2019

This particular decision makes Magento BETTER for developers. You need to do things properly instead of adding some hacks/flags/exclusions here and there.

@orlangur I completely agree, however, we've noticed that almost every 3rd party module developer including modules that are bundled in with the core, don't always follow those practices, which means that we then have to patch OTHER's code to change the "hacks/flags/exclusions here and there" simply because the flexibility isn't there.

I am simply offering a solution to account for the code that isn't up to standard while still allowing a development workflow that doesn't break the entire pipeline.

@PivitParkour94 could you please be more specific?

I've made a number of different Pull Requests, which takes effort and they have been declined and it's just gotten to the point where we maintain a bunch of patches to core that we have to update ourselves with each new version.

It's not as though I'm suggesting a change that forces everyone to change, but rather accommodates those edge cases in which the 0.1% of developers have previously been restricted.

@jwundrak has shown a gist that achieves very similar functionality so clearly this issue effects at least both of our environments.

@orlangur
Copy link
Contributor

@PivitParkour94,

almost every 3rd party module developer including modules that are bundled in with the core, don't always follow those practices

This is something core developers are being working on hard now. Trying to catch as much guidekines violations as possible.

@PivitParkour94
Copy link
Author

This is something core developers are being working on hard now. Trying to catch as much guidekines violations as possible.

@orlangur even if that is the case, nothing is going to stop 3rd party developers from trying to force their own development practices into the modules rather than take the time to learn how Magento 2 should be developed and extended.

It's clear that this is not going to be solved and we'll just have to deal with it.

Having said that, in a perfect world everyone would develop according to the standards and things would never break, but this is Software Dev, far from a perfect world.

@jasonhildebrand
Copy link

I have a real-world use case. In our Magento instance, we use a 3rd party module called mconnect. It is installed (via composer), and it is used by a custom module (MConnect) in our source tree.

mconnect is installed only in staging and production environments. This is partly due to licensing, and partly because it syncs data with other systems - we don't want to impact these systems from our dev instances. In development, we simply leave MConnect disabled.

However, running bin/magento setup:di:compile fails when it scans the MConnect code, because the classes from mconnect which it requires are not installed. Ideally, we'd have a way to exclude MConnect from being scanned, since we are leaving it disabled and do not use it in dev environments.

@orlangur
Copy link
Contributor

@jasonhildebrand,

In development, we simply leave MConnect disabled.

You clearly don't need it on dev instances. So either strip it during deploy on dev or add it dynamically during deploy on staging/production.

@orlangur
Copy link
Contributor

The rule of thumb is simple: don't keep in source code what you actually don't use. As a side effect you may avoid a lot of troubles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants