Skip to content

Commit

Permalink
local config override, part 2
Browse files Browse the repository at this point in the history
Package configs now parameterized using associative arrays and so can
be overridden in `local-config.sh`.

- Move package distro checks to distro.sh
- Guess package compression from tarball
- Move proxy functions out of `init-cli.sh`

Completes #9, 'Add local config override file'
  • Loading branch information
zultron committed Apr 12, 2015
1 parent a0ccf83 commit af53da9
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 219 deletions.
2 changes: 1 addition & 1 deletion dbuild
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ case $MODE in
;;

CONFIGURE_PKG) # -C: (Internal use) Pre-build configure script
( cd $BUILD_SRC_DIR && configure_package; )
run_configure_package_func
;;

##### Functions run inside Docker container #####
Expand Down
10 changes: 7 additions & 3 deletions scripts/architecture.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ arch_host() {
local ARCH=$2

if test $ARCH = 'default'; then
ARCH=$(arch_default)
ARCH=$(arch_default $DISTRO)
fi
echo $ARCH
}

arch_build() {
# For non-binary pkg builds, simply return the host arch.
#
# The build arch for a package is the host arch if the package
# cannot be cross-built. Otherwise, if the host arch is a
# 'personality' of the machine arch (e.g. amd64->i386), use the
Expand All @@ -24,8 +26,10 @@ arch_build() {
local ARCH=$2
local HOST_ARCH=$(arch_host $DISTRO $ARCH)

if $NATIVE_BUILD_ONLY || \
! distro_base_repo $DISTRO $HOST_ARCH >/dev/null; then
if ! mode BUILD_PACKAGE || \
${PACKAGE_NATIVE_BUILD_ONLY[$PACKAGE]} || \
! distro_base_repo $DISTRO $HOST_ARCH >/dev/null;
then
echo $HOST_ARCH
return
fi
Expand Down
3 changes: 2 additions & 1 deletion scripts/debian-binary-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ binary_package_check_arch() {
local ARCH=$(arch_host $DISTRO $HOST_ARCH)

# Check package's list of excluded arches
for a in $EXCLUDE_ARCHES; do
for a in ${PACKAGE_EXCLUDE_ARCHES[$PACKAGE]}; do
if test $a = $ARCH; then
error "Package $PACKAGE excluded from arch $ARCH"
fi
Expand All @@ -24,6 +24,7 @@ binary_package_build() {
msg "Building binary package '$PACKAGE'"
source_package_init
binary_package_check_arch
distro_check_package $DISTRO $PACKAGE
ccache_setup
sbuild_build_package
}
Expand Down
31 changes: 16 additions & 15 deletions scripts/debian-debzn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ parse_changelog() {
}

debianization_init() {
test -z "$PACKAGE_VERSION" || return
test -z "$DEBIANIZATION_INIT" || return 0
DEBIANIZATION_INIT=1 # Don't do this twice

PACKAGE_VERSION=$(parse_changelog version)
debug " Upstream package version-release: $PACKAGE_VERSION"
Expand Down Expand Up @@ -38,24 +39,24 @@ debianization_init() {
}

debianization_git_tree_update() {
if test -z "$GIT_URL"; then
debug " (No GIT_URL defined; not handling debianization git tree)"
if test -z "${PACKAGE_DEBZN_GIT_URL[$PACKAGE]}"; then
debug " (No PACKAGE_DEBZN_GIT_URL defined; not handling git tree)"
return
fi

if test ! -d $DEBZN_GIT_DIR/.git; then
msg " Cloning new debianization git tree"
debug " Source: $GIT_URL"
debug " Source: ${PACKAGE_DEBZN_GIT_URL[$PACKAGE]}"
debug " Dir: $DEBZN_GIT_DIR"
debug " Git branch: ${GIT_BRANCH:-master}"
run_user git clone -o dbuild -b ${GIT_BRANCH:-master} --depth=1 \
$GIT_URL $DEBZN_GIT_DIR
debug " Git branch: ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]}"
run_user git clone -o dbuild -b ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]} \
--depth=1 ${PACKAGE_DEBZN_GIT_URL[$PACKAGE]} $DEBZN_GIT_DIR
else
msg " Updating debianization git tree"
debug " Dir: $DEBZN_GIT_DIR"
debug " Git branch: ${GIT_BRANCH:-master}"
debug " Git branch: ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]}"
run_user git --git-dir=$DEBZN_GIT_DIR/.git --work-tree=$DEBZN_GIT_DIR \
pull --ff-only dbuild ${GIT_BRANCH:-master}
pull --ff-only dbuild ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]}
fi

debug " Saving original changelog"
Expand Down Expand Up @@ -89,16 +90,16 @@ debianization_add_changelog() {
}

debianization_git_tree_unpack() {
if test -n "$GIT_URL"; then
if test -n "${PACKAGE_DEBZN_GIT_URL[$PACKAGE]}"; then
msg " Copying debianization from git tree"
debug " Debzn git dir: $DEBZN_GIT_DIR"
debug " Dest dir: $BUILD_SRC_DIR/debian"
debug " Git branch: ${GIT_BRANCH:-master}"
run_user git --git-dir=$DEBZN_GIT_DIR/.git archive \
--prefix=debian/ ${GIT_BRANCH:-master} | \
run_user tar xCf $BUILD_SRC_DIR -
debug " Git branch: ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]}"
run_user bash -c "'git --git-dir=$DEBZN_GIT_DIR/.git archive \\
--prefix=debian/ ${PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]} | \\
tar xCf $BUILD_SRC_DIR -'"
else
debug " (No GIT_URL defined; not unpacking debianization from git)"
debug " (No PACKAGE_DEBZN_GIT_URL defined; not unpacking from git)"
fi
}

