fix: find and source ~/.jq file on windows (fixes #3104) (#3114)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kirk McKelvey · committed by GitHub · parent da2a0b9 · Browse files · 4 files·+20 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+20 added−6 removed
- tests:+11 added−0 removed
- other:+9 added−6 removed
Provenance
- Commit
6322b99- Tree
987848b- Author
Kirk McKelvey <kirkoman@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
da2a0b9
4 files changed+20 added−6 removed
modified:docs/content/manual/dev/manual.yml+2 added-1 removed
3689 unmodified lines3690 3691 For example, with `-L$HOME/.jq` a module `foo` can be found in3692 `$HOME/.jq/foo.jq` and `$HOME/.jq/foo/foo.jq`.3693 3694- If `$HOME/.jq` is a file, it is sourced into the main program.3694+ If `.jq` exists in the user's home directory, and is a file (not a3695+ directory), it is automatically sourced into the main program.3696 3697 entries:3698 - title: "`import RelativePathString as NAME [<metadata>];`"3699 body: |113 unmodified linesmodified:src/linker.c+6 added-4 removed
418 unmodified lines419 block_free(program);420 return 1;421 }422 423- char* home = getenv("HOME");424- if (home) { // silently ignore no $HOME425- /* Import ~/.jq as a library named "" found in $HOME */423+ jv home = get_home();424+ if (jv_is_valid(home)) {425+ /* Import ~/.jq as a library named "" found in $HOME or %USERPROFILE% */426 block import = gen_import_meta(gen_import("", NULL, 0),427 gen_const(JV_OBJECT(428 jv_string("optional"), jv_true(),429- jv_string("search"), jv_string(home))));429+ jv_string("search"), home)));430 program = BLOCK(import, program);431+ } else { // silently ignore if home dir not determined432+ jv_free(home);433 }434 435 nerrors = process_dependencies(jq, jq_get_jq_origin(jq), jq_get_prog_origin(jq), &program, &lib_state);436 block libs = gen_noop();16 unmodified linesmodified:tests/shtest+11 added
357 unmodified lines358 echo "Bug #479 appears to be back" 1>&2359 exit 1360 fi361 362+if $msys || $mingw; then363+ HOME_BAK=$HOME364+ unset HOME365+ if [ "$(USERPROFILE="$mods/home1" $VALGRIND $Q $JQ -nr foo)" != baz ]; then366+ echo "Bug #3104 regressed (sourcing %USERPROFILE%/.jq on Windows)" 1>&2367+ exit 1368+ fi369+ export HOME=$HOME_BAK370+ unset HOME_BAK371+fi372+373 if [ $(HOME="$mods/home1" $VALGRIND $Q $JQ --debug-dump-disasm -n fg | grep '^[a-z]' | wc -l) -ne 3 ]; then374 echo "Binding too many defs into program" 1>&2375 exit 1376 fi327 unmodified linesmodified:jq.1.prebuilt+1 added-1 removed
4107 unmodified lines4108 .P4109 For example, with \fB\-L$HOME/\.jq\fR a module \fBfoo\fR can be found in \fB$HOME/\.jq/foo\.jq\fR and \fB$HOME/\.jq/foo/foo\.jq\fR\.4110 .4111 .P4112-If \fB$HOME/\.jq\fR is a file, it is sourced into the main program\.4112+If \fB\.jq\fR exists in the user\'s home directory, and is a file (not a directory), it is automatically sourced into the main program\.4113 .4114 .SS "import RelativePathString as NAME [<metadata>];"4115 Imports a module found at the given path relative to a directory in a search path\. A \fB\.jq\fR suffix will be added to the relative path string\. The module\'s symbols are prefixed with \fBNAME::\fR\.4116 .132 unmodified lines