-
Notifications
You must be signed in to change notification settings - Fork 443
feature: concurrency action #6933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rgrinberg
merged 4 commits into
ocaml:main
from
Alizter:ps/rr/feature__concurrency_action
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.8) |
84 changes: 84 additions & 0 deletions
84
test/blackbox-tests/test-cases/actions/concurrent-multi-diff.t/run.t
This file contains hidden or 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. | ||
Alizter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
We set up a (progn ) rule to diff all of them against their generated versions. | ||
Alizter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$ 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 A A.diff) | ||
> (diff B B.diff) | ||
> (diff C 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. | ||
Alizter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
$ 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 A A.diff) | ||
> (diff B B.diff) | ||
> (diff C 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 hidden or 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,59 @@ | ||
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. | ||
snowleopard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
We write a shell script that will similtaneously read and write to two named | ||
snowleopard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pipes. (This has to be similtaneious otherwise the read will block the write). | ||
snowleopard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
||
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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.