-
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix JVM resource classification and artifact grouping (Cherry-pick of #…
…15567) (#15573) #15457 introduced a code generator to generate `resources` from `resources`, and that broke the classification of `resources` for the JVM, because the `JvmResourcesRequest` matched twice. Additionally, the generator-awareness of `resources` processing was not working (depending on a `resources` generator should bring in a single jar containing the entire set of files, while depending on a single `resource` target should expose only that file) due to an inverted condition. Add an integration test to cover both cases. [ci skip-rust] [ci skip-build-wheels]
- Loading branch information
Showing
4 changed files
with
111 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
from pants.build_graph.address import Address | ||
from pants.core.target_types import ResourcesGeneratorTarget, ResourceTarget | ||
from pants.core.target_types import rules as core_target_types_rules | ||
from pants.engine.addresses import Addresses | ||
from pants.jvm import classpath, resources, testutil | ||
from pants.jvm.goals import lockfile | ||
from pants.jvm.resolve.coursier_fetch import CoursierResolvedLockfile | ||
from pants.jvm.resolve.coursier_fetch import rules as coursier_fetch_rules | ||
from pants.jvm.resolve.coursier_test_util import TestCoursierWrapper | ||
from pants.jvm.testutil import RenderedClasspath, maybe_skip_jdk_test | ||
from pants.jvm.util_rules import rules as util_rules | ||
from pants.testutil.rule_runner import PYTHON_BOOTSTRAP_ENV, QueryRule, RuleRunner | ||
|
||
EMPTY_LOCKFILE = TestCoursierWrapper(CoursierResolvedLockfile(())).serialize([]) | ||
|
||
|
||
@pytest.fixture | ||
def rule_runner() -> RuleRunner: | ||
rule_runner = RuleRunner( | ||
rules=[ | ||
*core_target_types_rules(), | ||
*coursier_fetch_rules(), | ||
*lockfile.rules(), | ||
*resources.rules(), | ||
*classpath.rules(), | ||
*util_rules(), | ||
*testutil.rules(), | ||
QueryRule(RenderedClasspath, (Addresses,)), | ||
], | ||
target_types=[ | ||
ResourcesGeneratorTarget, | ||
ResourceTarget, | ||
], | ||
) | ||
rule_runner.set_options(args=[], env_inherit=PYTHON_BOOTSTRAP_ENV) | ||
return rule_runner | ||
|
||
|
||
@maybe_skip_jdk_test | ||
def test_resources(rule_runner: RuleRunner) -> None: | ||
rule_runner.write_files( | ||
{ | ||
"BUILD": "resources(name='root', sources=['*.txt'])", | ||
"one.txt": "", | ||
"two.txt": "", | ||
"3rdparty/jvm/default.lock": EMPTY_LOCKFILE, | ||
} | ||
) | ||
|
||
# Building the generator target should exclude the individual files and result in a single jar | ||
# for the generator. | ||
rendered_classpath = rule_runner.request( | ||
RenderedClasspath, [Addresses([Address(spec_path="", target_name="root")])] | ||
) | ||
assert rendered_classpath.content == { | ||
".root.resources.jar": { | ||
"one.txt", | ||
"two.txt", | ||
} | ||
} | ||
|
||
# But requesting a single file should individually package it. | ||
rendered_classpath = rule_runner.request( | ||
RenderedClasspath, | ||
[Addresses([Address(spec_path="", target_name="root", relative_file_path="one.txt")])], | ||
) | ||
assert rendered_classpath.content == { | ||
".one.txt.root.resources.jar": { | ||
"one.txt", | ||
} | ||
} |