ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.64k stars 409 forks source link

Provide a copy_files_rec version of copy_files #11182

Open rlepigre opened 2 days ago

rlepigre commented 2 days ago

Desired Behavior

Assume I have a directory structure like the following, with files with the .d and .v extension:

a
├── a.d
├── a.v
├── b
│   ├── ab.d
│   ├── ab.v
│   └── c
│       ├── abc.d
│       └── abc.v
└── d
    ├── ad.d
    └── ad.v

Now, I would like to be able to do something like:

(subdir gen
 (copy_files_rec
  (files ../a/**.v)))

so that dune effectively copies all files with the .v extension in directory a into the directory gen.

Additionally, I would also like to have the option to preserve the directory structure when doing the copy (i.e., files like gen/a/b/c/abc.v would be produced). This would be very useful in combination with (include_subdirs qualified) in the context of Coq projects.

Example

For example, I would expect the following to work.


mkdir -p a/b/c a/d
touch a/a.v a/b/ab.v a/b/c/abc.v a/d/ad.v
touch a/a.d a/b/ab.d a/b/c/abc.d a/d/ad.d

echo "(lang dune 3.18)" > dune-project
cat > dune <<<EOF
(subdir gen_flat
 (copy_files_rec
  (files ../a/**.v)))

(subdir gen_flat
 (copy_files_rec
  (files ../a/**.v)
  (preserve_dir_structure)))
EOF
rlepigre commented 2 days ago

Note that this is related to https://github.com/ocaml/dune/issues/3387, but slightly different.