From ce7f128c020e1347f91c6074238fc5da58c5df71 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 25 Feb 2014 14:26:18 +0100 Subject: support DEB_BUILD_PROFILES and -P for build profiles Inspired by the rest of the patch in 661537, but abstract the parsing of various ways of setting the build profiles more so it can potentially be reused and all apt parts have the same behaviour. Especially config options, cmdline options and environment will not be combined as proposed as this isn't APTs usual behaviour and dpkg doesn't do it either, so one overrides the other as it normally does. --- apt-pkg/aptconfiguration.cc | 26 +++- apt-pkg/aptconfiguration.h | 5 + apt-pkg/deb/deblistparser.cc | 2 +- apt-private/private-cmndline.cc | 2 + cmdline/apt-config.cc | 5 + cmdline/apt-get.cc | 6 + debian/control | 2 +- doc/apt-get.8.xml | 13 +- doc/apt.conf.5.xml | 9 ++ test/integration/framework | 6 + .../test-bug-661537-build-profiles-support | 147 +++++++++++++++++++++ 11 files changed, 219 insertions(+), 4 deletions(-) create mode 100755 test/integration/test-bug-661537-build-profiles-support diff --git a/apt-pkg/aptconfiguration.cc b/apt-pkg/aptconfiguration.cc index f5c758e14..3948854c6 100644 --- a/apt-pkg/aptconfiguration.cc +++ b/apt-pkg/aptconfiguration.cc @@ -426,7 +426,7 @@ void Configuration::setDefaultConfigurationForCompressors() { } } /*}}}*/ -// getCompressors - Return Vector of usbale compressors /*{{{*/ +// getCompressors - Return Vector of usealbe compressors /*{{{*/ // --------------------------------------------------------------------- /* return a vector of compressors used by apt-ftparchive in the multicompress functionality or to detect data.tar files */ @@ -508,4 +508,28 @@ Configuration::Compressor::Compressor(char const *name, char const *extension, UncompressArgs.push_back(uncompressArg); } /*}}}*/ +// getBuildProfiles - return a vector of enabled build profiles /*{{{*/ +std::vector const Configuration::getBuildProfiles() { + // order is: override value (~= commandline), environment variable, list (~= config file) + std::string profiles_env = getenv("DEB_BUILD_PROFILES") == 0 ? "" : getenv("DEB_BUILD_PROFILES"); + if (profiles_env.empty() == false) { + profiles_env = SubstVar(profiles_env, " ", ","); + std::string const bp = _config->Find("APT::Build-Profiles"); + _config->Clear("APT::Build-Profiles"); + if (bp.empty() == false) + _config->Set("APT::Build-Profiles", bp); + } + return _config->FindVector("APT::Build-Profiles", profiles_env); +} +std::string const Configuration::getBuildProfilesString() { + std::vector profiles = getBuildProfiles(); + if (profiles.empty() == true) + return ""; + std::vector::const_iterator p = profiles.begin(); + std::string list = *p; + for (; p != profiles.end(); ++p) + list.append(",").append(*p); + return list; +} + /*}}}*/ } diff --git a/apt-pkg/aptconfiguration.h b/apt-pkg/aptconfiguration.h index bf7deae85..026493c6d 100644 --- a/apt-pkg/aptconfiguration.h +++ b/apt-pkg/aptconfiguration.h @@ -117,6 +117,11 @@ public: /*{{{*/ /** \brief Return a vector of extensions supported for data.tar's */ std::vector static const getCompressorExtensions(); + + /** \return Return a vector of enabled build profile specifications */ + std::vector static const getBuildProfiles(); + /** \return Return a comma-separated list of enabled build profile specifications */ + std::string static const getBuildProfilesString(); /*}}}*/ private: /*{{{*/ void static setDefaultConfigurationForCompressors(); diff --git a/apt-pkg/deb/deblistparser.cc b/apt-pkg/deb/deblistparser.cc index a4795f15d..89f3514c9 100644 --- a/apt-pkg/deb/deblistparser.cc +++ b/apt-pkg/deb/deblistparser.cc @@ -625,7 +625,7 @@ const char *debListParser::ParseDepends(const char *Start,const char *Stop, if (unlikely(I == Stop)) return 0; - std::vector const profiles = _config->FindVector("APT::Build-Profiles"); + std::vector const profiles = APT::Configuration::getBuildProfiles(); const char *End = I; bool Found = false; diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index ef7d65f3c..b99443210 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -141,6 +141,7 @@ bool addArgumentsAPTGet(std::vector &Args, char const * const { addArg('b', "compile", "APT::Get::Compile", 0); addArg('b', "build", "APT::Get::Compile", 0); + addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg); addArg(0, "diff-only", "APT::Get::Diff-Only", 0); addArg(0, "debian-only", "APT::Get::Diff-Only", 0); addArg(0, "tar-only", "APT::Get::Tar-Only", 0); @@ -149,6 +150,7 @@ bool addArgumentsAPTGet(std::vector &Args, char const * const else if (CmdMatches("build-dep")) { addArg('a', "host-architecture", "APT::Get::Host-Architecture", CommandLine::HasArg); + addArg('P', "build-profiles", "APT::Build-Profiles", CommandLine::HasArg); addArg(0, "purge", "APT::Get::Purge", 0); addArg(0, "solver", "APT::Solver", CommandLine::HasArg); // this has no effect *but* sbuild is using it (see LP: #1255806) diff --git a/cmdline/apt-config.cc b/cmdline/apt-config.cc index 30c2a22d5..9f20b3c1b 100644 --- a/cmdline/apt-config.cc +++ b/cmdline/apt-config.cc @@ -155,6 +155,11 @@ int main(int argc,const char *argv[]) /*{{{*/ _config->Set(comp + "UncompressArg::", *a); } + std::vector const profiles = APT::Configuration::getBuildProfiles(); + _config->Clear("APT::Build-Profiles"); + for (std::vector::const_iterator p = profiles.begin(); p != profiles.end(); ++p) + _config->Set("APT::Build-Profiles::", *p); + // Match the operation CmdL.DispatchArg(Cmds); diff --git a/cmdline/apt-get.cc b/cmdline/apt-get.cc index 12e385b69..f8de80a91 100644 --- a/cmdline/apt-get.cc +++ b/cmdline/apt-get.cc @@ -970,6 +970,12 @@ bool DoSource(CommandLine &CmdL) string buildopts = _config->Find("APT::Get::Host-Architecture"); if (buildopts.empty() == false) buildopts = "-a" + buildopts + " "; + + // get all active build profiles + std::string const profiles = APT::Configuration::getBuildProfilesString(); + if (profiles.empty() == false) + buildopts.append(" -P").append(profiles).append(" "); + buildopts.append(_config->Find("DPkg::Build-Options","-b -uc")); // Call dpkg-buildpackage diff --git a/debian/control b/debian/control index 2d58d0711..5ce68414e 100644 --- a/debian/control +++ b/debian/control @@ -21,7 +21,7 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, ${apt:keyring}, gnupg Replaces: manpages-pl (<< 20060617-3~), manpages-it (<< 2.80-4~) Breaks: manpages-pl (<< 20060617-3~), manpages-it (<< 2.80-4~) Conflicts: python-apt (<< 0.7.93.2~) -Suggests: aptitude | synaptic | wajig, dpkg-dev, apt-doc, python-apt +Suggests: aptitude | synaptic | wajig, dpkg-dev (>= 1.17.2), apt-doc, python-apt Description: commandline package manager This package provides commandline tools for searching and managing as well as querying information about packages diff --git a/doc/apt-get.8.xml b/doc/apt-get.8.xml index 595ea875d..1ed08904e 100644 --- a/doc/apt-get.8.xml +++ b/doc/apt-get.8.xml @@ -371,7 +371,18 @@ by apt-get source --compile and how cross-builddependencies are satisfied. By default is it not set which means that the host architecture is the same as the build architecture (which is defined by APT::Architecture). - Configuration Item: APT::Get::Host-Architecture + Configuration Item: APT::Get::Host-Architecture. + + + + + + This option controls the activated build profiles for which + a source package is built by apt-get source --compile and + how build dependencies are satisfied. By default no build profile is active. + More than one build profile can be activated at a time by concatenating them + with a comma. + Configuration Item: APT::Build-Profiles. diff --git a/doc/apt.conf.5.xml b/doc/apt.conf.5.xml index bfc43ba29..78f6a27a2 100644 --- a/doc/apt.conf.5.xml +++ b/doc/apt.conf.5.xml @@ -177,6 +177,15 @@ DPkg::Pre-Install-Pkgs {"/usr/sbin/dpkg-preconfigure --apt";}; + + + List of all build profiles enabled for build-dependency resolution, + without the "profile." namespace prefix. + By default this list is empty. The DEB_BUILD_PROFILES + as used by &dpkg-buildpackage; overrides the list notation. + + + Default release to install packages from if more than one version is available. Contains release name, codename or release version. Examples: 'stable', 'testing', diff --git a/test/integration/framework b/test/integration/framework index 911a4d742..9c4ac87d3 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -120,6 +120,9 @@ aptwebserver() { dpkg() { command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@" } +dpkgcheckbuilddeps() { + command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@" +} aptitude() { if [ -f ./aptconfig.conf ]; then APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@" @@ -240,6 +243,9 @@ setupenvironment() { # newer gpg versions are fine without it, but play it safe for now gpg --quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev/null 2>&1 + # cleanup the environment a bit + unset GREP_OPTIONS DEB_BUILD_PROFILES + msgdone "info" } diff --git a/test/integration/test-bug-661537-build-profiles-support b/test/integration/test-bug-661537-build-profiles-support new file mode 100755 index 000000000..ae1403f71 --- /dev/null +++ b/test/integration/test-bug-661537-build-profiles-support @@ -0,0 +1,147 @@ +#!/bin/sh +set -e + +TESTDIR=$(readlink -f $(dirname $0)) +. $TESTDIR/framework +setupenvironment +configarchitecture 'amd64' 'i386' 'armel' + +insertinstalledpackage 'build-essential' 'all' '0' 'Multi-Arch: foreign' + +insertpackage 'unstable' 'foo' 'all' '1.0' +insertpackage 'unstable' 'bar' 'all' '1.0' + +insertsource 'unstable' 'buildprofiles' 'any' '1' 'Build-Depends: foo (>= 1.0) [i386 arm] , bar' + +# table from https://wiki.debian.org/BuildProfileSpec +insertsource 'unstable' 'spec-1' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-2' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-3' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-4' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-5' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-6' 'any' '1' 'Build-Depends: foo ' +# multiple stanzas not supported: error out +insertsource 'unstable' 'spec-7' 'any' '1' 'Build-Depends: foo ' +insertsource 'unstable' 'spec-8' 'any' '1' 'Build-Depends: foo ' + +setupaptarchive + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + bar +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst bar (1.0 unstable [all]) +Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + bar foo +0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded. +Inst bar (1.0 unstable [all]) +Inst foo (1.0 unstable [all]) +Conf bar (1.0 unstable [all]) +Conf foo (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=i386 + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + bar +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst bar (1.0 unstable [all]) +Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=armel + +testequal 'Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + bar +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst bar (1.0 unstable [all]) +Conf bar (1.0 unstable [all])' aptget build-dep buildprofiles -s -o APT::Architecture=i386 -P stage1 + +KEEP='Reading package lists... +Building dependency tree... +The following NEW packages will be installed: + foo +0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. +Inst foo (1.0 unstable [all]) +Conf foo (1.0 unstable [all])' +DROP='Reading package lists... +Building dependency tree... +0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.' + +msgtest 'Check if version of installed dpkg is high enough for' 'build profiles support' +if dpkg --compare-versions "$(command dpkg-query --showformat='${Version}' --show dpkg)" 'ge' '1.17.2'; then + msgpass + testwithdpkg() { + msgtest "Test with" "dpkg-checkbuilddeps -d '$1' -P '$2'" + local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testwithdpkg.output" + if dpkgcheckbuilddeps -d "$1" -P "$2" /dev/null >$OUTPUT 2>&1; then + if [ "$3" = "$DROP" ]; then + msgpass + else + cat $OUTPUT + msgfail + fi + else + if [ "$3" = "$KEEP" ]; then + msgpass + else + cat $OUTPUT + msgfail + fi + fi + } +else + msgskip + testwithdpkg() { + msgtest "Test with" "dpkg-checkbuilddeps -d '$1' -P '$2'" + msgskip + } +fi + +testprofile() { + if [ -n "$3" ]; then + testequal "$4" aptget build-dep "$1" -s -P "$3" + export DEB_BUILD_PROFILES="$(echo "$3" | tr ',' ' ')" + testequal "$4" aptget build-dep "$1" -s -o with::environment=1 + unset DEB_BUILD_PROFILES + else + testequal "$4" aptget build-dep "$1" -s + fi + testwithdpkg "$2" "$3" "$4" +} + +testprofile 'spec-1' 'foo ' '' "$KEEP" +testprofile 'spec-1' 'foo ' 'stage1' "$DROP" +testprofile 'spec-1' 'foo ' 'notest' "$KEEP" +testprofile 'spec-1' 'foo ' 'stage1,notest' "$DROP" + +testprofile 'spec-2' 'foo ' '' "$DROP" +testprofile 'spec-2' 'foo ' 'stage1' "$KEEP" +testprofile 'spec-2' 'foo ' 'notest' "$DROP" +testprofile 'spec-2' 'foo ' 'stage1,notest' "$KEEP" + +testprofile 'spec-3' 'foo ' '' "$KEEP" +testprofile 'spec-3' 'foo ' 'stage1' "$DROP" +testprofile 'spec-3' 'foo ' 'notest' "$DROP" +testprofile 'spec-3' 'foo ' 'stage1,notest' "$DROP" + +testprofile 'spec-4' 'foo ' '' "$DROP" +testprofile 'spec-4' 'foo ' 'stage1' "$KEEP" +testprofile 'spec-4' 'foo ' 'notest' "$KEEP" +testprofile 'spec-4' 'foo ' 'stage1,notest' "$KEEP" + +testprofile 'spec-5' 'foo ' '' "$KEEP" +testprofile 'spec-5' 'foo ' 'stage1' "$DROP" +testprofile 'spec-5' 'foo ' 'notest' "$KEEP" +testprofile 'spec-5' 'foo ' 'stage1,notest' "$DROP" + +testprofile 'spec-6' 'foo ' '' "$KEEP" +testprofile 'spec-6' 'foo ' 'stage1' "$KEEP" +testprofile 'spec-6' 'foo ' 'notest' "$DROP" +testprofile 'spec-6' 'foo ' 'stage1,notest' "$KEEP" + +testfailure aptget build-dep spec-7 -s +testfailure aptget build-dep spec-8 -s -- cgit v1.2.3