From 7e4c5dc86838b3b4a2891026a5afe345fd83a2f3 Mon Sep 17 00:00:00 2001 From: "Steven E. Harris" Date: Fri, 15 Mar 2024 09:07:17 -0400 Subject: [PATCH] Introduce "output_package_name" attribute 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. --- cue/cue.bzl | 14 ++++++++++++-- test/testdata/non-cue/BUILD.bazel | 5 +---- test/testdata/non-cue/non-cue-golden.cue | 2 ++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/cue/cue.bzl b/cue/cue.bzl index c37855f..59ce132 100644 --- a/cue/cue.bzl +++ b/cue/cue.bzl @@ -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. @@ -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: @@ -776,6 +784,7 @@ def _add_common_exported_output_attrs_to(attrs): doc = "Output format", default = "json", values = [ + "cue", "json", "text", "yaml", @@ -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", diff --git a/test/testdata/non-cue/BUILD.bazel b/test/testdata/non-cue/BUILD.bazel index c2748b3..321df75 100644 --- a/test/testdata/non-cue/BUILD.bazel +++ b/test/testdata/non-cue/BUILD.bazel @@ -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:", ], diff --git a/test/testdata/non-cue/non-cue-golden.cue b/test/testdata/non-cue/non-cue-golden.cue index 383e74c..1ece127 100644 --- a/test/testdata/non-cue/non-cue-golden.cue +++ b/test/testdata/non-cue/non-cue-golden.cue @@ -1,3 +1,5 @@ +package merged + import "strings" name: strings.MinRunes(1) & {