1- load ("@io_bazel_rules_go//go:def.bzl" , "GoSource" , "go_context" )
1+ load ("@io_bazel_rules_go//go:def.bzl" , "GoSource" , "GoPath" , " go_context" , "go_path " )
22
33EntGenerateInfo = provider (
44 "Ent schema generation info" ,
@@ -21,8 +21,6 @@ def _ent_generate_impl(ctx):
2121 files = []
2222 for f in [
2323 "client" ,
24- "config" ,
25- "context" ,
2624 "ent" ,
2725 "mutation" ,
2826 "runtime" ,
@@ -54,8 +52,13 @@ def _ent_generate_impl(ctx):
5452 else :
5553 libraries .setdefault ("ent" , []).append (outfile )
5654
55+ schema_srcs = []
56+ for pkg in ctx .attr .gopath [GoPath ].packages :
57+ for src in pkg .srcs :
58+ schema_srcs .append (src )
59+
5760 schema_path = "./" + ctx .attr .schema .label .package
58- schema_package = ctx .attr .schema . label . name
61+ schema_package = ctx .attr .schema [ GoSource ]. library . importpath
5962 target_path = outputs [0 ].dirname # TODO: better/cleaner way?
6063 target_package = ctx .attr .importpath
6164
@@ -77,7 +80,7 @@ def _ent_generate_impl(ctx):
7780 arguments = [schema_path , schema_package , target_path , target_package ],
7881 # TODO: check rules_go again what tools are really needed here.
7982 tools = [ctx .executable ._generate ] + go .sdk_tools + go .sdk_files ,
80- inputs = depset (ctx .files .gomod + ctx . attr . schema [ GoSource ]. srcs ),
83+ inputs = depset (ctx .files .gomod + schema_srcs ),
8184 outputs = outputs ,
8285 env = {"GOROOT_FINAL" : "GOROOT" },
8386 )
@@ -112,6 +115,7 @@ _ent_generate = rule(
112115 "_go_context_data" : attr .label (
113116 default = Label ("@io_bazel_rules_go//:go_context_data" ),
114117 ),
118+ "gopath" : attr .label (),
115119 "importpath" : attr .string (mandatory = True ),
116120 "deps" : attr .label_list (
117121 default = [
@@ -175,12 +179,17 @@ _ent_library = rule(
175179
176180def go_ent_library (name , gomod , entities , schema , visibility , importpath ):
177181 # TODO: handle potential name conflicts.
182+ go_path (
183+ name = name + "_gopath" ,
184+ deps = [schema ],
185+ )
178186 _ent_generate (
179187 name = name + "_generate" ,
180188 entities = entities ,
181189 schema = schema ,
182190 gomod = gomod ,
183191 importpath = importpath ,
192+ gopath = ":" + name + "_gopath" ,
184193 )
185194
186195 default_deps = [
0 commit comments