Skip to content

Commit 2d297e9

Browse files
authored
Cleanup path-mapping enablement (#4441)
**What type of PR is this?** code cleanup **What does this PR do? Why is it needed?** This enables path-mapping for the GoInfo action and simplifies the `builder_args`. As a side effect, we now set the `-goroot` flag for link actions but they do not yet opt into path mapping (and I don't think they will work yet, since they use .path on the archives) **Which issues(s) does this PR fix?** Fixes # **Other notes for review**
1 parent 2fd5c18 commit 2d297e9

File tree

8 files changed

+20
-17
lines changed

8 files changed

+20
-17
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Benjamin Staffin <[email protected]>
1010
Brian Silverman <[email protected]>
1111
David Santiago <[email protected]>
12+
David Zbarsky <[email protected]>
1213
Google Inc.
1314
Jake Voytko <[email protected]>
1415
Yuki Yugui Sonoda <[email protected]>

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Brian Silverman <[email protected]>
1414
Damien Martin-Guillerez <[email protected]>
1515
David Chen <[email protected]>
1616
David Santiago <[email protected]>
17+
David Zbarsky <[email protected]>
1718
Fabian Meumertzheim <[email protected]>
1819
Han-Wen Nienhuys <[email protected]>
1920
Ian Cottrell <[email protected]>

go/private/actions/compilepkg.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def emit_compilepkg(
9999
inputs_transitive = [sdk.headers, sdk.tools, go.stdlib.libs, headers]
100100
outputs = [out_lib, out_export]
101101

102-
shared_args = go.builder_args(go, use_path_mapping = True)
102+
shared_args = go.builder_args(go)
103103
shared_args.add_all(sources, before_each = "-src")
104104

105105
compile_args = go.tool_args(go)

go/private/actions/link.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def emit_link(
6666

6767
# use ar tool from cc toolchain if cc toolchain provides it
6868
if go.cgo_tools and go.cgo_tools.ar_path and go.cgo_tools.ar_path.endswith("ar"):
69-
tool_args.add_all(["-extar", go.cgo_tools.ar_path])
69+
tool_args.add("-extar", go.cgo_tools.ar_path)
7070

7171
# Add in any mode specific behaviours
7272
if go.mode.race:

go/private/actions/stdlib.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ def _build_stdlib_list_json(go):
6868
out = go.declare_file(go, "stdlib.pkg.json")
6969
cache_dir = go.declare_directory(go, "gocache")
7070
args = go.builder_args(go, "stdliblist")
71-
args.add("-sdk", sdk.root_file.dirname)
7271
args.add("-out", out)
73-
args.add("-cache", cache_dir.path)
72+
args.add_all("-cache", [cache_dir], expand_directories = False)
7473
if go.export_stdlib:
7574
args.add("-export", go.export_stdlib)
7675

@@ -87,6 +86,7 @@ def _build_stdlib_list_json(go):
8786
arguments = [args],
8887
env = _build_env(go),
8988
toolchain = GO_TOOLCHAIN_LABEL,
89+
execution_requirements = SUPPORTS_PATH_MAPPING_REQUIREMENT,
9090
)
9191
return out, cache_dir
9292

@@ -130,7 +130,7 @@ def _dirname(file):
130130

131131
def _build_stdlib(go):
132132
pkg = go.declare_directory(go, path = "pkg")
133-
args = go.builder_args(go, "stdlib", use_path_mapping = True)
133+
args = go.builder_args(go, "stdlib")
134134

135135
# Use a file rather than pkg.dirname as the latter is just a string and thus
136136
# not subject to path mapping.

go/private/context.bzl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def _declare_directory(go, path = "", ext = "", name = ""):
178178
def _dirname(file):
179179
return file.dirname
180180

181-
def _builder_args(go, command = None, use_path_mapping = False):
181+
def _builder_args(go, command = None):
182182
args = go.actions.args()
183183
args.use_param_file("-param=%s")
184184
if command:
@@ -188,15 +188,15 @@ def _builder_args(go, command = None, use_path_mapping = False):
188188

189189
# Path mapping can't map the values of environment variables, so we need to pass GOROOT to the
190190
# action via an argument instead.
191-
if use_path_mapping:
192-
if go.stdlib:
193-
goroot_file = go.stdlib.root_file
194-
else:
195-
goroot_file = sdk_root_file
196-
197-
# Use a file rather than goroot as the latter is just a string and thus
198-
# not subject to path mapping.
199-
args.add_all("-goroot", [goroot_file], map_each = _dirname, expand_directories = False)
191+
if go.stdlib:
192+
goroot_file = go.stdlib.root_file
193+
else:
194+
goroot_file = sdk_root_file
195+
196+
# Use a file rather than goroot as the latter is just a string and thus
197+
# not subject to path mapping.
198+
args.add_all("-goroot", [goroot_file], map_each = _dirname, expand_directories = False)
199+
200200
mode = go.mode
201201
args.add("-installsuffix", installsuffix(mode))
202202
args.add_joined("-tags", mode.tags, join_with = ",")

go/private/rules/info.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ load(
2424
def _go_info_impl(ctx):
2525
go = go_context(ctx)
2626
report = go.declare_file(go, ext = ".txt")
27-
args = go.builder_args(go)
27+
args = go.actions.args()
28+
args.add("-sdk", go.sdk.root_file.dirname)
2829
args.add("-out", report)
2930
go.actions.run(
3031
inputs = depset([go.sdk.go], transitive = [go.sdk.tools]),

go/private/rules/test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _go_test_impl(ctx):
120120
run_dir = repo_relative_rundir
121121

122122
main_go = go.declare_file(go, path = "testmain.go")
123-
arguments = go.builder_args(go, "gentestmain", use_path_mapping = True)
123+
arguments = go.builder_args(go, "gentestmain")
124124
arguments.add("-output", main_go)
125125
if go.coverage_enabled:
126126
# Always use atomic mode as the "runtime/coverage" APIs require it

0 commit comments

Comments
 (0)