Skip to content

Commit d08cf18

Browse files
committed
Remove some fields from Go context
1 parent 56d415d commit d08cf18

File tree

5 files changed

+22
-29
lines changed

5 files changed

+22
-29
lines changed

extras/gomock.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ def _gomock_source_impl(ctx):
7373
needed_files.append(aux)
7474
args += ["-aux_files", ",".join(aux_files)]
7575

76+
sdk = go_ctx.sdk
77+
7678
inputs_direct = needed_files + [source]
77-
inputs_transitive = [go_ctx.sdk.tools, go_ctx.sdk.headers, go_ctx.sdk.srcs]
79+
inputs_transitive = [sdk.tools, sdk.headers, sdk.srcs]
7880

7981
# We can use the go binary from the stdlib for most of the environment
8082
# variables, but our GOPATH is specific to the library target we were given.
@@ -83,7 +85,7 @@ def _gomock_source_impl(ctx):
8385
inputs = depset(inputs_direct, transitive = inputs_transitive),
8486
tools = [
8587
ctx.file.mockgen_tool,
86-
go_ctx.go,
88+
sdk.go,
8789
],
8890
toolchain = GO_TOOLCHAIN_LABEL,
8991
command = """
@@ -92,7 +94,7 @@ def _gomock_source_impl(ctx):
9294
{cmd} {args} > {out}
9395
""".format(
9496
gopath = gopath,
95-
goroot = go_ctx.sdk.root_file.dirname,
97+
goroot = sdk.root_file.dirname,
9698
cmd = "$(pwd)/" + ctx.file.mockgen_tool.path,
9799
args = " ".join(args),
98100
out = ctx.outputs.out.path,

go/private/actions/compilepkg.bzl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def emit_compilepkg(
122122
else:
123123
cover_mode = "set"
124124
args.add("-cover_mode", cover_mode)
125-
args.add("-cover_format", go.cover_format)
125+
args.add("-cover_format", go.mode.cover_format)
126126
args.add_all(cover, before_each = "-cover")
127127
args.add_all(archives, before_each = "-arc", map_each = _archive)
128128
if recompile_internal_deps:
@@ -133,7 +133,7 @@ def emit_compilepkg(
133133
args.add("-importpath", go.label.name)
134134
if importmap:
135135
args.add("-p", importmap)
136-
args.add("-package_list", go.package_list)
136+
args.add("-package_list", sdk.package_list)
137137

138138
args.add("-lo", out_lib)
139139
args.add("-o", out_export)
@@ -235,10 +235,12 @@ def _run_nogo(
235235
out_validation,
236236
nogo):
237237
"""Runs nogo on Go source files, including those generated by cgo."""
238-
inputs_direct = (sources + [nogo, go.package_list] +
238+
sdk = go.sdk
239+
240+
inputs_direct = (sources + [nogo, sdk.package_list] +
239241
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
240242
[archive.data.export_file for archive in archives])
241-
inputs_transitive = [go.sdk.tools, go.sdk.headers, go.stdlib.libs]
243+
inputs_transitive = [sdk.tools, sdk.headers, go.stdlib.libs]
242244
outputs = [out_facts, out_log]
243245

244246
args = go.builder_args(go, "nogo", use_path_mapping = True)
@@ -257,7 +259,7 @@ def _run_nogo(
257259
args.add("-importpath", go.label.name)
258260
if importmap:
259261
args.add("-p", importmap)
260-
args.add("-package_list", go.package_list)
262+
args.add("-package_list", sdk.package_list)
261263

262264
args.add_all(archives, before_each = "-facts", map_each = _facts)
263265
args.add("-out_facts", out_facts)

go/private/actions/link.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def emit_link(
136136
not any([arc.importmap == go.coverdata.data.importmap for arc in arcs])):
137137
arcs.append(go.coverdata.data)
138138
builder_args.add_all(arcs, before_each = "-arc", map_each = _format_archive)
139-
builder_args.add("-package_list", go.package_list)
139+
builder_args.add("-package_list", go.sdk.package_list)
140140

141141
# Build a list of rpaths for dynamic libraries we need to find.
142142
# rpaths are relative paths from the binary to directories where libraries
@@ -156,7 +156,7 @@ def emit_link(
156156
stamp_x_defs_stable = False
157157
for k, v in archive.x_defs.items():
158158
builder_args.add("-X", "%s=%s" % (k, v))
159-
if go.stamp:
159+
if go.mode.stamp:
160160
stable_vars_count = (count_group_matches(v, "{STABLE_", "}") +
161161
v.count("{BUILD_EMBED_LABEL}") +
162162
v.count("{BUILD_USER}") +

go/private/context.bzl

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ def _declare_file(go, path = "", ext = "", name = ""):
159159
def _declare_directory(go, path = "", ext = "", name = ""):
160160
return go.actions.declare_directory(_child_name(go, path, ext, name))
161161

162-
def _new_args(go):
163-
# TODO(jayconrod): print warning.
164-
return go.builder_args(go)
165-
166162
def _dirname(file):
167163
return file.dirname
168164

@@ -172,21 +168,22 @@ def _builder_args(go, command = None, use_path_mapping = False):
172168
args.set_param_file_format("shell")
173169
if command:
174170
args.add(command)
175-
args.add("-sdk", go.sdk.root_file.dirname)
171+
sdk_root_file = go.sdk.root_file
172+
args.add("-sdk", sdk_root_file.dirname)
176173

177174
# Path mapping can't map the values of environment variables, so we need to pass GOROOT to the
178175
# action via an argument instead.
179176
if use_path_mapping:
180177
if go.stdlib:
181178
goroot_file = go.stdlib.root_file
182179
else:
183-
goroot_file = go.sdk_root
180+
goroot_file = sdk_root_file
184181

185182
# Use a file rather than goroot as the latter is just a string and thus
186183
# not subject to path mapping.
187184
args.add_all("-goroot", [goroot_file], map_each = _dirname, expand_directories = False)
188185
args.add("-installsuffix", installsuffix(go.mode))
189-
args.add_joined("-tags", go.tags, join_with = ",")
186+
args.add_joined("-tags", go.mode.tags, join_with = ",")
190187
return args
191188

192189
def _tool_args(go):
@@ -471,7 +468,6 @@ def go_context(ctx, attr = None):
471468

472469
mode = get_mode(ctx, toolchain, cgo_context_info, go_config_info)
473470
tags = mode.tags
474-
binary = toolchain.sdk.go
475471

476472
if stdlib:
477473
goroot = stdlib.root_file.dirname
@@ -563,16 +559,11 @@ def go_context(ctx, attr = None):
563559
toolchain = toolchain,
564560
sdk = toolchain.sdk,
565561
mode = mode,
566-
root = goroot,
567-
go = binary,
568562
stdlib = stdlib,
569-
sdk_root = toolchain.sdk.root_file,
570-
sdk_tools = toolchain.sdk.tools,
571563
actions = ctx.actions,
572564
exe_extension = goos_to_extension(mode.goos),
573565
shared_extension = goos_to_shared_extension(mode.goos),
574566
cc_toolchain_files = cc_toolchain_files,
575-
package_list = toolchain.sdk.package_list,
576567
importpath = importpath,
577568
importmap = importmap,
578569
importpath_aliases = importpath_aliases,
@@ -584,25 +575,23 @@ def go_context(ctx, attr = None):
584575
coverage_instrumented = ctx.coverage_instrumented(),
585576
env = env,
586577
env_for_path_mapping = env_for_path_mapping,
587-
tags = tags,
588-
stamp = mode.stamp,
589578
label = ctx.label,
590-
cover_format = mode.cover_format,
591-
pgoprofile = mode.pgoprofile,
592579
# Action generators
593580
archive = toolchain.actions.archive,
594581
binary = toolchain.actions.binary,
595582
link = toolchain.actions.link,
596583

597584
# Helpers
598-
args = _new_args, # deprecated
599585
builder_args = _builder_args,
600586
tool_args = _tool_args,
601587
new_library = _new_library,
602588
library_to_source = _library_to_source,
603589
declare_file = _declare_file,
604590
declare_directory = _declare_directory,
605591

592+
# TODO(zbarsky): package_list only used in gazelle, this can be removed
593+
package_list = toolchain.sdk.package_list,
594+
606595
# Private
607596
# TODO: All uses of this should be removed
608597
_ctx = ctx,

go/private/rules/test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _go_test_impl(ctx):
101101
arguments.add("-cover_mode", "atomic")
102102
else:
103103
arguments.add("-cover_mode", "set")
104-
arguments.add("-cover_format", go.cover_format)
104+
arguments.add("-cover_format", go.mode.cover_format)
105105
arguments.add(
106106
# the l is the alias for the package under test, the l_test must be the
107107
# same with the test suffix

0 commit comments

Comments
 (0)