Skip to content

Commit c4e878f

Browse files
committed
Infer importpath if not set explicitely
1 parent 7309aba commit c4e878f

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

go/private/rules/library.bzl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ load(
2929
load(
3030
"//go/private:providers.bzl",
3131
"GoLibrary",
32-
"INFERRED_PATH",
3332
)
3433
load(
3534
"//go/private/rules:transition.bzl",
@@ -39,8 +38,6 @@ load(
3938
def _go_library_impl(ctx):
4039
"""Implements the go_library() rule."""
4140
go = go_context(ctx)
42-
if go.pathtype == INFERRED_PATH:
43-
fail("importpath must be specified in this library or one of its embedded libraries")
4441
library = go.new_library(go)
4542
source = go.library_to_source(go, ctx.attr, library, ctx.coverage_instrumented())
4643
archive = go.archive(go, source)

proto/def.bzl

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ load(
3131
"//go/private:go_toolchain.bzl",
3232
"GO_TOOLCHAIN",
3333
)
34-
load(
35-
"//go/private:providers.bzl",
36-
"INFERRED_PATH",
37-
)
3834
load(
3935
"//go/private/rules:transition.bzl",
4036
"non_go_tool_transition",
@@ -46,7 +42,7 @@ load(
4642

4743
GoProtoImports = provider()
4844

49-
def get_imports(attr):
45+
def get_imports(attr, importpath):
5046
proto_deps = []
5147

5248
# ctx.attr.proto is a one-element array since there is a Starlark transition attached to it.
@@ -60,7 +56,7 @@ def get_imports(attr):
6056
direct = dict()
6157
for dep in proto_deps:
6258
for src in dep[ProtoInfo].check_deps_sources.to_list():
63-
direct["{}={}".format(proto_path(src, dep[ProtoInfo]), attr.importpath)] = True
59+
direct["{}={}".format(proto_path(src, dep[ProtoInfo]), importpath)] = True
6460

6561
deps = getattr(attr, "deps", []) + getattr(attr, "embed", [])
6662
transitive = [
@@ -71,7 +67,8 @@ def get_imports(attr):
7167
return depset(direct = direct.keys(), transitive = transitive)
7268

7369
def _go_proto_aspect_impl(_target, ctx):
74-
imports = get_imports(ctx.rule.attr)
70+
go = go_context(ctx, ctx.rule.attr)
71+
imports = get_imports(ctx.rule.attr, go.importpath)
7572
return [GoProtoImports(imports = imports)]
7673

7774
_go_proto_aspect = aspect(
@@ -80,6 +77,7 @@ _go_proto_aspect = aspect(
8077
"deps",
8178
"embed",
8279
],
80+
toolchains = [GO_TOOLCHAIN],
8381
)
8482

8583
def _proto_library_to_source(_go, attr, source, merge):
@@ -93,8 +91,6 @@ def _proto_library_to_source(_go, attr, source, merge):
9391

9492
def _go_proto_library_impl(ctx):
9593
go = go_context(ctx)
96-
if go.pathtype == INFERRED_PATH:
97-
fail("importpath must be specified in this library or one of its embedded libraries")
9894
if ctx.attr.compiler:
9995
#TODO: print("DEPRECATED: compiler attribute on {}, use compilers instead".format(ctx.label))
10096
compilers = [ctx.attr.compiler]
@@ -124,7 +120,7 @@ def _go_proto_library_impl(ctx):
124120
go,
125121
compiler = compiler,
126122
protos = [d[ProtoInfo] for d in proto_deps],
127-
imports = get_imports(ctx.attr),
123+
imports = get_imports(ctx.attr, go.importpath),
128124
importpath = go.importpath,
129125
))
130126
library = go.new_library(

0 commit comments

Comments
 (0)