Module B0_srcs

Select source files.

This module provides a type to select source files for build units in B0 files. To support generated source files, selections can depend on the build.

In a nutshell the declaration:

let srcs = [ `Dir "src-exe"; `Dir_rec "src"; `X "src/"; `X "src/not"]

instructs to:

Relative file paths are expressed relative to the build unit's root directory.

The prefix relation for exclusions respects path segments boundaries. In the example any file whose path matches src/, src/*, src/not or src/not/* is excluded from the selection. But for example src/not.c is not.

The relative order of directory selections and exclusions doesn't matter, the semantics is to select all the files via `Dir and `Dir_rec and then apply the exclusion `X on the resulting set. Exclusions affect only directory selections, not file `File and future `Future selections.

When a directory is selected via `Dir or `Dir_rec, all its files are, modulo exclusions. It is expected that build units themselves filter the final result by file extension or additional mechanisms. Consult the documentation of build units for more information.

Source selection

type fpath = string

The type for file paths. Must be convertible with B00_std.Fpath.of_string. We do not use B00_std.Fpath directly to allow for a lighter syntax in B0 files.

Important. Use only "/" as the directory separator even on Windows® platforms. Don't be upset the UI gives them back to you using the local platform separator.

val fpath : B00_std.Fpath.t -> fpath

fpath is B00_std.Fpath.to_string. If you prefer to specify your paths the clean way. TODO remove ?

type sel = [
| `Dir of fpath
| `Dir_rec of fpath
| `X of fpath
| `File of fpath
| `Fut of B0_build.t -> B00_std.Fpath.Set.t B00_std.Fut.t

The type for file selectors.

  • `File f unconditionaly selects the file f. f must exist and be a file.
  • `Dir d selects the files of directory d modulo `X exclusions. d must exist and be a directory. dotfile paths are ignored.
  • `Dir_rec d selects the files of the file hierarchy rooted at d modulo `X exclusions. d must exist and be a directory. dotfile paths are ignored.
  • `X x removes from directory selections any file whose path segments are prefixed by x, respecting segment boundaries. A potential trailing directory separators in x is removed.
  • `Fut f uses the given future during the build to determine a set of files unconditionally added to the selection.

Except for `Fut, any relative path is made absolute to the current build unit with B0_build.Unit.root_dir.

type t = sel list

The type for source selection.

val select : B0_build.t -> t -> B00_std.Fut.t

select b sels selects in b the sources specified by sels and returns them mapped by their file extension (not multiple file extension). Each file is guaranteed to appear only once in the map.

Important. All files in the map that were selected via `File, `D and `D_rec are automatically made ready in the build. For those selected via `Fut readyness determination is left to the invoked funtion.

FIXME. Provide ordering guarantes and avoid non-det from the fs. We likely don't want to return only file extension map.