Skip to content

Commit

Permalink
Rename subdirs to dirs
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Nov 29, 2018
1 parent 65c0ef4 commit f0b7598
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ next

- Add predicate language support for specifying sub directories. This allows the
use globs, set operations, and special values in specifying the sub
directories used for the build. For example: `(subdirs :standard \ lib*)` will
directories used for the build. For example: `(dirs :standard \ lib*)` will
use all directories except those that start with `lib`. (#1517, #1568,
@rgrinberg)

Expand Down
4 changes: 2 additions & 2 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ Fields supported in ``<settings>`` are:

.. _dune-subdirs:

subdirs (since 1.6)
dirs (since 1.6)
-------------------

The ``subdirs`` stanza allows to tell specify the sub-directories dune will
Expand Down Expand Up @@ -877,7 +877,7 @@ instead of this stanza. For example:

.. code:: scheme
(subdirs :standard \ <sub-dir1> <sub-dir2> ...)
(dirs :standard \ <sub-dir1> <sub-dir2> ...)
.. _include_subdirs:

Expand Down
38 changes: 16 additions & 22 deletions src/sub_dirs.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open! Stdune

type 'set t =
{ sub_dirs : 'set
{ dirs : 'set
; data_only : 'set
}

Expand All @@ -11,34 +11,31 @@ let default =
| "" -> false
| s -> s.[0] <> '.' && s.[0] <> '_')
in
{ sub_dirs = standard_dirs
{ dirs = standard_dirs
; data_only = Predicate_lang.empty
}

let make ~sub_dirs ~data_only ~ignored_sub_dirs =
let sub_dirs =
Option.value sub_dirs ~default:default.sub_dirs in
let make ~dirs ~data_only ~ignored_sub_dirs =
let dirs = Option.value dirs ~default:default.dirs in
let data_only =
let data_only = Option.value data_only ~default:default.data_only in
Predicate_lang.union (data_only :: ignored_sub_dirs)
in
{ sub_dirs ; data_only }
{ dirs ; data_only }

let add_data_only_dirs t ~dirs =
{ t with data_only =
Predicate_lang.union
[t.data_only; (Predicate_lang.of_string_set dirs)] }

let eval t ~dirs =
let sub_dirs =
Predicate_lang.filter t.sub_dirs ~standard:default.sub_dirs dirs
in
let dirs = Predicate_lang.filter t.dirs ~standard:default.dirs dirs in
let data_only =
Predicate_lang.filter t.data_only ~standard:default.data_only sub_dirs
Predicate_lang.filter t.data_only ~standard:default.data_only dirs
|> String.Set.of_list
in
let sub_dirs = String.Set.of_list sub_dirs in
{ sub_dirs
let dirs = String.Set.of_list dirs in
{ dirs
; data_only
}

Expand All @@ -47,9 +44,7 @@ module Status = struct
end

let status t ~dir =
match String.Set.mem t.sub_dirs dir
, String.Set.mem t.data_only dir
with
match String.Set.mem t.dirs dir, String.Set.mem t.data_only dir with
| true, false -> Status.Normal
| true, true -> Data_only
| false, false -> Ignored
Expand Down Expand Up @@ -89,25 +84,24 @@ let decode =
Predicate_lang.decode
in
let decode =
let%map ignored_sub_dirs =
multi_field "ignored_subdirs" ignored_sub_dirs
let%map dirs = field_o "dirs" (located plang)
and data_only = field_o "data_only_dirs" (located plang)
and sub_dirs = field_o "subdirs" (located plang)
and ignored_sub_dirs = multi_field "ignored_subdirs" ignored_sub_dirs
and rest = leftover_fields
in
match data_only, sub_dirs, ignored_sub_dirs with
match data_only, dirs, ignored_sub_dirs with
| None, Some (loc, _), _::_ ->
Errors.fail loc
"Cannot have both sub_dirs and ignored_subdirs \
"Cannot have both dirs and ignored_subdirs \
stanza in a dune file. "
| Some (loc, _), None, _::_ ->
Errors.fail loc
"Cannot have both data_only_dirs and ignored_subdirs \
stanza in a dune file. "
| _ ->
let sub_dirs = Option.map ~f:snd sub_dirs in
let dirs = Option.map ~f:snd dirs in
let data_only = Option.map ~f:snd data_only in
( make ~sub_dirs ~data_only ~ignored_sub_dirs
( make ~dirs ~data_only ~ignored_sub_dirs
, rest
)
in
Expand Down
2 changes: 1 addition & 1 deletion src/sub_dirs.mli
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
open Stdune

type 'set t = private
{ sub_dirs : 'set
{ dirs : 'set
; data_only : 'set
}

Expand Down
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/ignored_subdirs/1.6/dune
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(subdirs real)
(dirs real)
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/ignored_subdirs/glob/dune
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(subdirs (:standard \ garbage*))
(dirs (:standard \ garbage*))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(subdirs (and :standard (or foo bar)))
(dirs (and :standard (or foo bar)))

0 comments on commit f0b7598

Please sign in to comment.