forked from pantsbuild/pants
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go: analyze imports paths by module to enable multiple go_mod targets (…
…pantsbuild#16386) The package mapping from import path to addresses (`ImportPathToPackages`) was global to the entire repository and not split by Go module. This prevented using multiple Go modules in a single repository. This PR solves the issue by introducing `GoImportPathMappingRequest` which allows the package mapping to be requested per module. That per-module mapping relies on a repository-wide mapping available as `AllGoModuleImportPathsMappings`. The `GoModuleImportPathsMappingsHook` union allows plugins to provide their own import path mappings. For example, this support is now used by the protobuf/go codegen backend to supply import paths from generated protobuf code, meaning that the Go backend is able to infer dependencies between Go code and protobuf code automatically. Fixes pantsbuild#13114. [ci skip-rust]
- Loading branch information
Tom Dyas
committed
Sep 8, 2022
1 parent
7270296
commit 857371b
Showing
13 changed files
with
787 additions
and
278 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2022 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
|
||
from pants.build_graph.address import Address | ||
from pants.engine.environment import EnvironmentName | ||
from pants.engine.unions import union | ||
from pants.util.frozendict import FrozenDict | ||
|
||
|
||
@union(in_scope_types=[EnvironmentName]) | ||
@dataclass(frozen=True) | ||
class GoModuleImportPathsMappingsHook: | ||
"""An entry point for a specific implementation of mapping Go import paths to owning targets. | ||
All implementations will be merged together. The core Go dependency inference rules will request | ||
the `GoModuleImportPathsMappings` type using implementations of this union. | ||
""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class GoImportPathsMappingAddressSet: | ||
addresses: tuple[Address, ...] | ||
infer_all: bool | ||
|
||
|
||
@dataclass(frozen=True) | ||
class GoModuleImportPathsMapping: | ||
"""Maps import paths (as strings) to one or more addresses of targets providing those import | ||
path(s) for a single Go module.""" | ||
|
||
mapping: FrozenDict[str, GoImportPathsMappingAddressSet] | ||
|
||
|
||
@dataclass(frozen=True) | ||
class GoModuleImportPathsMappings: | ||
"""Import path mappings for all Go modules in the repository. | ||
This type is requested from plugins which provide implementations for the GoCodegenBuildRequest | ||
union and then merged. | ||
""" | ||
|
||
modules: FrozenDict[Address, GoModuleImportPathsMapping] | ||
|
||
|
||
class AllGoModuleImportPathsMappings(GoModuleImportPathsMappings): | ||
pass |
Oops, something went wrong.