42 changes: 18 additions & 24 deletions scripts/debian-orig-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,37 @@
debug " Sourcing debian-orig-tarball.sh"

source_tarball_init() {
case "$DEBIAN_PACKAGE_COMP" in
gz)
DPKG_BUILD_ARGS=-Zgzip
;;
xz)
DPKG_BUILD_ARGS=-Zxz
;;
# Default to bz2
bz2|*)
DPKG_BUILD_ARGS=-Zbzip2
DEBIAN_PACKAGE_COMP=bz2
;;
case "${PACKAGE_COMP[$PACKAGE]}" in
gz) DPKG_BUILD_ARGS=-Zgzip ;;
xz) DPKG_BUILD_ARGS=-Zxz ;;
bz2) DPKG_BUILD_ARGS=-Zbzip2 ;;
*) error "Package $PACKAGE: Unknown package compression format" ;;
esac

local BASENAME=${PACKAGE}_${PACKAGE_VER}
case "$DEBIAN_PACKAGE_FORMAT" in
case "${PACKAGE_FORMAT[$PACKAGE]}" in
'3.0 (quilt)')
DEBIAN_TARBALL=${BASENAME}.orig.tar.${DEBIAN_PACKAGE_COMP}
ORIG_TARBALL=${BASENAME}.orig.tar.${PACKAGE_COMP[$PACKAGE]}
;;
'3.0 (native)')
DEBIAN_TARBALL=${BASENAME}.tar.${DEBIAN_PACKAGE_COMP}
ORIG_TARBALL=${BASENAME}.tar.${PACKAGE_COMP[$PACKAGE]}
;;
*)
error "Package ${PACKAGE}:" \
"Unknown package format '${DEBIAN_PACKAGE_FORMAT}'"
"Unknown package format '${PACKAGE_FORMAT[$PACKAGE]}'"
;;
esac
}

