Skip to content

Commit 7cdfea0

Browse files
committed
Remove some fields from Go context
1 parent a32f3e1 commit 7cdfea0

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
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)
@@ -237,10 +237,12 @@ def _run_nogo(
237237
out_validation,
238238
nogo):
239239
"""Runs nogo on Go source files, including those generated by cgo."""
240-
inputs_direct = (sources + [nogo, go.package_list] +
240+
sdk = go.sdk
241+
242+
inputs_direct = (sources + [nogo, sdk.package_list] +
241243
[archive.data.facts_file for archive in archives if archive.data.facts_file] +
242244
[archive.data.export_file for archive in archives])
243-
inputs_transitive = [go.sdk.tools, go.sdk.headers, go.stdlib.libs]
245+
inputs_transitive = [sdk.tools, sdk.headers, go.stdlib.libs]
244246
outputs = [out_facts, out_log]
245247

246248
args = go.builder_args(go, "nogo", use_path_mapping = True)
@@ -259,7 +261,7 @@ def _run_nogo(
259261
args.add("-importpath", go.label.name)
260262
if importmap:
261263
args.add("-p", importmap)
262-
args.add("-package_list", go.package_list)
264+
args.add("-package_list", sdk.package_list)
263265

264266
args.add_all(archives, before_each = "-facts", map_each = _facts)
265267
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: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,6 @@ def _declare_file(go, path = "", ext = "", name = ""):
158158
def _declare_directory(go, path = "", ext = "", name = ""):
159159
return go.actions.declare_directory(_child_name(go, path, ext, name))
160160

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

@@ -171,21 +167,22 @@ def _builder_args(go, command = None, use_path_mapping = False):
171167
args.set_param_file_format("shell")
172168
if command:
173169
args.add(command)
174-
args.add("-sdk", go.sdk.root_file.dirname)
170+
sdk_root_file = go.sdk.root_file
171+
args.add("-sdk", sdk_root_file.dirname)
175172

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

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

191188
def _tool_args(go):
@@ -437,7 +434,7 @@ def get_nogo(go):
437434
else:
438435
return None
439436

440-
def go_context(ctx, attr = None):
437+
def go_context(ctx, attr = None, include_deprecated_properties = True):
441438
"""Returns an API used to build Go code.
442439
443440
See /go/toolchains.rst#go-context
@@ -468,8 +465,6 @@ def go_context(ctx, attr = None):
468465
stdlib = _flatten_possibly_transitioned_attr(attr._stdlib)[GoStdLib]
469466

470467
mode = get_mode(ctx, toolchain, cgo_context_info, go_config_info)
471-
tags = mode.tags
472-
binary = toolchain.sdk.go
473468

474469
if stdlib:
475470
goroot = stdlib.root_file.dirname
@@ -528,19 +523,29 @@ def go_context(ctx, attr = None):
528523
importpath, importmap, pathtype = _infer_importpath(ctx, attr)
529524
importpath_aliases = tuple(getattr(attr, "importpath_aliases", ()))
530525

526+
if include_deprecated_properties:
527+
deprecated_properties = {
528+
"root": goroot,
529+
"go": toolchain.sdk.go,
530+
"sdk_root": toolchain.sdk.root_file,
531+
"sdk_tools": toolchain.sdk.tools,
532+
"package_list": toolchain.sdk.package_list,
533+
"tags": mode.tags,
534+
"stamp": mode.stamp,
535+
"cover_format": mode.cover_format,
536+
"pgoprofile": mode.pgoprofile,
537+
}
538+
else:
539+
deprecated_properties = {}
540+
531541
return struct(
532542
# Fields
533543
toolchain = toolchain,
534544
sdk = toolchain.sdk,
535545
mode = mode,
536-
root = goroot,
537-
go = binary,
538546
stdlib = stdlib,
539-
sdk_root = toolchain.sdk.root_file,
540-
sdk_tools = toolchain.sdk.tools,
541547
actions = ctx.actions,
542548
cc_toolchain_files = cc_toolchain_files,
543-
package_list = toolchain.sdk.package_list,
544549
importpath = importpath,
545550
importmap = importmap,
546551
importpath_aliases = importpath_aliases,
@@ -552,18 +557,14 @@ def go_context(ctx, attr = None):
552557
coverage_instrumented = ctx.coverage_instrumented(),
553558
env = env,
554559
env_for_path_mapping = env_for_path_mapping,
555-
tags = tags,
556-
stamp = mode.stamp,
557560
label = ctx.label,
558-
cover_format = mode.cover_format,
559-
pgoprofile = mode.pgoprofile,
561+
560562
# Action generators
561563
archive = toolchain.actions.archive,
562564
binary = toolchain.actions.binary,
563565
link = toolchain.actions.link,
564566

565567
# Helpers
566-
args = _new_args, # deprecated
567568
builder_args = _builder_args,
568569
tool_args = _tool_args,
569570
new_library = _new_library,
@@ -574,6 +575,9 @@ def go_context(ctx, attr = None):
574575
# Private
575576
# TODO: All uses of this should be removed
576577
_ctx = ctx,
578+
579+
# Deprecated
580+
**deprecated_properties
577581
)
578582

579583
def _go_context_data_impl(ctx):

go/private/rules/test.bzl

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

0 commit comments

Comments
 (0)