This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
buildctl
executable file
·252 lines (230 loc) · 6.65 KB
/
buildctl
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/usr/bin/bash
NOBANNER=1
batch_flag=""
lint_flag=""
if [ "${BATCH}" = 1 ]; then
echo "Enabling batch mode."
batch_flag="-b"
fi
cd build
. ../lib/functions.sh
[ "${1}" == "licenses" ] && AUDIT_LICENSE=1
# targets maps any valid package name to its build script.
declare -A targets
# fulltargets maps full package names to their build script.
declare -A fulltargets
# list of packages already built.
declare -A already_built
DEPENDENCY_CHECK="n"
add_target() {
local pkg=$1
local build=$2
[[ -n ${fulltargets[$pkg]} ]] && \
logerr "Target $pkg specified by ${fulltargets[$pkg]} and $build."
fulltargets+=([$pkg]=$build)
#
# Repeatedly strip off leading components to generate all valid
# names for this package. If more than one package has the same
# abbreviated name, the first one wins.
#
[[ -n ${targets[$pkg]} ]] || targets+=([$pkg]=$build)
while [[ $pkg =~ '/' ]]; do
pkg=${pkg#*/}
[[ -n ${targets[$pkg]} ]] || targets+=([$pkg]=$build)
done
}
declare -A licenses
TCNT=0
for build in */build*.sh
do
for PKG in $(grep -v '##IGNORE##' $build | sed -e 's/^ +//' -e 's/ +#.+//' -e 's/=/ /g' -e 's/^.+make_package/make_package/g' | awk '{if($1=="PKG"){PKG=$2; print $2;} if($1=="make_package"){print PKG"="$2;}}')
do
if [ -n "`echo ${PKG} | grep '.='`" ] ; then
[ -z "${AUDIT_LICENSE}" ] && continue
MOG=`echo ${PKG} | sed -e 's/^.*=//'`
PKG=`echo ${PKG} | sed -e 's/=.*$//'`
LOCALMOG=`echo ${build} | sed -e 's:/.*$:/local.mog:'`
[ -f $MOG ] || MOG=""
[ -f $LOCALMOG ] || LOCALMOG=""
LICENSE=`nawk -F "[ =]" '/"/{gsub("\"", "")} /^license/ {print $3;}' $MOG $LOCALMOG /dev/null | xargs`
licenses+=([$PKG]=$LICENSE)
TCNT=$(($TCNT + 1))
print -f "."
else
add_target $PKG $build
fi
done
done
[ -n "${AUDIT_LICENSE}" ] && echo
for manifest in */*.p5m
do
for PKG in $(awk '/^set name=pkg.fmri/ {print $3;}' $manifest | sed -e 's/value=//' -e 's/.*\/\/[^\/]*\///g' -e 's/@.*//')
do
add_target $PKG $manifest
done
done
usage() {
echo $0
echo " list [grep pattern] (sorted alphabetically)"
echo " list-build [grep pattern] (sorted in build order)"
echo " licenses"
echo " build <pkg> | all"
exit
}
bail() {
echo $*
exit
}
list() {
PAT=${1-.}
for target in "${!fulltargets[@]}"
do
if [[ "$PAT" = "." ]]; then
echo " * $target"
elif [[ -n $(echo "$target" | grep "$PAT") ]]; then
echo " * $target"
fi
done | sort
}
list_build() {
PAT=${1-.}
for target in "${!fulltargets[@]}"
do
if [[ "$PAT" = "." ]]; then
echo " * $target"
elif [[ -n $(echo "$target" | grep "$PAT") ]]; then
echo " * $target"
fi
done
}
build() {
if [[ -z "${targets[$1]}" ]]; then
bail "Unknown package: $1"
fi
if [[ "${already_built[$1]}" = "1" ]]; then
logmsg "--- This package was already built."
else
DIR=$(dirname ${targets[$1]})
pushd $DIR > /dev/null || bail "Cannot chdir to $DIR"
PKGSRVR=$DEFAULT_PKGSRVR
PKGPUBLISHER=$DEFAULT_PKGPUBLISHER
PKGROOT=`pwd`/root
if [[ -f environment ]]; then
logmsg "--- Setting new environment"
. environment
fi
if [[ -f dependencies && $DEPENDENCY_CHECK = "y" ]]; then
for dep in `cat dependencies`
do
logmsg "--------- Dependency on $dep"
if [[ "${already_built[$dep]}" = "1" ]]; then
logmsg "----------- (already resolved)"
else
logmsg "----------- (needs building)"
pushd .. > /dev/null || bail "Cannot pop up"
build $dep
popd > /dev/null
fi
done
fi
SCRIPT=$(basename ${targets[$1]})
if [[ -n $(echo $SCRIPT | grep ".p5m$") ]]; then
echo "Found a manifest file. Preparing it for publishing."
sed -e "s/@PKGPUBLISHER@/$PKGPUBLISHER/g; s/@RELVER@/$RELVER/g; s/@PVER@/$PVER/g;" < $SCRIPT > $SCRIPT.final
if [[ -f root.tar.bz2 ]]; then
echo "File archive found. Extracting..."
bzip2 -dc root.tar.bz2 | tar xf - || \
bail "Failed to extract root.tar.bz2"
echo "Publishing from $SCRIPT.final"
pkgsend -s $PKGSRVR publish -d $PKGROOT $SCRIPT.final || \
bail "pkgsend failed"
rm -rf $PKGROOT
# In case we just have a tree of files and not a tarball
elif [[ -d $PKGROOT ]]; then
echo "Publishing from $SCRIPT.final"
pkgsend -s $PKGSRVR publish -d $PKGROOT $SCRIPT.final || \
bail "pkgsend failed"
# Else we just have a manifest to import
else
echo "Simple manifest to import... importing to $PKGSRVR"
pkgsend -s $PKGSRVR publish $SCRIPT.final || \
bail "pkgsend failed"
rm $SCRIPT.final
fi
else
PATH=$PATH:. $SCRIPT -r $PKGSRVR $batch_flag $lint_flag || \
logerr "Unable to run $SCRIPT"
fi
already_built+=([$1]=1)
popd >/dev/null
fi
}
licenses() {
LCNT=0
for target in "${!licenses[@]}"
do
if [[ -n "${licenses[$target]}" ]]; then
echo " * $target -> ${licenses[$target]}"
LCNT=$(($LCNT + 1))
fi
done | sort
if [ $LCNT -ne $TCNT ]; then
echo
echo "=== Packages missing license information ==="
for target in "${!licenses[@]}"
do
if [[ -z "${licenses[$target]}" ]]; then
echo " * $target"
fi
done | sort
fi
}
DEFAULT_PKGSRVR=$PKGSRVR
DEFAULT_PKGPUBLISHER=$PKGPUBLISHER
# When we get here, honor any -l or -b flags from the buildctl command line,
# or even the environment.
if [ "${BATCH}" = 1 ]; then
logmsg "Enabling batch mode."
batch_flag="-b"
fi
if [ "${SKIP_PKGLINT}" = 1 ]; then
logmsg "Disabling pkglint."
lint_flag="-l"
fi
case "$1" in
list)
list $2
exit
;;
list-build)
list_build $2
exit
;;
licenses)
licenses
exit
;;
build)
shift
tobuild=$*
if [ -z "$tobuild" ] || [ "$tobuild" == "all" ]; then
batch_flag="-b"
DEPENDENCY_CHECK="y"
for tgt in "${!fulltargets[@]}"; do
# Uncomment the echo line if you want to see a
# one-package-per-line status of what's building in
# /tmp/debug.<PID>.
# echo "Target = $tgt" >> /tmp/debug.$$
build $tgt
done
else
for tgt in $tobuild; do
build $tgt
done
fi
exit
;;
*)
usage
;;
esac