Skip to content

Commit

Permalink
fix: def output to cue instead of json
Browse files Browse the repository at this point in the history
Some cue library may requires specific context to eval and is expected to be incomplete.

It is not guarenteed to be exportable to json.
  • Loading branch information
yujunz authored and tnarg committed Apr 23, 2022
1 parent 1f245c4 commit f855461
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go/private:common.bzl", "env_execute", "executable_extension")
load("@io_bazel_rules_go//go/private:common.bzl", "env_execute")

CuePkg = provider(
doc = "Collects files from cue_library for use in downstream cue_export",
Expand All @@ -20,7 +20,7 @@ def _cue_def(ctx):
"Cue def library"
srcs_zip = _zip_src(ctx, ctx.files.srcs)
merged = _pkg_merge(ctx, srcs_zip)
def_out = ctx.actions.declare_file(ctx.label.name + "~def.json")
def_out = ctx.actions.declare_file(ctx.label.name + "~def.cue")

args = ctx.actions.args()
args.add(ctx.executable._cue.path)
Expand Down Expand Up @@ -60,8 +60,8 @@ def _cue_library_impl(ctx):
def_out = _cue_def(ctx)

# Create the manifest input to zipper
pkg = "pkg/"+ctx.attr.importpath.split(":")[0]
manifest = "".join([pkg+"/"+src.basename + "=" + src.path + "\n" for src in ctx.files.srcs])
pkg = "pkg/" + ctx.attr.importpath.split(":")[0]
manifest = "".join([pkg + "/" + src.basename + "=" + src.path + "\n" for src in ctx.files.srcs])
manifest_file = ctx.actions.declare_file(ctx.label.name + "~manifest")
ctx.actions.write(manifest_file, manifest)

Expand All @@ -72,7 +72,6 @@ def _cue_library_impl(ctx):
args.add(pkg.path)
args.add("@" + manifest_file.path)


ctx.actions.run(
mnemonic = "CuePkg",
outputs = [pkg],
Expand Down Expand Up @@ -160,6 +159,7 @@ def _cue_export(ctx, merged, output):

if ctx.attr.escape:
args.add("--escape")

#if ctx.attr.ignore:
# args.add("--ignore")
#if ctx.attr.simplify:
Expand Down Expand Up @@ -203,8 +203,6 @@ def _cue_export_impl(ctx):
runfiles = ctx.runfiles(files = [ctx.outputs.export]),
)



_cue_deps_attr = attr.label_list(
doc = "cue_library targets to include in the evaluation",
providers = [CuePkg],
Expand Down Expand Up @@ -321,7 +319,7 @@ the input name, so use this attribute with caution.""",
executable = True,
allow_single_file = True,
cfg = "host",
)
),
}

cue_export = rule(
Expand Down Expand Up @@ -375,7 +373,7 @@ def _cue_repository_impl(ctx):
"-repo_root",
ctx.path(""),
"-repo_config",
ctx.path(ctx.attr.build_config)
ctx.path(ctx.attr.build_config),
]
if ctx.attr.build_file_name:
cmd.extend(["-build_file_name", ctx.attr.build_file_name])
Expand Down Expand Up @@ -438,7 +436,7 @@ cue_repository = repository_rule(
],
),
"build_extra_args": attr.string_list(),
"build_config": attr.label(default= "@bazel_gazelle_go_repository_config//:WORKSPACE"),
"build_config": attr.label(default = "@bazel_gazelle_go_repository_config//:WORKSPACE"),
"build_directives": attr.string_list(default = []),

# Patches to apply after running gazelle.
Expand Down

0 comments on commit f855461

Please sign in to comment.