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

init: fix non-existing file check in csh #4482

Merged
merged 3 commits into from
Jan 12, 2021
Merged

Conversation

gahr
Copy link
Contributor

@gahr gahr commented Dec 18, 2020

This fixes an issue whereas disabling the hook script by answering "no"
to the 2nd question of "opam init" you end with an init script that
tries to source the non-existing env hook script.

@gahr
Copy link
Contributor Author

gahr commented Dec 21, 2020

I guess the failure in appveyor is not related to my change

C:/projects/opam/bootstrap/ocaml/lib/ocaml/caml/misc.h:409:18: error: static declaration of ‘caml_snprintf’ follows non-static declaration
  409 | #define snprintf caml_snprintf
      |                  ^~~~~~~~~~~~~
C:/projects/opam/bootstrap/ocaml/lib/ocaml/caml/misc.h:408:12: note: previous declaration of ‘caml_snprintf’ was here
  408 | extern int caml_snprintf(char * buf, size_t size, const char * format, ...);
      |            ^~~~~~~~~~~~~

@rjbou
Copy link
Collaborator

rjbou commented Dec 22, 2020

Thanks for the PR.
On the issue you mention, do you have a failing log ?
Because it's not important that the script is written or no. In the init.sh (that is sourced in *shrc), there is a test on the availability of the script to source.
A sh generated one gives:

$ cat /tmp/opamroot/opam-init/init.sh
if [ -t 0 ]; then
  test -r /tmp/opamroot/opam-init/complete.sh && . /tmp/opamroot/opam-init/complete.sh > /dev/null 2> /dev/null || true

  test -r /tmp/opamroot/opam-init/env_hook.sh && . /tmp/opamroot/opam-init/env_hook.sh > /dev/null 2> /dev/null || true
fi

test -r /tmp/opamroot/opam-init/variables.sh && . /tmp/opamroot/opam-init/variables.sh > /dev/null 2> /dev/null || true

@gahr
Copy link
Contributor Author

gahr commented Dec 22, 2020

Ah thanks, I hadn't noticed the attemp to handle a non-existing file in init.(c)sh. That attempt is broken for csh, though.

Printf.sprintf "source %s >& /dev/null || true\n" (file f)

It tries to handle the error using || true, but in csh (citing the man page) "An error in a source at any level terminates all nested source commands." This causes a termination in sourcing the startup file ~/.cshrc.

I'll update the PR to properly check for the file existence in init.csh.

@gahr gahr force-pushed the fix-no-env-hook branch 2 times, most recently from 84402ad to f2db3e1 Compare December 22, 2020 16:01
@gahr gahr changed the title init: do not source env_hook script if not enabled init: fix non-existing file check in csh Dec 22, 2020
In csh, a failed "source" command propagates up the stack and causes all
the nesting "source" commands to fail. This makes the `|| true` check
useless.
@gahr
Copy link
Contributor Author

gahr commented Jan 11, 2021

@rjbou need anything from my side?

@dra27 dra27 merged commit 9d31f5b into ocaml:master Jan 12, 2021
@dra27
Copy link
Member

dra27 commented Jan 12, 2021

Thanks!

@rjbou rjbou added this to PR in Progress in Opam 2.1.x via automation Jan 12, 2021
@rjbou rjbou added this to the 2.1.0~beta4 milestone Jan 12, 2021
@rjbou
Copy link
Collaborator

rjbou commented Jan 12, 2021

Oops, forgot to see the new version. lgtm, thanks @gahr!

@rjbou rjbou moved this from PR in Progress to PR Finalised in Opam 2.1.x Jan 12, 2021
@rjbou rjbou moved this from PR Finalised to Done in Opam 2.1.x Jan 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Opam 2.1.x
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants