forked from ocaml/dune
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for globs in dune-action-plugin.
Signed-off-by: Jakub Staron <jstaron@janestreet.com>
- Loading branch information
Showing
13 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
(library | ||
(name dune_action_plugin) | ||
(public_name dune-action-plugin.dune_action_plugin) | ||
(libraries stdune) | ||
(libraries stdune dune_re) | ||
(synopsis | ||
"Monadic interface for defining scripts with dynamic or complex set of depencencies.")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
open Stdune | ||
open Dune_re | ||
|
||
type t = | ||
{ re : Re.re | ||
; repr : string | ||
} | ||
|
||
let test t = Re.execp t.re | ||
|
||
let of_string repr = | ||
let result = | ||
Glob_lexer.parse_string repr | ||
|> Result.map ~f:(fun re -> { re = Re.compile re; repr }) | ||
in | ||
match result with | ||
| Error (_, msg) -> invalid_arg (Printf.sprintf "invalid glob: :%s" msg) | ||
| Ok t -> t | ||
|
||
let to_string (t : t) = t.repr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(** Simple glob support library. *) | ||
|
||
type t | ||
|
||
(** Tests if string matches the glob. *) | ||
val test : t -> string -> bool | ||
|
||
(** Returns textual representation of a glob. *) | ||
val to_string : t -> string | ||
|
||
(** Converts string to glob. Throws [Invalid_argument] exception if string is | ||
not a valid glob. *) | ||
val of_string : string -> t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...box-tests/test-cases-with-libs/dune-action-plugin/depends-on-directory-with-glob/bin/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executables | ||
(names foo) | ||
(libraries dune-action-plugin.dune_action_plugin)) |
11 changes: 11 additions & 0 deletions
11
...x-tests/test-cases-with-libs/dune-action-plugin/depends-on-directory-with-glob/bin/foo.ml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
open Dune_action_plugin | ||
|
||
let action = | ||
let open Dune_action_plugin.O in | ||
let glob = Glob.of_string "some_file*" in | ||
let+ listing = | ||
read_directory_with_glob ~path:(Path.of_string "some_dir") ~glob | ||
in | ||
String.concat "\n" listing |> print_endline | ||
|
||
let () = run action |
19 changes: 19 additions & 0 deletions
19
...lackbox-tests/test-cases-with-libs/dune-action-plugin/depends-on-directory-with-glob/dune
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(data_only_dirs test) | ||
|
||
(alias | ||
(name run_dynamic) | ||
(deps | ||
(package dune) | ||
(source_tree test/) | ||
(glob_files bin/*.exe)) | ||
(action | ||
(chdir | ||
test | ||
(progn | ||
(run %{bin:cram} -test run.t) | ||
(diff? run.t run.t.corrected))))) | ||
|
||
(alias | ||
(name runtest) | ||
(deps | ||
(alias run_dynamic))) |
42 changes: 42 additions & 0 deletions
42
...x-tests/test-cases-with-libs/dune-action-plugin/depends-on-directory-with-glob/test/run.t
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
$ echo "(lang dune 2.0)" > dune-project | ||
|
||
$ cat > dune << EOF | ||
> (alias | ||
> (name runtest) | ||
> (action (dynamic-run ./foo.exe))) | ||
> EOF | ||
|
||
$ mkdir some_dir | ||
|
||
$ cat > some_dir/dune << EOF | ||
> (rule | ||
> (target some_file) | ||
> (action | ||
> (progn | ||
> (echo "Building some_file!\n") | ||
> (with-stdout-to %{target} (echo ""))))) | ||
> \ | ||
> (rule | ||
> (target another_file) | ||
> (action | ||
> (progn | ||
> (echo "SHOULD NOT BE PRINTED!") | ||
> (with-stdout-to %{target} (echo ""))))) | ||
> \ | ||
> (rule | ||
> (target some_file_but_different) | ||
> (action | ||
> (progn | ||
> (echo "Building some_file_but_different!\n") | ||
> (with-stdout-to %{target} (echo ""))))) | ||
> EOF | ||
|
||
$ cp ../bin/foo.exe ./ | ||
|
||
$ dune runtest --display short | ||
foo alias runtest | ||
Building some_file! | ||
Building some_file_but_different! | ||
foo alias runtest | ||
some_file | ||
some_file_but_different |