-
-
Notifications
You must be signed in to change notification settings - Fork 644
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
[IntelliJ] Export only modulizable targets when in export-dep-as-jar
#8812
[IntelliJ] Export only modulizable targets when in export-dep-as-jar
#8812
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @blorente! Looks reasonable overall. Please kindly see comments.
src/python/pants/backend/project_info/tasks/export_dep_as_jar.py
Outdated
Show resolved
Hide resolved
src/python/pants/backend/project_info/tasks/export_dep_as_jar.py
Outdated
Show resolved
Hide resolved
src/python/pants/backend/project_info/tasks/export_dep_as_jar.py
Outdated
Show resolved
Hide resolved
Addressed comments and updated description. |
I found another problem: |
This is now ready for review. In particular the last commit (Modify tests to accomodate for the new structure) gives a good intuition on how the output has changed. (cc\ @wisechengyi @olafurpg) |
Corresponding plugin changes: pantsbuild/intellij-pants-plugin#465 |
Found some issues after a closer look. With The target relation is correct: https://gist.github.com/wisechengyi/75e00245542efdbae26abcf009936b64#file-gistfile1-txt-L6-L8 But Neither should these two entries exist: https://gist.github.com/wisechengyi/75e00245542efdbae26abcf009936b64#file-gistfile1-txt-L121-L126 because they are target roots. |
Also to be clear on the high level, given
|
849eec1
to
7bb0f0b
Compare
export-dep-as-jar
export-dep-as-jar
#8812) ### Problem As an optimization for exporting source dependencies as jars, we want to export `target` entries only for targets that are either: - Target Roots, or - Between target roots (e.g. if A -> B -> C and we `./pants export-dep-as-jar :A :C`, we want `:B` to also be in the output). ### Solution Split the function `generate_targets_map` into three parts: 1.- We iterate over all targets to create the resource map. This is `O(|all_targets|)` 2.- We iterate over all targets to fill up the `graph_info['libraries']` section. This is also `O(|all_targets|)`. 3.- We calculate the modulizable targets (that fulfil the constraints above), and populate `targets_map` with entries for those. Figuring out the modulizable targets boils down to a call to `BuildGraph.transitive_dependees_of_addresses`, which is a DFS graph traversal. Populating `targets_map` can be quadratic, because for each modulizable target we must walk its transitive dependency graph to include all of those dependencies as libraries.
The follow-up change to pantsbuild/pants#8812. ### Problem Since we will now be relying on libraries as a mechanism to express dependencies between targets, we need to process the libraries field for jvm executables as well. ### Solution Relax the filter in `PantsLibrariesExtension` to process any scala target (not just JarLibraries). ### Result: In combination with the pants PR above, the following UX is achieved: pantsbuild/pants#8812 (comment)
#8812) ### Problem As an optimization for exporting source dependencies as jars, we want to export `target` entries only for targets that are either: - Target Roots, or - Between target roots (e.g. if A -> B -> C and we `./pants export-dep-as-jar :A :C`, we want `:B` to also be in the output). ### Solution Split the function `generate_targets_map` into three parts: 1.- We iterate over all targets to create the resource map. This is `O(|all_targets|)` 2.- We iterate over all targets to fill up the `graph_info['libraries']` section. This is also `O(|all_targets|)`. 3.- We calculate the modulizable targets (that fulfil the constraints above), and populate `targets_map` with entries for those. Figuring out the modulizable targets boils down to a call to `BuildGraph.transitive_dependees_of_addresses`, which is a DFS graph traversal. Populating `targets_map` can be quadratic, because for each modulizable target we must walk its transitive dependency graph to include all of those dependencies as libraries.
### Problem When running the `export-dep-as-jar` Goal we compile all targets in the build context. This is unnecessary and can be problematic if any of the target roots have compile errors in them, because the export will fail. It is unnecessary because the target roots are being exported as source modules #8812 ### Solution We exclude target_roots, and their dependees from the compile context. ### Result Only targets in the build context that are not being exported as sources are compiled.
### Problem When running the `export-dep-as-jar` Goal we compile all targets in the build context. This is unnecessary and can be problematic if any of the target roots have compile errors in them, because the export will fail. It is unnecessary because the target roots are being exported as source modules #8812 ### Solution We exclude target_roots, and their dependees from the compile context. ### Result Only targets in the build context that are not being exported as sources are compiled.
Problem
As an optimization for exporting source dependencies as jars, we want to export
target
entries only for targets that are either:./pants export-dep-as-jar :A :C
, we want:B
to also be in the output).Solution
Split the function
generate_targets_map
into three parts:1.- We iterate over all targets to create the resource map. This is
O(|all_targets|)
2.- We iterate over all targets to fill up the
graph_info['libraries']
section. This is alsoO(|all_targets|)
.3.- We calculate the printable targets (that fulfil the constraints above), and populate
targets_map
with entries for those. Figuring out the printable targets boils down to a call toBuildGraph.transitive_dependees_of_addresses
, which is a DFS graph traversal. Populatingtargets_map
can be quadratic, because for each modulizable target we must walk its transitive dependency graph to include all of those dependencies as libraries.TODO before merging:
Result
The output json will only include the targets that fulfil the constraints defined in
Problem
in thetargets
section, as opposed to all the targets in play.