Skip to content
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

[export-dep-as-jar] Respect strict_deps in libraries field #9145

Conversation

blorente
Copy link
Contributor

Problem

The libraries field of a target didn't respect the strict_deps of the target, making it not correct.

Solution

Precalculate a set of "things we want in the classpath", which takes strict_deps into account.
Predicate including something in the libraries field, so that we only include things from this set.

Result

The test introduced in the third commit failed before the change, succeeds after.

Notes:

Copy link
Member

@hrfuller hrfuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

Copy link
Contributor

@wisechengyi wisechengyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Borja!

@blorente blorente merged commit 15a36df into pantsbuild:master Feb 19, 2020
wisechengyi pushed a commit that referenced this pull request May 15, 2020
…9485)

### Problem

In #9145, we made the `libraries` field in a `target` entry respect `stric_deps`. While this is correct to construct an accurate compile classpath, there are certain cases where it now becomes impossible to reconstruct a runtime classpath.

Runtime classpaths shouldn't respect strict deps, so we need to store that information somewhere.

### Solution

Implementation:
- We implement this by storing extra information when we compute the flat non-modulizable dependency list. We introduce a new type to hold that information:
```
@DataClass()
class FlatDependenciesInfo:
    """Holds flat meta information about the runtime and compile time dependencies of a target.

    Compile time dependencies should respect strict_deps, whereas runtime deps should not.
    """

    compile_deps: FrozenOrderedSet[Target]
    runtime_deps: FrozenOrderedSet[Target]
```
- We modify `_flat_non_modulizable_deps_for_modulizable_targets` so that it returns a `Dict[Target, FlatDependenciesInfo]` (instead of the previous `Dict[Target, FrozenOrderedSet[Target]]`).
- In that function, when we pre-seed the dict with targets that have `strict_deps` enabled, we calculate the `runtime_deps` with the target's `closure()`. This is potentially expensive, but the implementation remains significantly cleaner this way, because we can keep avoiding expanding `strict_deps` targets. This can be changed if needed.

### Result

Introduce API changes to `export-dep-as-jar`:
- `libraries` entries for targets will now be named `compile_libraries`.
- There is a new entry in a target, called `runtime_libraries`, which will include all non-modulizable targets that are dependencies, not restricting strict_deps. This field should be combined with the values of `runtime_libraries` of all dependencies under the `targets` field to create the runtime classpath.

**Note** Depends on #9748
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants