ocaml / ocamlbuild

The legacy OCamlbuild build manager
Other
121 stars 81 forks source link

Should ignore `_opam` directory by default #257

Closed edwintorok closed 7 years ago

edwintorok commented 7 years ago

With opam 2.0.0~beta3:

opam2 switch create `pwd` ocaml-system
eval $(opam2 env --switch=`pwd`)
opam2 install ocamlfind
touch x.ml
echo '<**/*>: warn_a' >_tags
ocamlbuild -use-ocamlfind x.native

I get hygiene errors from _opam (note the use of **/ in _tags, without a _tags file ocamlbuild doesn't attempt to look deeply inside _opam and doesn't complain):

SANITIZE: a total of 18 files that should probably not be in your source tree
  has been found. A script shell file "/tmp/o/_build/sanitize.sh" is being
  created. Check this script and run it to remove unwanted files or use other
  options (such as defining hygiene exceptions or using the -no-hygiene
  option).
IMPORTANT: I cannot work with leftover compiled files.
ERROR: Leftover OCaml compilation files:
  File num_top.cmi in _opam/lib/num-top has suffix .cmi
  File num_top_printers.cmi in _opam/lib/num-top has suffix .cmi
  File num_top.cma in _opam/lib/num-top has suffix .cma
ERROR: Leftover object files:
  File findlib.a in _opam/lib/findlib has suffix .a
  File findlib_top.a in _opam/lib/findlib has suffix .a
  File findlib_dynload.a in _opam/lib/findlib has suffix .a
ERROR: Leftover OCaml compilation files:
  File findlib.cmi in _opam/lib/findlib has suffix .cmi
  File topfind.cmi in _opam/lib/findlib has suffix .cmi
  File fl_package_base.cmi in _opam/lib/findlib has suffix .cmi
  File fl_metascanner.cmi in _opam/lib/findlib has suffix .cmi
  File fl_metatoken.cmi in _opam/lib/findlib has suffix .cmi
  File fl_dynload.cmi in _opam/lib/findlib has suffix .cmi
  File findlib.cma in _opam/lib/findlib has suffix .cma
  File findlib_top.cma in _opam/lib/findlib has suffix .cma
  File findlib_dynload.cma in _opam/lib/findlib has suffix .cma
  File findlib.cmxa in _opam/lib/findlib has suffix .cmxa
  File findlib_top.cmxa in _opam/lib/findlib has suffix .cmxa
  File findlib_dynload.cmxa in _opam/lib/findlib has suffix .cmxa
Exiting due to hygiene violations.
Compilation unsuccessful after building 0 targets (0 cached) in 00:00:00.

One can use -X _opam to avoid this, but would be nice if ocamlbuild did this automatically.

gasche commented 7 years ago

The part I needed (from the topkg issue) is "why do we have an _opam directory in a project?"). The answer is "this is how opam local switches work", which is a perfectly good reason to special-case them and have them in the default include list.

Would you like to provide a PR for this? (There are two different places in the codebase where exclude directories are mentioned, but just grepping for ".git" or "_darcs" should let you locate them.) It's an easy fix so I can also do it. (Remember to edit the Changes file.)

edwintorok commented 7 years ago

Thanks, I was actually a bit confused in trying to reproduce this, because without the _tags file everything just worked. If you want to make the change please do it, I'm about to go on a vacation :)

gasche commented 7 years ago

Will do. Have good vacations!