3131 "//go/private:go_toolchain.bzl" ,
3232 "GO_TOOLCHAIN" ,
3333)
34- load (
35- "//go/private:providers.bzl" ,
36- "INFERRED_PATH" ,
37- )
3834load (
3935 "//go/private/rules:transition.bzl" ,
4036 "non_go_tool_transition" ,
4642
4743GoProtoImports = 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
7369def _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
8583def _proto_library_to_source (_go , attr , source , merge ):
@@ -93,8 +91,6 @@ def _proto_library_to_source(_go, attr, source, merge):
9391
9492def _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