diff options
author | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-04-14 12:20:55 +0200 |
---|---|---|
committer | Klaus Aehlig <klaus.aehlig@huawei.com> | 2023-04-14 14:37:07 +0200 |
commit | 2fa19d98f7e4024da9dc6c9bb8f0071f966c3ae7 (patch) | |
tree | 83657ce4b5322138a5e53d90d64dc3024dd553f1 /test | |
parent | ec4820b68c6c6957cf621f5339164ff28861ef1d (diff) | |
download | justbuild-2fa19d98f7e4024da9dc6c9bb8f0071f966c3ae7.tar.gz |
just-mr support -D option
Make just-mr unconditionally support an option -D that collects a
configuration overlay and forwards it to the invocation of a just
subcommand that supports this option. This syntax-switching facility
makes it easy to embedd dynamic parts of the configuration (like
the head commit to be part of a version string) as those information
can unconditionally be the first argument to just-mr.
Diffstat (limited to 'test')
-rw-r--r-- | test/end-to-end/just-mr/defaults.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/end-to-end/just-mr/defaults.sh b/test/end-to-end/just-mr/defaults.sh index 77febef2..de641ab2 100644 --- a/test/end-to-end/just-mr/defaults.sh +++ b/test/end-to-end/just-mr/defaults.sh @@ -63,9 +63,13 @@ parser.add_argument("-f", "--log-file", dest="log_file", parser.add_argument("--log-limit", dest="log_limit") parser.add_argument("--log-append", dest="log_append", action="store_true", default=False) +parser.add_argument("-D", "--defines", dest="defines", + action="append", default=[]) (options, args) = parser.parse_known_args(sys.argv[2:]) target_dir=args[-1] +with open(os.path.join(target_dir, "defines"), "w") as f: + f.write(json.dumps([json.loads(x) for x in options.defines])) with open(os.path.join(target_dir, "log-limit"), "w") as f: f.write(json.dumps(options.log_limit)) with open(os.path.join(target_dir, "log-file"), "w") as f: @@ -141,4 +145,29 @@ test $(jq '. == ["cmd", "line", "launcher"] ' "${PARSE_DIR}/launcher") = "true" build "${PARSE_DIR}" 2>&1 test "$(cat "${PARSE_DIR}/launcher")" = 'null' +## Command-line -D + +# ignored on non-build commands +"${JUST_MR}" --local-build-root "${LBR}" --just "${PARSE}" \ + -D 'this is not json' version "${PARSE_DIR}" 2>&1 +test $(jq '. == [] ' "${PARSE_DIR}/defines") = "true" + +# not forwarded, if empty +"${JUST_MR}" --local-build-root "${LBR}" --just "${PARSE}" \ + -D '{}' build "${PARSE_DIR}" 2>&1 +test $(jq '. == [] ' "${PARSE_DIR}/defines") = "true" + +# combined on forwarding +"${JUST_MR}" --local-build-root "${LBR}" --just "${PARSE}" \ + -D '{"foo": "bar"}' -D '{"baz": "baz"}' -D '{"foo": "override"}' \ + build "${PARSE_DIR}" 2>&1 +test $(jq '. == [ {"foo": "override", "baz": "baz"}] ' "${PARSE_DIR}/defines") = true + +# but passed arguments are given separately + +"${JUST_MR}" --local-build-root "${LBR}" --just "${PARSE}" \ + -D '{"foo": "bar"}' -D '{"baz": "baz"}' \ + build -D '{"foo": "override"}' -D '{"x": "y"}' "${PARSE_DIR}" 2>&1 +test $(jq '. == [ {"foo": "bar", "baz": "baz"}, {"foo": "override"}, {"x": "y"}] ' "${PARSE_DIR}/defines") = true + echo OK |