Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --config option printing ./configure options used #2817

Merged
merged 1 commit into from
Aug 19, 2023
Merged
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
14 changes: 10 additions & 4 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ ACLOCAL_AMFLAGS = -I config/m4
# header file creation so we'll use good old make
if MAINTAINER_MODE
BUILT_SOURCES = src/lexer.h src/lexer.c src/parser.h src/parser.c \
src/builtin.inc src/version.h
src/builtin.inc src/config_opts.inc src/version.h
src/lexer.c: src/lexer.l
$(AM_V_LEX) flex -o src/lexer.c --header-file=src/lexer.h $<
src/lexer.h: src/lexer.c
else
BUILT_SOURCES = src/builtin.inc src/version.h
BUILT_SOURCES = src/builtin.inc src/config_opts.inc src/version.h
.y.c:
$(AM_V_YACC) echo "NOT building parser.c!"
.l.c:
Expand Down Expand Up @@ -109,14 +109,20 @@ generate_ver = ver="`{ $(srcdir)/scripts/version || echo '$(VERSION)' ; } | sed
src/version.h: .remake-version-h
mkdir -p src
$(AM_V_GEN) $(generate_ver); echo "$$ver" > $@
src/main.c: src/version.h
src/config_opts.inc:
mkdir -p src
$(AM_V_GEN) if test -x ./config.status; then \
./config.status --config; \
else echo "(unknown)"; \
fi | sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/"/' -e 's/^/#define JQ_CONFIG /' > $@
src/main.c: src/version.h src/config_opts.inc

src/builtin.inc: $(srcdir)/src/builtin.jq
mkdir -p src
$(AM_V_GEN) sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/"/' -e 's/$$/\\n"/' $(srcdir)/src/builtin.jq > $@
src/builtin.o: src/builtin.inc

CLEANFILES = src/version.h .remake-version-h src/builtin.inc
CLEANFILES = src/version.h .remake-version-h src/builtin.inc src/config_opts.inc

bin_PROGRAMS = jq
jq_SOURCES = src/main.c src/version.h
Expand Down
19 changes: 19 additions & 0 deletions docs/content/manual/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@ sections:

Output the jq version and exit with zero.

* `--build-configuration`:

Output the build configuration of jq and exit with zero.
This output has no supported format or structure and may change
without notice in future releases.

* `--help` / `-h`:

Output the jq help and exit with zero.
Expand Down Expand Up @@ -1968,6 +1974,19 @@ sections:
output:
- '[{"a":{"b":2}}]'

- title: "`$JQ_BUILD_CONFIGURATION`"
body: |

This builtin binding shows the jq executable's build
configuration. Its value has no particular format, but
it can be expected to be at least the `./configure`
command-line arguments, and may be enriched in the
future to include the version strings for the build
tooling used.

Note that this can be overriden in the command-line
with `--arg` and related options.

- title: "`$ENV`, `env`"
body: |

Expand Down
12 changes: 12 additions & 0 deletions jq.1.prebuilt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ extern void jv_tsd_dtoa_ctx_init();
#include "jv_alloc.h"
#include "util.h"
#include "src/version.h"
#include "src/config_opts.inc"

int jq_testsuite(jv lib_dirs, int verbose, int argc, char* argv[]);

Expand Down Expand Up @@ -106,6 +107,7 @@ static void usage(int code, int keep_it_short) {
" -b, --binary open input/output streams in binary mode;\n"
#endif
" -V, --version show the version;\n"
" --build-configuration show jq's build configuration;\n"
" -h, --help show the help;\n"
" -- terminates argument processing;\n\n"
"Named arguments are also available as $ARGS.named[], while\n"
Expand Down Expand Up @@ -580,6 +582,11 @@ int main(int argc, char* argv[]) {
ret = JQ_OK;
goto out;
}
if (isoption(argv[i], 0, "build-configuration", &short_opts)) {
printf("%s\n", JQ_CONFIG);
ret = JQ_OK;
goto out;
}
if (isoption(argv[i], 0, "run-tests", &short_opts)) {
i++;
// XXX Pass program_arguments, even a whole jq_state *, through;
Expand Down Expand Up @@ -677,6 +684,10 @@ int main(int argc, char* argv[]) {
ARGS = JV_OBJECT(jv_string("positional"), ARGS,
jv_string("named"), jv_copy(program_arguments));
program_arguments = jv_object_set(program_arguments, jv_string("ARGS"), jv_copy(ARGS));
if (!jv_object_has(jv_copy(program_arguments), jv_string("JQ_BUILD_CONFIGURATION")))
program_arguments = jv_object_set(program_arguments,
jv_string("JQ_BUILD_CONFIGURATION"),
jv_string(JQ_CONFIG)); /* named arguments */
compiled = jq_compile_args(jq, skip_shebang(jv_string_value(data)), jv_copy(program_arguments));
free(program_origin);
jv_free(data);
Expand All @@ -685,6 +696,10 @@ int main(int argc, char* argv[]) {
ARGS = JV_OBJECT(jv_string("positional"), ARGS,
jv_string("named"), jv_copy(program_arguments));
program_arguments = jv_object_set(program_arguments, jv_string("ARGS"), jv_copy(ARGS));
if (!jv_object_has(jv_copy(program_arguments), jv_string("JQ_BUILD_CONFIGURATION")))
program_arguments = jv_object_set(program_arguments,
jv_string("JQ_BUILD_CONFIGURATION"),
jv_string(JQ_CONFIG)); /* named arguments */
compiled = jq_compile_args(jq, program, jv_copy(program_arguments));
}
if (!compiled){
Expand Down