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