Skip to content

Commit

Permalink
don't generate default tool lockfiles (Cherry pick of #15488) (#15498)
Browse files Browse the repository at this point in the history
Do not generate tool lockfiles if the tool is using the default lockfile. The bug was probably introduced by me in #15242.

Closes #15460.

[ci skip-rust]
[ci skip-build-wheels]
  • Loading branch information
Tom Dyas authored May 17, 2022
1 parent 18659e5 commit b8b6e45
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/python/pants/jvm/resolve/jvm_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ async def setup_lockfile_request_from_tool(
return GenerateJvmLockfile(
artifacts=artifacts,
resolve_name=request.resolve_name,
lockfile_dest=request.write_lockfile_dest,
lockfile_dest=request.write_lockfile_dest
if request.read_lockfile_dest != DEFAULT_TOOL_LOCKFILE
else DEFAULT_TOOL_LOCKFILE,
)


Expand Down
34 changes: 33 additions & 1 deletion src/python/pants/jvm/resolve/jvm_tool_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import textwrap

from pants.core.goals.generate_lockfiles import GenerateToolLockfileSentinel
from pants.core.goals.generate_lockfiles import DEFAULT_TOOL_LOCKFILE, GenerateToolLockfileSentinel
from pants.core.util_rules import config_files, source_files
from pants.core.util_rules.external_tool import rules as external_tool_rules
from pants.engine.fs import Digest, DigestContents
Expand All @@ -20,6 +20,7 @@
from pants.jvm.target_types import JvmArtifactTarget
from pants.jvm.util_rules import rules as util_rules
from pants.testutil.rule_runner import PYTHON_BOOTSTRAP_ENV, QueryRule, RuleRunner
from pants.util.ordered_set import FrozenOrderedSet


class MockJvmTool(JvmToolBase):
Expand All @@ -36,13 +37,36 @@ class MockJvmToolLockfileSentinel(GenerateToolLockfileSentinel):
resolve_name = MockJvmTool.options_scope


class MockInternalToolLockfileSentinel(GenerateToolLockfileSentinel):
resolve_name = "mock-internal-tool"


@rule
def generate_test_tool_lockfile_request(
_: MockJvmToolLockfileSentinel, tool: MockJvmTool
) -> GenerateJvmLockfileFromTool:
return GenerateJvmLockfileFromTool.create(tool)


@rule
def generate_internal_test_tool_lockfile_request(
_: MockInternalToolLockfileSentinel,
) -> GenerateJvmLockfileFromTool:
return GenerateJvmLockfileFromTool(
artifact_inputs=FrozenOrderedSet(
{
"com.google.code.gson:gson:2.9.0",
}
),
artifact_option_name="n/a",
lockfile_option_name="n/a",
resolve_name=MockInternalToolLockfileSentinel.resolve_name,
read_lockfile_dest=DEFAULT_TOOL_LOCKFILE,
write_lockfile_dest="mock-write-lockfile.lock",
default_lockfile_resource=("pants.backend.jvm.resolve", "mock-internal-tool.lock"),
)


def test_jvm_tool_base_extracts_correct_coordinates() -> None:
rule_runner = RuleRunner(
rules=[
Expand All @@ -55,8 +79,10 @@ def test_jvm_tool_base_extracts_correct_coordinates() -> None:
*jvm_tool.rules(),
*lockfile_rules(),
generate_test_tool_lockfile_request,
generate_internal_test_tool_lockfile_request,
SubsystemRule(MockJvmTool),
QueryRule(GenerateJvmLockfile, (MockJvmToolLockfileSentinel,)),
QueryRule(GenerateJvmLockfile, (MockInternalToolLockfileSentinel,)),
QueryRule(DigestContents, (Digest,)),
],
target_types=[JvmArtifactTarget],
Expand Down Expand Up @@ -89,3 +115,9 @@ def test_jvm_tool_base_extracts_correct_coordinates() -> None:
Coordinate(group="junit", artifact="junit", version="4.13.2"),
Coordinate(group="org.hamcrest", artifact="hamcrest-core", version="1.3"),
]

# Ensure that an internal-only tool will not have a lockfile generated.
default_lockfile_result = rule_runner.request(
GenerateJvmLockfile, [MockInternalToolLockfileSentinel()]
)
assert default_lockfile_result.lockfile_dest == DEFAULT_TOOL_LOCKFILE

0 comments on commit b8b6e45

Please sign in to comment.