Last active
March 18, 2016 23:30
-
-
Save colin-kiegel/40432d62c70c2ddf7354 to your computer and use it in GitHub Desktop.
cargo-wait
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
#!/bin/bash | |
# This FIRST WRAPPER only calls cargo - but it has a different name, so we can search for its PID in the second wrapper | |
# | |
# This is only meant to be called by cargo-wait (=second wrapper) | |
/usr/local/bin/cargo $@ |
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
#!/bin/bash | |
# This SECOND WRAPPER script waits for existing runs of cargo-exec (=first wrapper) to finish | |
# | |
# This is meant to be called instead of cargo to avoid concurrency issues | |
function getpid() { | |
# get all process IDs, and trim whitespaces - i.e. result is equivalent to | |
# echo "$PID1 $PID2 .. $PIDXy" | |
ps -C $PROCESS -o pid= | tr -d "[:blank:]" | sed ':a;N;$!ba;s/\n/ /g' | |
} | |
PROCESS="cargo-exec" | |
PID=$(getpid) | |
if [ -n "$PID" ]; then | |
echo -n "Waiting for $PROCESS to finish (PID: $PID)" | |
while [ -n "$PID" ]; do | |
echo -n "." | |
sleep 1 | |
PID=$(getpid) | |
done | |
echo "DONE" | |
fi | |
$PROCESS $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Setup (Linux)
Step 1
You can now use cargo-wait for safe concurrent calls to cargo.
Step 2 (optional)
If you want to shadow the cargo binary (for third party tools like IDE-extensions) - I suggest to do this for each user individually:
First make sure ~/bin is in your PATH in ~/.profile, then: