-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We add a (concurrent ) action which acts like (progn ) the difference being the actions contained within can be executed concurrently by Dune. <!-- ps-id: 28962076-9451-4253-be23-14d44a88eec0 --> Signed-off-by: Ali Caglayan <alizter@gmail.com>
- Loading branch information
Showing
22 changed files
with
231 additions
and
15 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
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
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
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
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/A
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 @@ | ||
I am file A. |
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/B
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 @@ | ||
I am file B. |
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/C
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 @@ | ||
I am file C. |
1 change: 1 addition & 0 deletions
1
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/dune-project
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 @@ | ||
(lang dune 3.7) |
84 changes: 84 additions & 0 deletions
84
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/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,84 @@ | ||
The use of (concurrent ) illustrated in the context of diffing multiple files. | ||
|
||
Say we want to diff 3 files. | ||
$ cat A | ||
I am file A. | ||
$ cat B | ||
I am file B. | ||
$ cat C | ||
I am file C. | ||
|
||
We set up a (progn ) rule to diff all of them against their generated versions. | ||
|
||
$ cat > dune << EOF | ||
> (rule | ||
> (action | ||
> (progn | ||
> (with-outputs-to A.diff (echo "I am file A.\n")) | ||
> (with-outputs-to B.diff (echo "I am certainly file B.\n")) | ||
> (with-outputs-to C.diff (echo "I am most certainly file C.\n"))))) | ||
> | ||
> (rule | ||
> (action | ||
> (progn | ||
> (with-outputs-to some-target (echo a)) | ||
> (diff %{dep:A} %{dep:A.diff}) | ||
> (diff %{dep:B} %{dep:B.diff}) | ||
> (diff %{dep:C} %{dep:C.diff})))) | ||
> EOF | ||
|
||
We can now run the rule and see that we fail before diffing C. | ||
|
||
$ dune build | ||
File "B", line 1, characters 0-0: | ||
Error: Files _build/default/B and _build/default/B.diff differ. | ||
[1] | ||
|
||
We can check which diffs were run by asking Dune to promote the files. | ||
|
||
$ dune promotion apply | ||
Promoting _build/default/B.diff to B. | ||
|
||
Since we failed early, only B was promoted. | ||
|
||
Let's reset B to its original state. | ||
|
||
$ rm B | ||
$ cat > B << EOF | ||
> I am file B. | ||
> EOF | ||
|
||
If we implement the rule using (concurrent ) instead. | ||
|
||
$ cat > dune << EOF | ||
> (rule | ||
> (action | ||
> (progn | ||
> (with-outputs-to A.diff (echo "I am file A.\n")) | ||
> (with-outputs-to B.diff (echo "I am certainly file B.\n")) | ||
> (with-outputs-to C.diff (echo "I am most certainly file C.\n"))))) | ||
> | ||
> (rule | ||
> (action | ||
> (concurrent | ||
> (with-outputs-to some-target (echo a)) | ||
> (diff %{dep:A} %{dep:A.diff}) | ||
> (diff %{dep:B} %{dep:B.diff}) | ||
> (diff %{dep:C} %{dep:C.diff})))) | ||
> EOF | ||
|
||
We see that all the files get diffed. | ||
|
||
$ dune build | ||
File "B", line 1, characters 0-0: | ||
Error: Files _build/default/B and _build/default/B.diff differ. | ||
File "C", line 1, characters 0-0: | ||
Error: Files _build/default/C and _build/default/C.diff differ. | ||
[1] | ||
|
||
And we have promotions for the two that failed. | ||
|
||
$ dune promote | ||
Promoting _build/default/B.diff to B. | ||
Promoting _build/default/C.diff to C. | ||
|
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,62 @@ | ||
Specification of the concurrency action: | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.7) | ||
> EOF | ||
|
||
$ cat > dune << EOF | ||
> (rule | ||
> (action | ||
> (concurrent ))) | ||
> EOF | ||
|
||
$ dune build | ||
File "dune", line 3, characters 2-15: | ||
3 | (concurrent ))) | ||
^^^^^^^^^^^^^ | ||
Error: 'concurrent' is only available since version 3.8 of the dune language. | ||
Please update your dune-project file to have (lang dune 3.8). | ||
[1] | ||
|
||
Requires Dune 3.8. | ||
|
||
$ cat > dune-project << EOF | ||
> (lang dune 3.8) | ||
> EOF | ||
|
||
(concurrent ...) runs actions concurrently. Here we mock up an example where two | ||
subactions rely on eachother to also be running in order to terminate. | ||
|
||
We write a shell script that will similtaneously read and write to two named | ||
pipes. (This has to be similtaneious otherwise the read will block the write). | ||
They will block on the read however, which means if called with the same two | ||
pipes but swapped, they will only terminate when both scripts are running at the | ||
same time. | ||
$ cat > run.sh << EOF | ||
> #!/bin/bash | ||
> echo foo>\$1 & read line<\$2 | ||
> EOF | ||
$ chmod +x run.sh | ||
$ cat run.sh | ||
#!/bin/bash | ||
echo foo>$1 & read line<$2 | ||
We create an action that will create named pipes a and b and then run our script | ||
on both of them, but importantly inside the concurrent action. This will | ||
demonstrate that subactions are indeed being run concurrently. | ||
$ cat > dune << EOF | ||
> (rule | ||
> (alias my-rule) | ||
> (action | ||
> (progn | ||
> (run mkfifo a b) | ||
> (concurrent | ||
> (run ./run.sh a b) | ||
> (run ./run.sh b a))))) | ||
> EOF | ||
|
||
When we run the rule, we see that the two actions are indeed run concurrently. | ||
$ dune build -j2 @my-rule --force | ||
|
||
Notice the need for a -j2. If Dune was configured with -j1 then the action would | ||
never terminate. |
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
Oops, something went wrong.