-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild
More file actions
executable file
·127 lines (122 loc) · 3.18 KB
/
build
File metadata and controls
executable file
·127 lines (122 loc) · 3.18 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -euo pipefail
here=$(dirname "${BASH_SOURCE[0]}")
here=$(readlink -f "$here")
if [ $# -lt 2 ]; then
echo >&2 "usage: $0 outputdir packagedir [input ...]"
exit 1
fi
out=$(readlink -f "$1")
shift
package_dir=$(readlink -f "$1")
package_name=$(basename "$package_dir")
shift
inputs=("$@")
if [ -e "$out"/.built ]; then
shouldBuild=no
newer=$(find "$package_dir" -newer "$out"/.built -print -quit)
if [ -n "$newer" ]; then
echo >&2 "$0: should build: $newer is newer than $out"
shouldBuild=yes
elif [ ${#inputs[@]} -ne 0 ]; then
for i in "${inputs[@]}"; do
if [ "$i"/.built -nt "$out"/.built ]; then
echo >&2 "$0: should build: $i is newer than $out"
shouldBuild=yes
break
fi
done
fi
else
echo >&2 "$0: should build: $out has not been built"
shouldBuild=yes
fi
bppm_escape() {
sed -e 's,%,%#,g' -e 's,=,%+,g' -e 's,:,%.,g'
}
bppm() {
local bppm
bppm=
while [ $# -gt 0 ]; do
a=$(bppm_escape <<< "$1")
b=$(bppm_escape <<< "$2")
bppm="$bppm:$a=$b"
shift 2
done
echo "${bppm#:}"
}
case "$shouldBuild" in
yes)
echo >&2 "$0: building: $out"
unset workdir
trap '[ -v workdir ] && echo >&2 "leaving behind: $workdir"' EXIT
workdir=$(mktemp -dt "$package_name".XXXXXXXX)
mkdir "$workdir"/tmp
if [ -d "$out" ]; then
find "$out" -type d -execdir chmod u+w {} +
fi
rm -rf "$out"
(
inputsvars=()
bppmentries=(
"/egg-workdir/$package_name" "$workdir"
"/egg-output/$package_name" "$out"
)
if [ ${#inputs[@]} -ne 0 ]; then
inputspaths=()
for i in "${inputs[@]}"; do
name=$(basename "$i")
fullpath=$(readlink -f "$i")
inputspaths+=("$fullpath")
inputsvars+=("${name//-/_}=$fullpath")
bppmentries+=(/egg-input/"$name" "$fullpath")
done
IFS=:
if [ -v PASS_PATH_THROUGH ] && [ ${#inputspaths[@]} -ne 0 ]; then
path=$PATH:"${inputspaths[*]/%//bin}"
elif [ -v PASS_PATH_THROUGH ]; then
path=$PATH
elif [ ${#inputspaths[@]} -ne 0 ]; then
path="${inputspaths[*]/%//bin}"
else
path=
fi
inputsvars+=(
CPATH="${inputspaths[*]/%//include}"
LD_LIBRARY_PATH="${inputspaths[*]/%//lib}"
LIBRARY_PATH="${inputspaths[*]/%//lib}"
PATH="$path"
)
unset IFS
fi
pathmap=$(bppm "${bppmentries[@]}")
cd "$workdir"
env -i \
out="$out" \
here="$package_dir" \
SOURCE_DATE_EPOCH=1 \
BUILD_PATH_PREFIX_MAP="$pathmap" \
TMPDIR="$workdir"/tmp \
EGG_JOBS="${EGG_JOBS:-1}" \
${inputsvars:+"${inputsvars[@]}"} \
/bin/bash -euo pipefail -- "$package_dir"/build
)
if [ ! -v LEAVE_WORKING_DIR ]; then
echo >&2 "cleaning up: $workdir"
find "$workdir" -type d -execdir chmod u+w {} +
rm -rf "$workdir"
unset workdir
fi
chmod u+w "$out"
touch "$out"/.built
find "$out" ! -type l -execdir chmod a-w {} +
;;
no)
echo >&2 "$0: not building: $out"
exit 0
;;
*)
echo >&2 "$0: internal error: $shouldBuild"
exit 2
;;
esac