]>
Commit | Line | Data |
---|---|---|
987288b3 | 1 | #!/bin/bash |
5e18ef4f XL |
2 | # Build a packaged crate. |
3 | # | |
4 | # This script is not run directly, but linked into ./build/ when running one of | |
5 | # the other scripts, so you should do that instead of running this directly. | |
6 | # | |
7 | # Usage: [REALVER=<EXACTVER>] ./build.sh <CRATE> [<SEMVER>] [<EXTRA DEPENDENCY DEB> ...] | |
8 | # | |
9 | # Envvars: | |
10 | # IGNORE_MISSING_BUILD_DEPS=1 | |
11 | # Don't abort on missing build deps. You'll need | |
12 | # this when giving extra dependency debs. | |
2466318e FG |
13 | # SKIP_SIGN=1 |
14 | # Skip signing built packages. | |
5e18ef4f XL |
15 | # DISTRIBUTION=$suite |
16 | # Release to something other than unstable, e.g. experimental | |
17 | # CHROOT=$chroot | |
18 | # Build using another schroot than debcargo-unstable-amd64-sbuild | |
1e197466 MC |
19 | # SBUILD_OPTS= |
20 | # will pass to sbuild; for example SBUILD_OPTS=--arch=i386 | |
3ceff793 BN |
21 | # EXTRA_DEBS |
22 | # Include extra dependency debs, e.g. EXTRA_DEBS=librust*.deb. | |
1057693c XL |
23 | set -e |
24 | ||
9cc53ba7 XL |
25 | SCRIPTDIR="$(dirname $(readlink -f "$0"))" |
26 | ||
1057693c | 27 | abort() { local x=$1; shift; for i in "$@"; do echo >&2 "$0: abort: $i"; done; exit "$x"; } |
9cc53ba7 | 28 | report() { for i in "$@"; do echo >&2 "debcargo-conf builder: $i"; done; } |
1057693c XL |
29 | |
30 | if [ "$(basename "$PWD")" != "build" ]; then | |
31 | abort 1 "This script is only meant to be run from the build/ directory." | |
32 | fi | |
33 | ||
34 | if [ -n "$DEBCARGO" ]; then | |
35 | true | |
38e27c24 IJ |
36 | elif type -p debcargo >/dev/null 2>&1; then |
37 | DEBCARGO=$(type -p debcargo) | |
1057693c XL |
38 | elif [ -f "$HOME/.cargo/bin/debcargo" ]; then |
39 | DEBCARGO="$HOME/.cargo/bin/debcargo" | |
40 | else | |
41 | abort 1 "debcargo not found, run \`cargo install debcargo\` or set DEBCARGO to point to it" | |
42 | fi | |
43 | ||
44 | CRATE="$1" | |
45 | VER="$2" | |
987288b3 XL |
46 | if test -z "$VER" -o -f "$VER"; then |
47 | VER="" | |
48 | shift | |
49 | else | |
50 | shift 2 | |
51 | fi | |
1057693c XL |
52 | DISTRIBUTION="${DISTRIBUTION:-unstable}" |
53 | ||
54 | PKGNAME=$($DEBCARGO deb-src-name "$CRATE" $VER || abort 1 "couldn't find crate $CRATE") | |
55 | DEBVER=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SVersion) | |
56 | DEBSRC=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SSource) | |
57 | DEBDIST=$(dpkg-parsechangelog -l $PKGNAME/debian/changelog -SDistribution) | |
58 | DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH) | |
9cc53ba7 XL |
59 | SRCNAME="${DEBSRC}_${DEBVER}" |
60 | BUILDNAME="${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}" | |
43b8c908 | 61 | if [ -z "$CHROOT" ]; then |
18699184 | 62 | if schroot -i -c "debcargo-unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then |
43b8c908 | 63 | CHROOT="debcargo-unstable-${DEB_HOST_ARCH}-sbuild" |
18699184 | 64 | elif schroot -i -c "unstable-${DEB_HOST_ARCH}-sbuild" >/dev/null 2>&1; then |
43b8c908 XL |
65 | CHROOT="unstable-${DEB_HOST_ARCH}-sbuild" |
66 | echo >&2 "Automatically using sbuild chroot unstable-${DEB_HOST_ARCH}-sbuild; however it's" | |
67 | echo >&2 "strongly recommended to create a separate chroot debcargo-unstable-${DEB_HOST_ARCH}-sbuild" | |
68 | echo >&2 "so your builds won't have to re-download & re-install cargo, rustc, and llvm every time." | |
69 | echo >&2 "See README.rst section \"Build environment\" for details." | |
70 | sleep 1 | |
18699184 | 71 | elif [ "$SOURCEONLY" != 1 ]; then |
43b8c908 XL |
72 | abort 1 "could not automatically find a suitable chroot; set CHROOT" |
73 | fi | |
1057693c XL |
74 | fi |
75 | ||
76 | shouldbuild() { | |
77 | local dst="$1" | |
78 | local src="$2" | |
79 | test ! -e "$dst" -o "$src" -nt "$dst" | |
80 | } | |
81 | ||
9cc53ba7 | 82 | if shouldbuild "$SRCNAME.dsc" "$PKGNAME/debian/changelog" ]; then |
2f1d8dc5 XL |
83 | if [ "$REUSE_EXISTING_ORIG_TARBALL" = 1 ]; then |
84 | UPSVER="${DEBVER%-*}" | |
85 | mv "${DEBSRC}_${UPSVER}.orig.tar.gz" "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | |
551c3a83 | 86 | apt-get -t unstable source --download-only "${DEBSRC}" # "=${DEBVER}" |
2f1d8dc5 | 87 | # check that old tarball contains same contents as new tarball |
a0c73b1a XL |
88 | if ! diff -ru \ |
89 | --label "${DEBSRC}_${UPSVER}.orig.tar.gz.new" \ | |
90 | <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz.new" | tar -tvvf-) \ | |
91 | --label "${DEBSRC}_${UPSVER}.orig.tar.gz" \ | |
92 | <(zcat "${DEBSRC}_${UPSVER}.orig.tar.gz" | tar -tvvf-); then | |
93 | read -p "contents differ, continue with old tarball or abort? [y/N] " x | |
94 | if [ "$x" != "y" ]; then exit 1; fi | |
95 | fi | |
551c3a83 XL |
96 | # extract old tarball into new directory, to avoid "modified files" problems with dpkg-source later |
97 | ( cd "$PKGNAME" && dpkg-source --after-build . && tar --strip-components=1 -xf "../${DEBSRC}_${UPSVER}.orig.tar.gz" ) | |
2f1d8dc5 | 98 | fi |
0b6cb5c1 | 99 | ( cd "$PKGNAME" && dpkg-buildpackage -d -S --no-sign ) |
1057693c XL |
100 | # sign if not UNRELEASED |
101 | if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then | |
2466318e FG |
102 | if [ "$SKIP_SIGN" != 1 ]; then |
103 | debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID} "${SRCNAME}_source.changes" | |
104 | fi | |
1057693c XL |
105 | fi |
106 | fi | |
107 | ||
3ceff793 BN |
108 | # allow tab, comma, space as separators |
109 | IFS=' , ' read -r -a EXTRA_DEBS <<< "$EXTRA_DEBS" | |
110 | if [ ${#EXTRA_DEBS[@]} -eq 0 ]; then | |
111 | EXTRA_DEBS=( "$@" ) | |
112 | fi | |
113 | if [ ${#EXTRA_DEBS[@]} -ne 0 ]; then | |
a7db8d2f XL |
114 | IGNORE_MISSING_BUILD_DEPS=1 |
115 | echo >&2 "Given non-empty extra debs; defaulting IGNORE_MISSING_BUILD_DEPS=1" | |
116 | fi | |
d0306da4 | 117 | |
1057693c XL |
118 | check_build_deps() { |
119 | mkdir -p dpkg-dummy | |
120 | if shouldbuild dpkg-dummy/status /var/cache/apt/pkgcache.bin; then | |
121 | # pretend dpkg status file that marks all packages as installed | |
122 | # this is because dpkg-checkbuilddeps only works on installed pkgs | |
bbaba306 | 123 | ( apt-cache dumpavail -o APT::Default-Release=$DISTRIBUTION && \ |
d0306da4 | 124 | for i in ${EXTRA_DEBS[*]}; do apt-cache show $(echo $i | cut -d_ -f1); done ) | \ |
0a25965e RG |
125 | sed -e 's/Package: .*/\0\nStatus: install ok installed/g' > dpkg-dummy/status.tmp |
126 | if ! test -s dpkg-dummy/status.tmp; then | |
9cc53ba7 | 127 | abort 1 "couldn't generate dpkg-dummy/status, is Debian unstable in your APT sources?" |
89617f5c | 128 | fi |
0a25965e | 129 | mv dpkg-dummy/status{.tmp,} |
1057693c | 130 | fi |
c7386c93 | 131 | ( cd "$PKGNAME" && dpkg-checkbuilddeps --admindir=../dpkg-dummy ) |
1057693c XL |
132 | } |
133 | ||
134 | if ! check_build_deps; then | |
581335d2 XL |
135 | if [ "$IGNORE_MISSING_BUILD_DEPS" != 1 ]; then |
136 | abort 1 "Missing build-dependencies, but maybe try '{apt,cargo} update'" | |
137 | fi | |
1057693c XL |
138 | fi |
139 | ||
140 | if [ "$SOURCEONLY" = 1 ]; then | |
141 | exit | |
142 | fi | |
143 | ||
95bfde43 FG |
144 | if [ -n "${EXTRA_DEBS[*]}" ]; then |
145 | EXTRA_DEBS_SBUILD=("${EXTRA_DEBS[@]/#/--extra-package=}") | |
146 | EXTRA_DEBS_REPO_TMP=$(mktemp -d "${SRCNAME}_REPO_XXXXXXXX") | |
5e18ef4f XL |
147 | # trap cleans up even if user does Ctrl-C |
148 | # https://stackoverflow.com/a/14812383 inside "trap" avoids running handler twice | |
149 | trap 'excode=$?; rm -rf "'"$EXTRA_DEBS_REPO_TMP"'"; trap - EXIT' EXIT HUP INT QUIT PIPE TERM | |
95bfde43 FG |
150 | # symlinks don't work here |
151 | ln -f "${EXTRA_DEBS[@]}" "$EXTRA_DEBS_REPO_TMP/" | |
152 | ( cd "$EXTRA_DEBS_REPO_TMP"; apt-ftparchive packages . > Packages ) | |
153 | EXTRA_DEBS_AUTOPKGTEST_OPTS=([0]=--autopkgtest-opt=--copy="$PWD/$EXTRA_DEBS_REPO_TMP/:/tmp/$EXTRA_DEBS_REPO_TMP/" [1]=--autopkgtest-opt=--add-apt-source="deb [trusted=yes] file:///tmp/$EXTRA_DEBS_REPO_TMP ./") | |
154 | fi | |
155 | ||
156 | AUTOPKGTEST_OPTS=("--run-autopkgtest" "--autopkgtest-root-arg=" "--autopkgtest-opts=-- schroot ${CHROOT}") | |
9cc53ba7 XL |
157 | if [ "$SKIP_AUTOPKGTEST" = 1 ]; then |
158 | AUTOPKGTEST_OPTS=() | |
95bfde43 | 159 | EXTRA_DEBS_AUTOPKGTEST_OPTS=() |
e3985deb RK |
160 | fi |
161 | ||
4a5c5885 RK |
162 | LINTIAN_OPTS=() |
163 | if echo "$DEBDIST" | grep -q UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then | |
95bfde43 | 164 | LINTIAN_OPTS=([0]="--lintian-opt=--suppress-tags" [1]="--lintian-opt=bad-distribution-in-changes-file") |
4a5c5885 RK |
165 | fi |
166 | ||
f890c341 | 167 | SBUILD_CONFIG="$SCRIPTDIR/dev/sbuildrc" sbuild --no-source --arch-any --arch-all \ |
987288b3 XL |
168 | ${CHROOT:+-c $CHROOT} \ |
169 | ${DISTRIBUTION:+-d $DISTRIBUTION} \ | |
95bfde43 FG |
170 | "${EXTRA_DEBS_SBUILD[@]}" \ |
171 | "${EXTRA_DEBS_AUTOPKGTEST_OPTS[@]}" \ | |
e3985deb | 172 | "${AUTOPKGTEST_OPTS[@]}" \ |
4a5c5885 | 173 | "${LINTIAN_OPTS[@]}" \ |
1e197466 | 174 | ${SBUILD_OPTS} \ |
9cc53ba7 XL |
175 | "$SRCNAME.dsc" |
176 | if [ "$SKIP_AUTOPKGTEST" != 1 ]; then | |
177 | report "analyzing autopkgtest log: $BUILDNAME.test.log" | |
178 | # this is a bit of a hack but works OK for now, until sbuild supports %SBUILD_BUILD_DIR in --autopkgtest-opt | |
179 | sed -ne '/autopkgtest .*: testing package .* version .*/,$p' "$BUILDNAME.build" > "$BUILDNAME.test.log" | |
180 | "$SCRIPTDIR/dev/rust-regressions.sh" "$BUILDNAME.test.log" | |
181 | fi | |
95bfde43 | 182 | |
9cc53ba7 XL |
183 | changestool "$BUILDNAME.changes" adddsc "$SRCNAME.dsc" |
184 | report "build complete: $BUILDNAME.changes" | |
1057693c | 185 | |
8f014087 SL |
186 | if grep -q "unknown-section FIXME" "$BUILDNAME.build"; then |
187 | abort 1 "Please fix the SECTION, found FIXME" | |
188 | fi | |
189 | ||
1057693c XL |
190 | # sign if not UNRELEASED |
191 | if echo "$DEBDIST" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then | |
2466318e FG |
192 | if [ "$SKIP_SIGN" != 1 ]; then |
193 | debsign ${DEBSIGN_KEYID:+-k $DEBSIGN_KEYID} --no-re-sign "$BUILDNAME.changes" | |
194 | fi | |
1057693c | 195 | fi |