Skip to content

Commit

Permalink
Introduce "output_package_name" attribute
Browse files Browse the repository at this point in the history
Per CUE CL 1177546, allow use of the CUE tool's broadened
interpretation of the "--package" command-line flag, introducing the
"output_package_name" attribute on the "cue_consolidated_*" and
"cue_exported_*" macros to designate into which CUE package to
generate CUE code, when the "output_format" attribute's value is
"cue".

With this new "output_package_name" attribute available, deprecate the
former "non_cue_file_package_name" attribute, intending to remove it
entirely in a subsequent release.

Allow generating CUE code with the "cue_exported_*" macros.
  • Loading branch information
seh committed Mar 15, 2024
1 parent ef25f54 commit 7e4c5dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
14 changes: 12 additions & 2 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,13 @@ def _add_common_output_producing_attrs_to(attrs):
default = True,
),
"non_cue_file_package_name": attr.string(
doc = "Name of the CUE package within which to merge non-CUE files.",
doc = """Name of the CUE package within which to merge non-CUE files.
Deprecated:
Use "output_package_name" instead.""",
),
"output_package_name": attr.string(
doc = "Name of the CUE package within which to generate CUE output.",
),
"path": attr.string_list(
doc = """Elements of CUE path at which to place top-level values.
Expand Down Expand Up @@ -208,7 +214,9 @@ def _add_common_output_producing_args_to(ctx, args, stamped_args_file, packagele
args.add("--inject-vars")
if not ctx.attr.merge_other_files:
args.add("--merge=false")
if ctx.attr.non_cue_file_package_name:
if ctx.attr.output_package_name:
args.add("--package", ctx.attr.output_package_name)
elif ctx.attr.non_cue_file_package_name: # TODO(seh): Remove this after deprecation period.
args.add("--package", ctx.attr.non_cue_file_package_name)
for p in ctx.attr.path:
if not p:
Expand Down Expand Up @@ -776,6 +784,7 @@ def _add_common_exported_output_attrs_to(attrs):
doc = "Output format",
default = "json",
values = [
"cue",
"json",
"text",
"yaml",
Expand All @@ -790,6 +799,7 @@ def _add_common_exported_output_attrs_to(attrs):

def _prepare_exported_output_rule(name, **kwargs):
extension_by_format = {
"cue": "cue",
"json": "json",
"text": "txt",
"yaml": "yaml",
Expand Down
5 changes: 1 addition & 4 deletions test/testdata/non-cue/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ cue_consolidated_standalone_files(
"merge.cue",
"name.txt",
],
# NB: This doesn't make a difference for this example, other than
# that if we were to specify a different package name here, "cue
# def" would fail, complaining about the mismatch.
non_cue_file_package_name = "merged",
output_package_name = "merged",
path = [
"name:",
],
Expand Down
2 changes: 2 additions & 0 deletions test/testdata/non-cue/non-cue-golden.cue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package merged

import "strings"

name: strings.MinRunes(1) & {
Expand Down

0 comments on commit 7e4c5dc

Please sign in to comment.