source_tarball_download() {
if test -n "$TARBALL_URL"; then
if test ! -f $SOURCE_PKG_DIR/$DEBIAN_TARBALL; then
if test -n "${PACKAGE_TARBALL_URL[$PACKAGE]}"; then
if test ! -f $SOURCE_PKG_DIR/$ORIG_TARBALL; then
msg " Downloading source tarball"
debug " Source: $TARBALL_URL"
debug " Dest: $SOURCE_PKG_DIR/$DEBIAN_TARBALL"
debug " Source: ${PACKAGE_TARBALL_URL[$PACKAGE]}"
debug " Dest: $SOURCE_PKG_DIR/$ORIG_TARBALL"
run_user mkdir -p $SOURCE_PKG_DIR
run_user wget $TARBALL_URL -O $SOURCE_PKG_DIR/$DEBIAN_TARBALL
run_user wget ${PACKAGE_TARBALL_URL[$PACKAGE]} \
-O $SOURCE_PKG_DIR/$ORIG_TARBALL
else
debug " (Source tarball exists; not downloading)"
fi
Expand All @@ -49,13 +43,13 @@ source_tarball_download() {
}

source_tarball_unpack() {
if test -z "$TARBALL_URL"; then
debug " (No TARBALL_URL defined; not unpacking source tarball)"
if test -z "${PACKAGE_TARBALL_URL[$PACKAGE]}"; then
debug " (No PACKAGE_TARBALL_URL defined; not unpacking)"
return
fi

msg " Unpacking source tarball"
run_user tar xCf $BUILD_SRC_DIR $SOURCE_PKG_DIR/$DEBIAN_TARBALL \
run_user tar xCf $BUILD_SRC_DIR $SOURCE_PKG_DIR/$ORIG_TARBALL \
--strip-components=1
}

Expand Down
76 changes: 76 additions & 0 deletions scripts/debian-package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
. $SCRIPTS_DIR/debian-source-package.sh
. $SCRIPTS_DIR/debian-binary-package.sh

# List of all packages
declare PACKAGES

# Package sources
declare -A PACKAGE_TARBALL_URL
declare -A PACKAGE_DEBZN_GIT_URL
declare -A PACKAGE_DEBZN_GIT_BRANCH
declare -A PACKAGE_COMP
declare -A PACKAGE_FORMAT

# Build params
declare -A PACKAGE_SBUILD_RESOLVER
declare -A PACKAGE_NATIVE_BUILD_ONLY
declare -A PACKAGE_EXCLUDE_ARCHES

# Source package configuration
declare -A PACKAGE_CONFIGURE_DEPS
declare -A PACKAGE_CONFIGURE_FUNC

package_read_config() {
local PACKAGE=$1
PACKAGES+=" $PACKAGE"

# set up defaults
PACKAGE_TARBALL_URL[$PACKAGE]=
PACKAGE_DEBZN_GIT_URL[$PACKAGE]=
PACKAGE_DEBZN_GIT_BRANCH[$PACKAGE]="master"
PACKAGE_COMP[$PACKAGE]=
PACKAGE_FORMAT[$PACKAGE]="3.0 (quilt)"
PACKAGE_SBUILD_RESOLVER[$PACKAGE]=
PACKAGE_NATIVE_BUILD_ONLY[$PACKAGE]="false"
PACKAGE_EXCLUDE_ARCHES[$PACKAGE]=
PACKAGE_CONFIGURE_DEPS[$PACKAGE]=
PACKAGE_CONFIGURE_FUNC[$PACKAGE]=

. $PACKAGE_CONFIG_DIR/$PACKAGE.sh

# Package compression
if test -z "${PACKAGE_COMP[$PACKAGE]}"; then
case "${PACKAGE_TARBALL_URL[$PACKAGE]}" in
""|*.xz) PACKAGE_COMP[$PACKAGE]="xz" ;;
*.bz2) PACKAGE_COMP[$PACKAGE]="bz2" ;;
*.gz) PACKAGE_COMP[$PACKAGE]="gz" ;;
*) error "Package $PACKAGE: Unknown package compression format" ;;
esac
fi
}

