diff --git a/doc/project-layout-specification.rst b/doc/project-layout-specification.rst index ad5b42a3..4baead69 100644 --- a/doc/project-layout-specification.rst +++ b/doc/project-layout-specification.rst @@ -111,9 +111,14 @@ will be automatically installed as well. jbuild-ignore ============= -By default Jbuilder traverses the whole source tree. To ignore a -subtree, simply write a ``jbuild-ignore`` file in the parent directory -containing the name of the sub-directories to ignore. +By default Jbuilder traverses the whole source tree, ignoring the +following files and directories: + +- any file that start with ``.#`` +- any directory that start with either ``.`` or ``_`` + +To ignore a subtree, simply write a ``jbuild-ignore`` file in the +parent directory containing the name of the sub-directories to ignore. So for instance, if you write ``foo`` in ``src/jbuild-ignore``, then ``src/foo`` won't be traversed and any ``jbuild`` file it contains will diff --git a/src/file_tree.ml b/src/file_tree.ml index 0033bc41..29b2c544 100644 --- a/src/file_tree.ml +++ b/src/file_tree.ml @@ -35,25 +35,24 @@ type t = let root t = t.root -let ignore_file = function - | "" - | "_opam" - | "_build" - | ".git" - | ".hg" - | "_darcs" - | "." -> true - | fn -> fn.[0] = '.' && fn.[1] = '#' +let ignore_file fn ~is_directory = + fn = "" || fn = "." || + (is_directory && (fn.[0] = '.' || fn.[0] = '_')) || + (fn.[0] = '.' && fn.[1] = '#') let load path = let rec walk path : Dir.t = let files, sub_dirs = Path.readdir path - |> List.filter ~f:(fun fn -> - not (ignore_file fn)) - |> List.partition_map ~f:(fun fn -> - let path = Path.relative path fn in - if Path.exists path && Path.is_directory path then + |> List.filter_map ~f:(fun fn -> + let path = Path.relative path fn in + let is_directory = Path.exists path && Path.is_directory path in + if ignore_file fn ~is_directory then + None + else + Some (fn, path, is_directory)) + |> List.partition_map ~f:(fun (fn, path, is_directory) -> + if is_directory then Inr (fn, walk path) else Inl fn)