Repository navigation
Expand file tree
/
Copy pathlake.sh
More file actions
100 lines (88 loc) · 3.01 KB
/
Copy pathlake.sh
File metadata and controls
100 lines (88 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env bash
# Shared Lake invocation for repository scripts.
#
# Source files and durable results remain in the checkout. Compiler artifacts use a per-worktree
# directory under the system temporary directory by default; callers may select another location
# with FLOATLIB_BUILD_DIR.
FLOATLIB_ROOT="$(
cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd
)"
FLOATLIB_WORKTREE_KEY="$(
printf '%s' "$FLOATLIB_ROOT" | cksum | awk '{print $1}'
)"
FLOATLIB_BUILD_DIR="${FLOATLIB_BUILD_DIR:-${TMPDIR:-/tmp}/floatlib-build-$FLOATLIB_WORKTREE_KEY}"
if [[ "$FLOATLIB_BUILD_DIR" != /* ]]; then
FLOATLIB_BUILD_DIR="$FLOATLIB_ROOT/$FLOATLIB_BUILD_DIR"
fi
FLOATLIB_BUILD_DIR="${FLOATLIB_BUILD_DIR%/}"
export FLOATLIB_BUILD_DIR
FLOATLIB_BUILD_LOCK="${FLOATLIB_BUILD_DIR}.lock"
floatlib_acquire_build_lock() {
local owner=""
local reported=0
mkdir -p "$(dirname "$FLOATLIB_BUILD_LOCK")"
until ln -s "$$" "$FLOATLIB_BUILD_LOCK" 2>/dev/null; do
owner="$(readlink "$FLOATLIB_BUILD_LOCK" 2>/dev/null || true)"
if [[ "$owner" =~ ^[0-9]+$ ]] && ! kill -0 "$owner" 2>/dev/null; then
if [[ "$(readlink "$FLOATLIB_BUILD_LOCK" 2>/dev/null || true)" == "$owner" ]]; then
rm -f "$FLOATLIB_BUILD_LOCK"
fi
continue
fi
if [[ "$reported" -eq 0 ]]; then
printf 'waiting for Lake build lock held by process %s\n' "${owner:-unknown}" >&2
reported=1
fi
sleep 0.1
done
}
floatlib_release_build_lock() {
if [[ "$(readlink "$FLOATLIB_BUILD_LOCK" 2>/dev/null || true)" == "$$" ]]; then
rm -f "$FLOATLIB_BUILD_LOCK"
fi
}
floatlib_lake_in() {
# `buildDir` is a configuration option read while Lake elaborates `lakefile.lean`.
# Reconfigure once for each root/build-directory pair, then reuse that configuration in this
# process and its children. Re-running `-R` for every build, executable, and checker forces Lake
# to inspect every dependency checkout repeatedly.
local workspace="${1:?a Lake workspace directory is required}"
shift
workspace="$(cd "$workspace" && pwd)" || return
local configuration="$workspace:$FLOATLIB_BUILD_DIR"
local status
local reconfigure=0
floatlib_acquire_build_lock
if [[ "${FLOATLIB_LAKE_CONFIGURED_FOR:-}" == "$configuration" ]]; then
if (cd "$workspace" && "${LAKE:-lake}" -KbuildDir="$FLOATLIB_BUILD_DIR" "$@"); then
status=0
else
status=$?
fi
else
reconfigure=1
if (cd "$workspace" && "${LAKE:-lake}" -R -KbuildDir="$FLOATLIB_BUILD_DIR" "$@"); then
status=0
else
status=$?
fi
fi
floatlib_release_build_lock
if [[ "$status" -eq 0 && "$reconfigure" -eq 1 ]]; then
export FLOATLIB_LAKE_CONFIGURED_FOR="$configuration"
fi
return "$status"
}
floatlib_lake() {
floatlib_lake_in "$PWD" "$@"
}
floatlib_test_lake() {
floatlib_lake_in "$FLOATLIB_ROOT/tests" "$@"
}
floatlib_benchmark_lake() {
floatlib_lake_in "$FLOATLIB_ROOT/benchmarks" "$@"
}
floatlib_build_path() {
local relative_path="${1:?a build-relative path is required}"
printf '%s/%s\n' "$FLOATLIB_BUILD_DIR" "${relative_path#/}"
}