Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cue/cue-run-from-archived-runfiles
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e

function usage() {
printf "usage: %s [-i instance_path] [-m module_file] [-p package_name] cue_tool cue_subcommand extra_args_file packageless_files_file output_file [args...]\n" "$(basename "${0}")" 1>&2
printf "usage: %s [-d cue_debug] [-i instance_path] [-m module_file] [-p package_name] cue_tool cue_subcommand extra_args_file packageless_files_file output_file [args...]\n" "$(basename "${0}")" 1>&2
exit 2
}

cue_debug=
instance_path=
module_file=
package_name=

function parse_args() {
while getopts i:m:p: name
while getopts d:i:m:p: name
do
case "${name}" in
d) cue_debug="${OPTARG}";;
i) instance_path="${OPTARG}";;
h) usage;;
m) module_file="${OPTARG}";;
Expand Down Expand Up @@ -101,6 +103,10 @@ if [ -n "${module_file}" ]; then
cd "${module_path}"
fi

if [ -n "${cue_debug}" ]; then
export CUE_DEBUG="${cue_debug}"
fi

# NB: See https://stackoverflow.com/questions/7577052 for the odd
# treatment of the "packageless_file_args" array variable here,
# handling the case where the array winds up empty for lack of
Expand Down
10 changes: 8 additions & 2 deletions cue/cue-run-from-runfiles
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e

function usage() {
printf "usage: %s [-c cue_cache_directory] [-i instance_path] [-m module_file] [-p package_name] cue_tool cue_subcommand extra_args_file packageless_files_file output_file [args...]\n" "$(basename "${0}")" 1>&2
printf "usage: %s [-c cue_cache_directory] [-d cue_debug] [-i instance_path] [-m module_file] [-p package_name] cue_tool cue_subcommand extra_args_file packageless_files_file output_file [args...]\n" "$(basename "${0}")" 1>&2
exit 2
}

cue_cache_directory=
cue_debug=
instance_path=
module_file=
package_name=

function parse_args() {
while getopts c:i:m:p: name
while getopts c:d:i:m:p: name
do
case "${name}" in
c) cue_cache_directory="${OPTARG}";;
d) cue_debug="${OPTARG}";;
i) instance_path="${OPTARG}";;
h) usage;;
m) module_file="${OPTARG}";;
Expand Down Expand Up @@ -103,6 +105,10 @@ elif [ -z "${HOME:-}" ]; then
export CUE_CACHE_DIR="${cue_cache_directory}"
fi

if [ -n "${cue_debug}" ]; then
export CUE_DEBUG="${cue_debug}"
fi

# NB: See https://stackoverflow.com/questions/7577052 for the odd
# treatment of the "packageless_file_args" array variable here,
# handling the case where the array winds up empty for lack of
Expand Down
9 changes: 9 additions & 0 deletions cue/cue.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ def _add_common_output_producing_attrs_to(attrs):
"concatenate_objects": attr.bool(
doc = "Concatenate multiple objects into a list.",
),
"cue_debug": attr.string(
doc = """Debug flags to pass to CUE via the CUE_DEBUG environment variable.

The value is a comma-separated list of debug flags. See CUE documentation
for available debug flags.""",
default = "",
),
# Unfortunately, we can't use a private attribute for an
# implicit dependency here, because we can't fix the default
# label value.
Expand Down Expand Up @@ -517,6 +524,8 @@ _cue_toolchain_type = "//tools/cue:toolchain_type"
def _make_output_producing_action(ctx, cue_subcommand, mnemonic, description, augment_args = None, module_file = None, instance_directory_path = None, instance_package_name = None, cue_cache_directory_path = None):
cue_tool = ctx.toolchains[_cue_toolchain_type].cueinfo.tool
args = ctx.actions.args()
if ctx.attr.cue_debug:
args.add("-d", ctx.attr.cue_debug)
if module_file:
args.add("-m", _runfile_path(ctx, module_file))
if instance_directory_path:
Expand Down
10 changes: 10 additions & 0 deletions test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,13 @@ cue_test(
name = "stamp",
generated_output_file = "//test/testdata/stamp:stamp.json",
)

cue_test(
name = "debug",
generated_output_file = "//test/testdata/debug:debug.json",
)

cue_test(
name = "debug_unsorted",
generated_output_file = "//test/testdata/debug:debug_unsorted.json",
)
24 changes: 24 additions & 0 deletions test/testdata/debug/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
load(
"//cue:cue.bzl",
"cue_exported_standalone_files",
)

exports_files([
"debug-golden.json",
"debug_unsorted-golden.json",
])

# Without cue_debug - fields stay in original order
cue_exported_standalone_files(
name = "debug_unsorted",
srcs = ["debug.cue"],
visibility = ["//test:__subpackages__"],
)

# With cue_debug = "sortfields" - fields are sorted alphabetically
cue_exported_standalone_files(
name = "debug",
srcs = ["debug.cue"],
cue_debug = "sortfields",
visibility = ["//test:__subpackages__"],
)
6 changes: 6 additions & 0 deletions test/testdata/debug/debug-golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"apple": "first fruit",
"banana": "second fruit",
"mango": "middle fruit",
"zebra": "last animal"
}
6 changes: 6 additions & 0 deletions test/testdata/debug/debug.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Fields in non-alphabetical order to test sortfields debug flag
zebra: "last animal"
apple: "first fruit"
mango: "middle fruit"
banana: "second fruit"

6 changes: 6 additions & 0 deletions test/testdata/debug/debug_unsorted-golden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"zebra": "last animal",
"apple": "first fruit",
"mango": "middle fruit",
"banana": "second fruit"
}