Skip to content

Commit

Permalink
more cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dzbarsky committed Aug 12, 2024
1 parent 3da0b45 commit 596038b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ go_tool_library = _go_tool_library
go_toolchain = _go_toolchain
nogo = _nogo

# This provider is deprecated and will be removed in a future release.
# Use GoSource instead.
GoLibrary = _GoSource

# See go/providers.rst#GoSource for full documentation.
GoSource = _GoSource

Expand Down
44 changes: 43 additions & 1 deletion go/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,43 @@ def _dedup_deps(deps):
deduped_deps.append(dep)
return deduped_deps

def _deprecated_new_library(go, name = None, importpath = None, resolver = None, importable = True, testfilter = None, is_main = False, **kwargs):
if not importpath:
importpath = go.importpath
importmap = go.importmap
else:
importmap = importpath
pathtype = go.pathtype
if not importable and pathtype == EXPLICIT_PATH:
pathtype = EXPORT_PATH

return struct(
name = go.label.name if not name else name,
label = go.label,
importpath = importpath,
importmap = importmap,
importpath_aliases = go.importpath_aliases,
pathtype = pathtype,
resolve = resolver,
testfilter = testfilter,
is_main = is_main,
**kwargs
)

def _deprecated_library_to_source(go, attr, library, coverage_instrumented):
return new_source(
go,
attr,
name = library.name,
importpath = library.importpath,
resolver = library.resolve,
testfilter = library.testfilter,
is_main = library.is_main,
coverage_instrumented = coverage_instrumented,
generated_srcs = getattr(library, "srcs", []),
pathtype = library.pathtype,
)

def new_source(
go,
attr,
Expand Down Expand Up @@ -296,6 +333,7 @@ def new_source(
"cgo_deps": [],
"cgo_exports": [],
"cc_info": None,
"pgoprofile": getattr(attr, "pgoprofile", None),
}
if coverage_instrumented:
source["cover"] = attr_srcs
Expand All @@ -309,7 +347,7 @@ def new_source(
for k, v in getattr(attr, "x_defs", {}).items():
v = _expand_location(go, attr, v)
if "." not in k:
k = "{}.{}".format(source["importmap"], k)
k = "{}.{}".format(importmap, k)
x_defs[k] = v
source["x_defs"] = x_defs
if not source["cgo"]:
Expand Down Expand Up @@ -562,6 +600,7 @@ def go_context(ctx, attr = None):

_check_importpaths(ctx)
importpath, importmap, pathtype = _infer_importpath(ctx, attr)
importpath_aliases = tuple(getattr(attr, "importpath_aliases", ()))

return struct(
# Fields
Expand All @@ -580,6 +619,7 @@ def go_context(ctx, attr = None):
package_list = toolchain.sdk.package_list,
importpath = importpath,
importmap = importmap,
importpath_aliases = importpath_aliases,
pathtype = pathtype,
cgo_tools = cgo_tools,
nogo = nogo,
Expand All @@ -602,6 +642,8 @@ def go_context(ctx, attr = None):
args = _new_args, # deprecated
builder_args = _builder_args,
tool_args = _tool_args,
new_library = _deprecated_new_library,
library_to_source = _deprecated_library_to_source,
declare_file = _declare_file,
declare_directory = _declare_directory,

Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/nogo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def _nogo_impl(ctx):
nogo_source = new_source(
go,
struct(
srcs = [struct(files = [nogo_main])],
embed = [ctx.attr._nogo_srcs],
deps = analyzer_archives,
),
generated_srcs = [nogo_main],
name = go.label.name + "~nogo",
importpath = "nogomain",
pathtype = EXPORT_PATH,
Expand Down
2 changes: 1 addition & 1 deletion go/private/rules/test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ def _go_test_impl(ctx):
test_source = new_source(
go,
struct(
srcs = [struct(files = [main_go])],
deps = test_deps,
),
name = go.label.name + "~testmain",
importpath = "testmain",
pathtype = INFERRED_PATH,
is_main = True,
generated_srcs = [main_go],
coverage_instrumented = False,
)
test_archive, executable, runfiles = go.binary(
Expand Down

0 comments on commit 596038b

Please sign in to comment.