use wait-for.sh to fix nix/clean.sh race condition

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-08-20 15:45:41 -04:00
parent 8c9af1ab51
commit 06dd2e5293
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 85 additions and 58 deletions

View File

@ -135,16 +135,16 @@ SPEC CHECKSUMS:
GoogleUtilities: 06b66f9567769a7958db20a92f0128b2843e49d5
nanopb: 5601e6bca2dbf1ed831b519092ec110f66982ca3
Protobuf: 1eb9700044745f00181c136ef21b8ff3ad5a0fd5
React: 1d605e098d69bdf08960787f3446f0a9dc2e2ccf
react-native-background-timer: bb7a98c8e97fc7c290de2d423dd09ddb73dcbcbb
react-native-camera: 68ad5143d2d0636236d46c7de8d2a6455ca52a36
react-native-webview: a42108b827082f8f0333529b0772102031d5960d
RNKeychain: 627c6095cef215dd3d9804a9a9cf45ab96aa3997
React: 36d0768f9e93be2473b37e7fa64f92c1d5341eef
react-native-background-timer: f7bc6cb474ca47d81f3be8a1b4c986ac7ee136b3
react-native-camera: 70db6904b34e02054a25deb84dde9196e94caaee
react-native-webview: 763be2e9f8b103d195170fafc2fd77805d5434b5
RNKeychain: 216f37338fcb9e5c3a2530f1e3295f737a690cb1
SQLCipher: f9fcf29b2e59ced7defc2a2bdd0ebe79b40d4990
SSZipArchive: 41455d4b8d2b6ab93990820b50dc697c2554a322
TouchID: b0640fedb86fa2db2fe1df15b61594ad49e76288
yoga: 128daf064cacaede0c3bb27424b6b4c71052e6cd
TouchID: ba4c656d849cceabc2e4eef722dea5e55959ecf4
yoga: 684513b14b03201579ba3cee20218c9d1298b0cc
PODFILE CHECKSUM: 13006106aa0716d54fffebf8dcb42006f0fb8798
COCOAPODS: 1.5.3
COCOAPODS: 1.7.5

View File

@ -7,7 +7,7 @@ function cleanup() {
# clear trapped signals
trap - EXIT ERR INT QUIT
# do the actual cleanup
./nix/clean.sh ${nixOpts[@]}
./nix/clean.sh "${nixResultPath}"
}
trap cleanup EXIT ERR INT QUIT
@ -21,6 +21,9 @@ function extractResults() {
chmod u+w -R result/
}
# Load Nix profile
. ~/.nix-profile/etc/profile.d/nix.sh
targetAttr="${1}"
shift

View File

