diff --git a/go/def.bzl b/go/def.bzl index abeff7aac..49da04e9f 100644 --- a/go/def.bzl +++ b/go/def.bzl @@ -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 diff --git a/go/private/context.bzl b/go/private/context.bzl index f86bc8bb5..1c7493410 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl @@ -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, @@ -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 @@ -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"]: @@ -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 @@ -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, @@ -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, diff --git a/go/private/rules/nogo.bzl b/go/private/rules/nogo.bzl index ec6d13994..288a02912 100644 --- a/go/private/rules/nogo.bzl +++ b/go/private/rules/nogo.bzl @@ -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, diff --git a/go/private/rules/test.bzl b/go/private/rules/test.bzl index 25eca2aa9..31ba3cedc 100644 --- a/go/private/rules/test.bzl +++ b/go/private/rules/test.bzl @@ -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(