[pbuilder] 01/01: Add initial cross build support
Mattia Rizzolo
mattia at debian.org
Thu Nov 10 22:06:53 UTC 2016
This is an automated email from the git hooks/post-receive script.
mattia pushed a commit to branch master
in repository pbuilder.
commit 1689c66af810f839b4b137cb75f34349eb47f536
Author: Mattia Rizzolo <mattia at debian.org>
Date: Sat Oct 1 23:35:48 2016 +0000
Add initial cross build support
+ Add a new --host-arch command line option (setting non-public HOST_ARCH
variable) to set the *host* architecture
+ --architecture/ARCHITECTURE is used to specify the *build* architecture.
(it defaults to the architecture of the host as reported by dpkg)
+ Some automatic setup is done to allow cross building (at `build` time):
- the host architecture is added to dpkg's list of architectures
- crossbuild-essential-$HOST_ARCH libc-dev:$HOST_ARCH libstdc++-6-dev:$HOST_ARCH
are preinstalled (the latter two due to bug #815172)
- `--host-arch $HOST_ARCH` is added to the options passed to dpkg-buildpackage
- 'nocheck' is added to DEB_BUILD_OPTIONS
- 'nocheck cross' is added to DEB_BUILD_PROFILES
+ A new --no-auto-cross can be used to override partially or all of the above
automatism; see pbuilder(8) for more.
+ The only dependency satisfier allowed when cross building is the APT one, as
that's the only one supporting --host-arch
This implementation is still *experimental*, details may vary across the next
releases, expecially the part relative to what's is automatically done.
Closes: #801799
---
pbuilder-buildpackage | 2 +-
pbuilder-buildpackage-funcs | 30 ++++++++++++++++++++++++++++++
pbuilder-checkparams | 17 +++++++++++++++++
pbuilder-modules | 2 ++
pbuilder-satisfydepends-apt | 5 +++++
pbuilder-satisfydepends-checkparams | 10 ++++++++++
pbuilder.8 | 33 ++++++++++++++++++++++++++++++++-
pbuilderrc.5 | 11 ++++++++---
8 files changed, 105 insertions(+), 5 deletions(-)
diff --git a/pbuilder-buildpackage b/pbuilder-buildpackage
index d2d476d..1b60cfb 100755
--- a/pbuilder-buildpackage
+++ b/pbuilder-buildpackage
@@ -118,7 +118,7 @@ if [ -f "${PBUILDER_BUILD_LOGFILE}" ]; then
chgrp "${BUILDRESULTGID}" "${PBUILDER_BUILD_LOGFILE}"
fi
-
+cross_build_setup
recover_aptcache
createbuilduser
CCACHE_ENV=
diff --git a/pbuilder-buildpackage-funcs b/pbuilder-buildpackage-funcs
index 2fe21ca..36b89d6 100644
--- a/pbuilder-buildpackage-funcs
+++ b/pbuilder-buildpackage-funcs
@@ -68,6 +68,8 @@ function checkbuilddep () {
esac
if \
("$PBUILDERSATISFYDEPENDSCMD" \
+ --build-arch "$ARCHITECTURE" \
+ --host-arch "$HOST_ARCH" \
--control "$control" \
--chroot "${BUILDPLACE}" \
--internal-chrootexec "${CHROOTEXEC}" \
@@ -206,6 +208,34 @@ EOF
rm "$tmpcl"
}
+cross_build_setup () {
+ if [[ "$ARCHITECTURE" = "$HOST_ARCH" ]]; then
+ # native build, nothing interesting to do here
+ return
+ fi
+ log.i "Doing a cross-architecture build"
+ log.i "Build architecture: $ARCHITECTURE"
+ log.i "Host architecture: $HOST_ARCH"
+
+ if [ "${NO_AUTO_CROSS:-}" != "really-dont-mess-with-me" ]; then
+ log.i "Setting up the environment for a cross build..."
+ if [[ "$(readlink -e "$PBUILDERSATISFYDEPENDSCMD")" != *-apt ]]; then
+ log.e "Cross building is possible only with the APT dependency resolver"
+ exit 1
+ fi
+ $CHROOTEXEC dpkg --add-architecture "$HOST_ARCH"
+ EXTRAPACKAGES="${EXTRAPACKAGES:+"$EXTRAPACKAGES" }crossbuild-essential-$HOST_ARCH libc-dev:$HOST_ARCH libstdc++-6-dev:$HOST_ARCH"
+ DEBBUILDOPTS="${DEBBUILDOPTS:+"$DEBBUILDOPTS" }--host-arch $HOST_ARCH"
+ if [ "${NO_AUTO_CROSS:-}" != "yes" ]; then
+ export DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS:+"$DEB_BUILD_OPTIONS" }nocheck"
+ export DEB_BUILD_PROFILES="${DEB_BUILD_PROFILES:+"$DEB_BUILD_PROFILES" }nocheck cross"
+ fi
+ else
+ log.w "Doing a cross build, but not setting up the environment as instructed"
+ return
+ fi
+}
+
function _find_additional_buildresults() {
local file f
local root="${BUILDPLACE}${BUILDDIR}/*"
diff --git a/pbuilder-checkparams b/pbuilder-checkparams
index 39139a9..4f36312 100755
--- a/pbuilder-checkparams
+++ b/pbuilder-checkparams
@@ -36,6 +36,7 @@ OVERRIDE_APTLINES="no"
OVERRIDE_APTLINES_WARN="" # set this if --override-config option should be set.
BINARY_ARCH="any" # can be one of 'any', 'all', 'binary'
BIN_NMU="no"
+HOST_ARCH="${HOST_ARCH:-$ARCHITECTURE}"
PBUILDER_BUILD_LOGFILE=
PRESERVE_BUILDPLACE="no"
unset EXTRA_CONFIGFILE || true
@@ -89,9 +90,25 @@ while [ -n "$1" ]; do
shift; shift;
;;
--architecture)
+ # if we were doing a native build before, still continue to be native
+ if [ "$ARCHITECTURE" = "$HOST_ARCH" ]; then
+ HOST_ARCH=$2
+ fi
ARCHITECTURE="$2";
shift; shift;
;;
+ --host-arch)
+ HOST_ARCH="$2"
+ shift 2
+ ;;
+ --no-auto-cross)
+ if [ "$NO_AUTO_CROSS" = "yes" ]; then
+ NO_AUTO_CROSS="really-dont-mess-with-me"
+ else
+ NO_AUTO_CROSS=yes
+ fi
+ shift
+ ;;
--components)
COMPONENTS="$2";
OVERRIDE_APTLINES_WARN=yes
diff --git a/pbuilder-modules b/pbuilder-modules
index e6a9e08..8a3914a 100644
--- a/pbuilder-modules
+++ b/pbuilder-modules
@@ -902,6 +902,8 @@ function executehooks () {
log.i "user script $fn starting"
BUILDDIR="$BUILDDIR" \
DISTRIBUTION="$DISTRIBUTION" \
+ BUILD_ARCH="$ARCHITECTURE" \
+ HOST_ARCH="$HOST_ARCH" \
$CHROOTEXEC "/$hooks/$(basename "$fn")"
log.i "user script $fn finished"
else
diff --git a/pbuilder-satisfydepends-apt b/pbuilder-satisfydepends-apt
index dfcae6f..c984424 100755
--- a/pbuilder-satisfydepends-apt
+++ b/pbuilder-satisfydepends-apt
@@ -58,6 +58,10 @@ function checkbuilddep_internal () {
;;
esac
+ if [[ "$BUILD_ARCH" != "$HOST_ARCH" ]]; then
+ APTGETOPT[${#APTGETOPT[@]}]="--host-architecture=$HOST_ARCH"
+ fi
+
$CHROOTEXEC apt-get \
-y \
"${APTGETOPT[@]}" \
@@ -76,6 +80,7 @@ pbuilder-satisfydepends -- satisfy dependencies
--chroot <chroot>: operate inside this chroot
--binary-all: include binary-all
--binary-arch: include binary-arch only
+--host-arch <arch>: perform a cross-build targetting this architecture
--echo: echo mode, do nothing.
EOF
diff --git a/pbuilder-satisfydepends-checkparams b/pbuilder-satisfydepends-checkparams
index 684b700..6f7e384 100755
--- a/pbuilder-satisfydepends-checkparams
+++ b/pbuilder-satisfydepends-checkparams
@@ -20,6 +20,8 @@
# module to satisfy build dependencies; parse command line parameters
+BUILD_ARCH="$(dpkg --print-architecture)"
+HOST_ARCH="$BUILD_ARCH"
DEBIAN_CONTROL=debian/control
CHROOT=""
CHROOTEXEC=""
@@ -91,6 +93,14 @@ while [ -n "$1" ]; do
EATMYDATA=yes
shift
;;
+ --build-arch)
+ BUILD_ARCH=$2
+ shift 2
+ ;;
+ --host-arch)
+ HOST_ARCH=$2
+ shift 2
+ ;;
--help|-h|*)
print_help
exit 1
diff --git a/pbuilder.8 b/pbuilder.8
index 23adfcd..6cab78b 100644
--- a/pbuilder.8
+++ b/pbuilder.8
@@ -220,10 +220,41 @@ or
.TP
.BI "\-\-architecture [" "architecture" "]"
-Specifies the architecture to use when creating the chroot, defaults to the
+Specifies the
+.B build architecture
+(as described in
+.BR dpkg\-architecture (1)).
+It'll be the architecture used when creating the chroot, defaults to the
system one. The supported values are the ones debootstrap supports.
.TP
+.BI "\-\-host-arch [" "architecture" "]"
+Specifies the
+.B host architecture
+(as described in
+.BR dpkg\-architecture (1)).
+Defaults to the build architecture.
+Use this flag if you are interested in doing a cross architecture build.
+pbuilder will make sure the environment is correctly set up, including adding
+.I nocheck
+to
+.B DEB_BUILD_OPTIONS
+and
+.BR DEB_BUILD_PROFILES .
+
+.TP
+.B \-\-no\-auto\-cross
+Suppress automatic addition of
+.I nocheck
+to
+.B DEB_BUILD_OPTIONS
+and
+.B DEB_BUILD_PROFILES
+in case of cross-building. All the other configuration (adding the architecture
+to dpkg, installing the cross toolchain, passing --host-arch to dpkg-buildpackage,
+etc) is done nonetheless; specify this flag twice to prevent that from happening too.
+
+.TP
.BI "\-\-components [" "components" "]"
Specifies the default distribution components to use. eg. "main contrib non-free".
Default is "main".
diff --git a/pbuilderrc.5 b/pbuilderrc.5
index 6bfb27f..4381968 100644
--- a/pbuilderrc.5
+++ b/pbuilderrc.5
@@ -40,11 +40,16 @@ By default, this value is empty,
allowing the usual configuration options
to take effect.
Setting this variable overrides other options.
+
.TP
.BI "ARCHITECTURE=" "`dpkg \-\-print\-architecture`"
-Specify the default distribution to use.
-This option only affects when doing
-.B "pbuilder create"
+Specifies the
+.B build architecture
+(as described in
+.BR dpkg\-architecture (1)).
+It'll be the architecture used when creating the chroot, defaults to the
+ system one. The supported values are the ones debootstrap supports.
+
.TP
.BI "AUTOCLEANAPTCACHE=" "yes"
Always run with
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/pbuilder.git
More information about the Pbuilder-maint
mailing list