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

Use MultiGet in Go rule #15838

Merged
merged 2 commits into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/python/pants/backend/go/util_rules/first_party_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,22 @@ async def setup_first_party_pkg_digest(
Digest, RemovePrefix(resources_sources.snapshot.digest, request.address.spec_path)
)
resources_digest = await Get(Digest, AddPrefix(resources_digest, "__resources__"))
sources_digest = await Get(Digest, MergeDigests((sources_digest, resources_digest)))

patterns_json = {
"EmbedPatterns": analysis.embed_patterns,
"TestEmbedPatterns": analysis.test_embed_patterns,
"XTestEmbedPatterns": analysis.xtest_embed_patterns,
}
patterns_json_digest = await Get(
Digest,
CreateDigest([FileContent("patterns.json", json.dumps(patterns_json).encode("utf-8"))]),

patterns_json = json.dumps(
{
"EmbedPatterns": analysis.embed_patterns,
"TestEmbedPatterns": analysis.test_embed_patterns,
"XTestEmbedPatterns": analysis.xtest_embed_patterns,
}
).encode("utf-8")
sources_digest, patterns_json_digest = await MultiGet(
Get(Digest, MergeDigests((sources_digest, resources_digest))),
Get(Digest, CreateDigest([FileContent("patterns.json", patterns_json)])),
)
input_digest = await Get(
Digest, MergeDigests((sources_digest, patterns_json_digest, embedder.digest))
)

embed_result = await Get(
FallibleProcessResult,
Process(
Expand Down
26 changes: 11 additions & 15 deletions src/python/pants/backend/go/util_rules/third_party_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import ijson

from pants.backend.go.go_sources.load_go_binary import LoadedGoBinary, LoadedGoBinaryRequest
from pants.backend.go.subsystems.golang import GolangSubsystem
from pants.backend.go.util_rules import pkg_analyzer
from pants.backend.go.util_rules.embedcfg import EmbedConfig
from pants.backend.go.util_rules.pkg_analyzer import PackageAnalyzerSetup
Expand Down Expand Up @@ -265,9 +264,7 @@ def _freeze_json_dict(d: dict[Any, Any]) -> FrozenDict[str, Any]:

@rule
async def analyze_go_third_party_module(
request: AnalyzeThirdPartyModuleRequest,
analyzer: PackageAnalyzerSetup,
golang_subsystem: GolangSubsystem,
request: AnalyzeThirdPartyModuleRequest, analyzer: PackageAnalyzerSetup
) -> AnalyzedThirdPartyModule:
# Download the module.
download_result = await Get(
Expand Down Expand Up @@ -450,17 +447,16 @@ async def analyze_go_third_party_package(
)

if analysis.embed_patterns or analysis.test_embed_patterns or analysis.xtest_embed_patterns:
embedder = await Get(
LoadedGoBinary, LoadedGoBinaryRequest("embedcfg", ("main.go",), "./embedder")
)
patterns_json = {
"EmbedPatterns": analysis.embed_patterns,
"TestEmbedPatterns": analysis.test_embed_patterns,
"XTestEmbedPatterns": analysis.xtest_embed_patterns,
}
patterns_json_digest = await Get(
Digest,
CreateDigest([FileContent("patterns.json", json.dumps(patterns_json).encode("utf-8"))]),
patterns_json = json.dumps(
{
"EmbedPatterns": analysis.embed_patterns,
"TestEmbedPatterns": analysis.test_embed_patterns,
"XTestEmbedPatterns": analysis.xtest_embed_patterns,
}
).encode("utf-8")
embedder, patterns_json_digest = await MultiGet(
Get(LoadedGoBinary, LoadedGoBinaryRequest("embedcfg", ("main.go",), "./embedder")),
Get(Digest, CreateDigest([FileContent("patterns.json", patterns_json)])),
)
input_digest = await Get(
Digest, MergeDigests((package_digest, patterns_json_digest, embedder.digest))
Expand Down