@ -2,43 +2,22 @@
set -e
function getSources() {
nix-store --query --binding src "${1}"
}
function log() { echo "$@" 1>&2; }
function getOutputs() {
nix-store --query --outputs "${1}"
}
# helpers for getting related paths in Nix store
function getSources() { nix-store --query --binding src "${1}"; }
function getOutputs() { nix-store --query --outputs "${1}"; }
function getDrvFiles() { nix-store --query --deriver "${1}"; }
function getReferrers() { nix-store --query --referrers "${1}"; }
function getDrvFiles() {
nix-store --query --deriver "${1}"
}
function getReferrers() {
nix-store --query --referrers "${1}"
}
# list of store entries to delete
declare -a toDelete
echo "Cleanup of /nix/store after build..."
# regular expression that should match all status-react build artifacts
searchRegex='.*-status-react-(shell|source|build).*'
# search for matching entries in the store
drvPaths=$(
find /nix/store -maxdepth 1 -type d -regextype egrep -regex "${searchRegex}"
)
# for each entry find the source and derivation
for path in ${drvPaths}; do
toDelete+=("${path}")
function findRelated() {
path="${1}"
found+=("${path}")
if [[ "${path}" =~ .*.chroot ]]; then
echo " ! Chroot: ${path}"
log " ! Chroot: ${path}"
continue
fi
echo " ? Checking: ${path}"
log " ? Checking: ${path}"
drv=$(getDrvFiles "${path}")
# if drv is unknown-deriver then path is a source
if [[ "${drv}" == "unknown-deriver" ]]; then
@ -47,14 +26,57 @@ for path in ${drvPaths}; do
elif [[ -f "${drv}" ]]; then
src=$(getSources "${drv}")
fi
echo " - Derivation: ${drv}"
echo " - Source: ${src}"
log " - Derivation: ${drv}"
log " - Source: ${src}"
found+=("${drv}" "${src}")
printf '%s\n' "${found[@]}"
}
toDelete+=("${drv}" "${src}")
done
# used to find things to delete based on a regex
function findByRegex() {
regex="${1}"
# remove duplicates
cleanToDelete=$(echo "${toDelete[@]}" | sort | uniq)
log "Searching by regex: '${regex}'"
# search for matching entries in the store
drvPaths=$(
find /nix/store -maxdepth 1 -type d -regextype egrep -regex "${regex}"
)
echo "Deleting..."
nix-store --ignore-liveness --delete ${cleanToDelete[@]}
# list of store entries to delete
declare -a found
# for each entry find the source and derivation
for mainPath in ${drvPaths}; do
findRelated "${mainPath}"
done
}
# used to find things to delete based on a given path
function findByResult() {
mainPath="${1}"
log "Searching by result: '${mainPath}'"
# list of store entries to delete
declare -a found
findRelated "${mainPath}"
}
log "Cleanup of /nix/store..."
# This is an optional CLI argument
nixResultPath="${1}"
if [[ -n "${nixResultPath}" ]]; then
# if provided we can narrow down what to clean based on result path
toDelete=$(findByResult "${nixResultPath}")
else
# use regular expression that should match all status-react build artifacts
toDelete=$(findByRegex '.*-status-react-(shell|source|build).*')
fi
# remove duplicates and return
toDelete=$(printf '%s\n' "${toDelete[@]}" | sort | uniq)
log "Deleting..."
nix-store --ignore-liveness --delete ${toDelete[@]}

View File

@ -37,7 +37,7 @@ let
# TARGETS
leiningen-shell = mkShell {
buildInputs = with pkgs; [ clojure leiningen maven nodejs ];
buildInputs = with pkgs; [ clojure leiningen maven nodejs openjdk ];
shellHook =
if target-os == "android" then mobile.android.shellHook else
if target-os == "ios" then mobile.ios.shellHook else "";

View File

@ -24,7 +24,7 @@ else
fi
if [ "$(uname)" == 'Darwin' ]; then
# CocoaPods are trash and can't handle other pod instances running at the same time
$STATUS_REACT_HOME/scripts/wait-for.sh pod 240
$STATUS_REACT_HOME/scripts/wait-for.sh 240 -f 'pod'
pushd $STATUS_REACT_HOME/ios && pod install; popd
fi
fi

View File

@ -2,25 +2,27 @@
set -e
PROC_NAME=${1}
TIMEOUT=${2:-600}
TIMEOUT=${1}
shift
PGREP_OPTS=${@}
SLEEP_SEC=5
STEPS=$((TIMEOUT / SLEEP_SEC))
if [[ -z ${PROC_NAME} ]]; then
echo "No process name specified!" >&2
if [[ -z ${PGREP_OPTS} ]]; then
echo "No pgrep options name specified!" >&2
exit 1
fi
echo "Checking for process: '${PGREP_OPTS}'"
for ((i = 0; i < ${STEPS}; i += 1)); do
if pgrep -f ${PROC_NAME} > /dev/null; then
if pgrep ${PGREP_OPTS} > /dev/null; then
echo "Process found. Sleeping ${SLEEP_SEC}..." >&2
sleep ${SLEEP_SEC}
else
echo "Process '${PROC_NAME}' gone." >&2
echo "Process '${PGREP_OPTS}' gone." >&2
exit 0
fi
done
echo "Timeout reached! (${TIMEOUT}s) Process still up: ${PROC_NAME}" >&2
echo "Timeout reached! (${TIMEOUT}s) Process still up: ${PGREP_OPTS}" >&2
exit 1