package_read_all_configs() {
debug " Sourcing package configurations:"
for config in $PACKAGE_CONFIG_DIR/*.sh; do
local package=$(basename $config .sh)
test $package != 'template' || continue # skip template
debug " $package"
package_read_config $package
done
}

package_debug() {
for p in $PACKAGES; do
debug "package $p:"
debug " tarball url: ${PACKAGE_TARBALL_URL[$p]}"
debug " debianization git url: ${PACKAGE_DEBZN_GIT_URL[$p]}"
debug " debianization git branch: ${PACKAGE_DEBZN_GIT_BRANCH[$p]}"
debug " compression: ${PACKAGE_COMP[$p]}"
debug " format: ${PACKAGE_FORMAT[$p]}"
debug " sbuild resolver: ${PACKAGE_SBUILD_RESOLVER[$p]}"
debug " native build only: ${PACKAGE_NATIVE_BUILD_ONLY[$p]}"
debug " excluded architectures: ${PACKAGE_EXCLUDE_ARCHES[$p]}"
debug " configuration deps: ${PACKAGE_CONFIGURE_DEPS[$p]}"
debug " configuration function: ${PACKAGE_CONFIGURE_FUNC[$p]}"
done
}
1 change: 1 addition & 0 deletions scripts/debian-pkg-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ deb_repo_build() {
deb_repo_init # repo config
deb_repo_setup # set up repo, if needed
source_package_init # source pkg config
distro_check_package $DISTRO $PACKAGE

# add source pkg
msg " Removing all packages for '$PACKAGE'"
Expand Down
37 changes: 27 additions & 10 deletions scripts/debian-source-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ debug " Sourcing debian-source-package.sh"
########################################
# Source package init vars
source_package_init() {
distro_check_package $DISTRO $PACKAGE

debianization_init # Init vars after unpacking

debug " Package format: ${DEBIAN_PACKAGE_FORMAT:=3.0 (quilt)}"
debug " Package format: ${PACKAGE_FORMAT[$PACKAGE]}"
}

########################################
Expand All @@ -22,19 +24,34 @@ source_package_setup() {
msg " Preparing source directory $BUILD_SRC_DIR"
run_user rm -rf $BUILD_SRC_DIR
run_user mkdir -p $BUILD_SRC_DIR/debian

# Proxy
if test -n "$HTTP_PROXY"; then
debug " Setting proxy: $HTTP_PROXY"
export http_proxy="$HTTP_PROXY"
export https_proxy="$HTTP_PROXY"
fi

}

########################################
# Source package configuration

configure_package_wrapper() {
# Some packages may define a configuration step
if declare -f configure_package >/dev/null; then
msg " Configuring source package"
sbuild_configure_package
else
debug " (No configure_package function defined)"
configure_package() {
if test -z "${PACKAGE_CONFIGURE_FUNC[$PACKAGE]}"; then
debug " (No source pkg configure function defined)"
return
fi

sbuild_configure_package
}

run_configure_package_func() {
debug " Running configure function: ${PACKAGE_CONFIGURE_FUNC[$PACKAGE]}"
(
cd $BUILD_SRC_DIR
run ${PACKAGE_CONFIGURE_FUNC[$PACKAGE]}
)
}

########################################
Expand All @@ -46,7 +63,7 @@ source_package_build_from_tree() {
(
cd $BUILD_SRC_DIR
run_user dpkg-source -b \
--format="'${DEBIAN_PACKAGE_FORMAT}'" .
--format="'${PACKAGE_FORMAT[$PACKAGE]}'" .
)
}

Expand Down Expand Up @@ -80,7 +97,7 @@ source_package_build() {
debianization_add_changelog

# Some packages may define a configuration step
configure_package_wrapper
configure_package

# Build the source package and clean up
source_package_build_from_tree
Expand Down
Loading

0 comments on commit af53da9

Please sign in to comment.