Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makerepropkg download used buid config #74

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
V=20210202
BUILDTOOLVER ?= $(V)-git

PREFIX = /usr/local
MANDIR = $(PREFIX)/share/man
Expand Down Expand Up @@ -92,7 +93,7 @@ edit = sed -e "s|@pkgdatadir[@]|$(PREFIX)/share/devtools|g"
%: %.in Makefile lib/common.sh
@echo "GEN $@"
@$(RM) "$@"
@{ echo -n 'm4_changequote([[[,]]])'; cat [email protected]; } | m4 -P --define=m4_devtools_version=$V | $(edit) >$@
@{ echo -n 'm4_changequote([[[,]]])'; cat [email protected]; } | m4 -P --define=m4_devtools_version=$(BUILDTOOLVER) | $(edit) >$@
@chmod a-w "$@"
@chmod +x "$@"
@bash -O extglob -n "$@"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ as following.
git config format.subjectprefix 'devtools] [PATCH'
```

## Building

When building official distro packages the `BUILDTOOLVER` needs to be set to the
exact label of the release package in order to allow to detect the exactly used
devtools version. This is required for reproducible builds to fetch the according
files like `makepkg.conf`.

```sh
BUILDTOOLVER="${pkgver}-${pkgrel}-${arch}" make all
```

## Releasing

1. bump the version in the Makefile
Expand Down
5 changes: 5 additions & 0 deletions doc/makerepropkg.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Options
*-M* <file>::
Location of a makepkg config file.

*-l* <chroot>::
The directory name to use as the chroot namespace
Useful for maintaining multiple copies
Default: $USER

*-h*::
Show this usage message

Expand Down
64 changes: 52 additions & 12 deletions makerepropkg.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ declare -a buildenv buildopts installed installpkgs

archiveurl='https://archive.archlinux.org/packages'
buildroot=/var/lib/archbuild/reproducible
chroot=testenv
diffoscope=0

chroot=$USER
[[ -n ${SUDO_USER:-} ]] && chroot=$SUDO_USER
[[ -z "$chroot" || $chroot = root ]] && chroot=copy

parse_buildinfo() {
local line var val

Expand Down Expand Up @@ -81,6 +84,18 @@ get_pkgfile() {
return 1
}

get_makepkg_conf() {
local fname=${1}
local makepkg_conf="${2}"
if ! buildtool_file=$(get_pkgfile "${fname}"); then
error "failed to retrieve ${fname}"
return 1
fi
msg2 "using makepkg.conf from ${fname}"
bsdtar xOqf "${buildtool_file/file:\/\//}" usr/share/devtools/makepkg-x86_64.conf > "${makepkg_conf}"
return 0
}

usage() {
cat << __EOF__
usage: ${BASH_SOURCE[0]##*/} [options] <package_file>
Expand All @@ -96,15 +111,19 @@ OPTIONS
-d Run diffoscope if the package is unreproducible
-c <dir> Set pacman cache
-M <file> Location of a makepkg config file
-l <chroot> The directory name to use as the chroot namespace
Useful for maintaining multiple copies
Default: $chroot
-h Show this usage message
__EOF__
}

while getopts 'dM:c:h' arg; do
while getopts 'dM:c:l:h' arg; do
case "$arg" in
d) diffoscope=1 ;;
M) archroot_args+=(-M "$OPTARG") ;;
c) cache_dirs+=("$OPTARG") ;;
l) chroot="$OPTARG" ;;
h) usage; exit 0 ;;
*|?) usage; exit 1 ;;
esac
Expand Down Expand Up @@ -172,23 +191,44 @@ BUILDTOOLVER="${buildinfo[buildtoolver]}"
PKGEXT=${splitpkgs[0]#${splitpkgs[0]%.pkg.tar*}}

# nuke and restore reproducible testenv
for copy in "${buildroot}"/*/; do
namespace="$buildroot/$chroot"
lock 9 "${namespace}.lock" "Locking chroot namespace '%s'" "${namespace}"
for copy in "${namespace}"/*/; do
[[ -d ${copy} ]] || continue
subvolume_delete_recursive "${copy}"
done
rm -rf --one-file-system "${buildroot}"
(umask 0022; mkdir -p "${buildroot}")
rm -rf --one-file-system "${namespace}"
(umask 0022; mkdir -p "${namespace}")

for fname in "${installed[@]}"; do
if ! allpkgfiles+=("$(get_pkgfile "${fname}")"); then
error "failed to retrieve ${fname}"
exit 1
fi
done
printf '%s\n' "${allpkgfiles[@]}" | mkarchroot -M @pkgdatadir@/makepkg-x86_64.conf -U "${archroot_args[@]}" "${buildroot}"/root - || exit 1

trap 'rm -rf $TEMPDIR' EXIT INT TERM QUIT
TEMPDIR=$(mktemp -d --tmpdir makerepropkg.XXXXXXXXXX)

makepkg_conf="${TEMPDIR}/makepkg.conf"
# anything before buildtool support is pinned to the last none buildtool aware release
if [[ -z "${BUILDTOOL}" ]]; then
get_makepkg_conf "devtools-20210202-3-any" "${makepkg_conf}" || exit 1
# prefere to assume devtools up until matching makepkg version so repository packages remain reproducible
elif [[ "${BUILDTOOL}" = makepkg ]] && (( $(vercmp "${BUILDTOOLVER}" 6.0.1) <= 0 )); then
get_makepkg_conf "devtools-20210202-3-any" "${makepkg_conf}" || exit 1
# all devtools builds
elif [[ "${BUILDTOOL}" = devtools ]] && get_makepkg_conf "${BUILDTOOL}-${BUILDTOOLVER}" "${makepkg_conf}"; then
true
# fallback to current makepkg.conf
else
warning "Unknown buildtool (${BUILDTOOL}-${BUILDTOOLVER}), using fallback"
makepkg_conf=@pkgdatadir@/makepkg-x86_64.conf
anthraxx marked this conversation as resolved.
Show resolved Hide resolved
fi
printf '%s\n' "${allpkgfiles[@]}" | mkarchroot -M "${makepkg_conf}" -U "${archroot_args[@]}" "${namespace}/root" - || exit 1

# use makechrootpkg to prep the build directory
makechrootpkg -r "${buildroot}" -l "${chroot}" -- --packagelist || exit 1
makechrootpkg -r "${namespace}" -l build -- --packagelist || exit 1

# set detected makepkg.conf options
{
Expand All @@ -197,22 +237,22 @@ makechrootpkg -r "${buildroot}" -l "${chroot}" -- --packagelist || exit 1
done
printf 'OPTIONS=(%s)\n' "${buildopts[*]@Q}"
printf 'BUILDENV=(%s)\n' "${buildenv[*]@Q}"
} >> "${buildroot}/${chroot}"/etc/makepkg.conf
install -d -o "${SUDO_UID:-$UID}" -g "$(id -g "${SUDO_UID:-$UID}")" "${buildroot}/${chroot}/${BUILDDIR}"
} >> "${namespace}/build"/etc/makepkg.conf
install -d -o "${SUDO_UID:-$UID}" -g "$(id -g "${SUDO_UID:-$UID}")" "${namespace}/build/${BUILDDIR}"

# kick off the build
arch-nspawn "${buildroot}/${chroot}" \
arch-nspawn "${namespace}/build" \
--bind="${PWD}:/startdir" \
--bind="${SRCDEST}:/srcdest" \
/chrootbuild -C --noconfirm --log --holdver --skipinteg
ret=$?

if (( ${ret} == 0 )); then
msg2 "built succeeded! built packages can be found in ${buildroot}/${chroot}/pkgdest"
msg2 "built succeeded! built packages can be found in ${namespace}/build/pkgdest"
msg "comparing artifacts..."

for pkgfile in "${splitpkgs[@]}"; do
comparefiles=("${pkgfile}" "${buildroot}/${chroot}/pkgdest/${pkgfile##*/}")
comparefiles=("${pkgfile}" "${namespace}/build/pkgdest/${pkgfile##*/}")
if cmp -s "${comparefiles[@]}"; then
msg2 "Package '%s' successfully reproduced!" "${pkgfile}"
else
Expand Down