diff options
author | Mark Ferrell <major@homeonderanged.org> | 2014-04-14 15:49:31 -0700 |
---|---|---|
committer | Mark Ferrell <major@homeonderanged.org> | 2014-04-14 15:49:31 -0700 |
commit | e1fcde4f5af9b331a3d67d84eccc932680e75d52 (patch) | |
tree | 238787e1f8a5aa60c5b02d01c6ea368aa3bd2a26 | |
parent | 9a6baaed0f08aae9bf8f80f0fa34323e6fbb9715 (diff) |
Setup the package environment during load_rules()
* We have pulled the environment setup from build-query and moved it into
load_rules(). This means that build-query acts to query information about a
package and is reserved more as a cmdline helper for external tools. Tools
that need package variables should use load_rules instead of
'build-query --environ'.
-rwxr-xr-x | build | 81 | ||||
-rwxr-xr-x | libexec/build-make-clean | 6 | ||||
-rwxr-xr-x | libexec/build-make-compile | 4 | ||||
-rwxr-xr-x | libexec/build-make-distclean | 6 | ||||
-rwxr-xr-x | libexec/build-make-export | 4 | ||||
-rwxr-xr-x | libexec/build-make-install | 6 | ||||
-rwxr-xr-x | libexec/build-make-package | 4 | ||||
-rwxr-xr-x | libexec/build-make-prep | 4 | ||||
-rwxr-xr-x | libexec/build-make-source | 4 | ||||
-rwxr-xr-x | libexec/build-make-test | 4 | ||||
-rwxr-xr-x | libexec/build-makedeps | 5 | ||||
-rwxr-xr-x | libexec/build-query | 108 |
12 files changed, 103 insertions, 133 deletions
@@ -89,23 +89,88 @@ import() BUILDER_CALL_STACK="${BUILDER_CALL_STASH}" } +# FIXME we need a build-resolv subcmd for resolving package names +parse_pkg_name() +{ + # Only allow a single '/' in the name + if [ "1${1##*/}" != "1${1#*/}" ]; then + return 1 + fi + + if [ "2${1#*/}" != "2${1}" ]; then + printf '%s' "${1}" + else + printf '%s' "${PROJECT}/${1}" + fi +} + +parse_name() +{ + if ! parse_pkg_name "${1}" > /dev/null 2>&1; then + return "$?" + fi + + set -- "$(parse_pkg_name "${1}")" + printf '%s' "${1#*/}" +} + +parse_category() +{ + if ! parse_pkg_name "${1}" > /dev/null 2>&1; then + return "$?" + fi + + set -- "$(parse_pkg_name "${1}")" + printf '%s' "${1%/*}" +} + ## load_rules <package> # load the Buildrules of a package into the current program space load_rules() { - # Evaluate our environment data - # There is a bit of a performance penalty here in that the query - # routine will source the build-rules to finish collecting data, so we - # end up sourcing the Buildrules twice. - eval $(build-query --environ "${1}") - RELEASE= - S= + # We can aquire this data before we bother loading anything + NAME="$(parse_name "${1}")" + CATEGORY="$(parse_category "${1}")" + PKG_NAME="${CATEGORY}/${NAME}" + + if [ ! -d "${BUILDER_PKGDIR}/${PKG_NAME}" ]; then + die "no such package '${1}'" + fi + + RULESFILE="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/Buildrules" + if [ ! -f "${RULESFILE}" ]; then + die "no rulesfile for package '${1}'" + fi + + export NAME CATEGORY PKG_NAME RULESFILE + + # These variables are used by the Buildrules and fundmentally make up + # the majority of their environ data + F="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/files" + W="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/work" + L="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/log" + E="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/env" + T="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/tmp" + D="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/install" + + export F W L E T D # Source in the category Buildrules if [ -f "${BUILDER_PKGDIR}/${CATEGORY}/.buildrules" ]; then . "${BUILDER_PKGDIR}/${CATEGORY}/.buildrules" fi + # These variables are only set within a Rulesfile and thus need to be + # cleared before sourcing it in. + VERSION= + RELEASE= + DESCRIPTION= + LICENSE= + SOURCE_URI= + PATCHES= + RDEPENDS= + BDEPENDS= + # Source in the package Buildrules . "${RULESFILE}" @@ -135,6 +200,8 @@ load_rules() if test -z "${S}"; then S="${W}/${NAME}-${VERSION}" fi + + export VERSION RELEASE DESCRIPTION LICENSE SOURCE_URI PATCHES BDEPENDS RDEPENDS } if [ "${BUILDER_DEBUG:-0}" != '0' ]; then diff --git a/libexec/build-make-clean b/libexec/build-make-clean index 6ccc730..ddc000c 100755 --- a/libexec/build-make-clean +++ b/libexec/build-make-clean @@ -1,8 +1,8 @@ #!/usr/bin/env build build_make_clean() -{ - eval $(build-query --environ "${1}") +{( + load_rules "${1}" if [ -z "${NOCLEAN}" ]; then echo "cleaning: ${1}" @@ -26,7 +26,7 @@ build_make_clean() rm "${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}" fi fi -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'clean' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-compile b/libexec/build-make-compile index 7596af3..c0ff684 100755 --- a/libexec/build-make-compile +++ b/libexec/build-make-compile @@ -28,7 +28,7 @@ build_compile() pkg_compile() { build_compile; } build_make_compile() -{ +{( trap build_make_compile_cleanup 0 load_rules "${1}" @@ -90,7 +90,7 @@ build_make_compile() wait find * -depth \( ! -type d \) -print0 > "${binpkg_list}" mv "${binpkg_list}" "${D}/var/db/binpkgs/${CATEGORY}/${NAME}" -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'compile' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-distclean b/libexec/build-make-distclean index 689ae80..ba39c6e 100755 --- a/libexec/build-make-distclean +++ b/libexec/build-make-distclean @@ -1,9 +1,9 @@ #!/usr/bin/env build build_make_distclean() -{ +{( echo "distcleaning: ${1}" - eval $(build-query --environ "${1}") + load_rules "${1}" if [ -f "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" ]; then rm "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" & @@ -24,7 +24,7 @@ build_make_distclean() if [ -f "${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}" ]; then rm "${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}" fi -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'distclean' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-export b/libexec/build-make-export index 230245f..c4183f3 100755 --- a/libexec/build-make-export +++ b/libexec/build-make-export @@ -1,7 +1,7 @@ #!/usr/bin/env build build_make_export() -{ +{( load_rules "${1}" if test -z "${LICENSE}"; then @@ -93,7 +93,7 @@ build_make_export() mkdir -p "${BUILDER_TOPDIR}/exports" # FIXME figure out the arch properly mv "${S}/RPMS/${CHOST%%-*}/${NAME}-${VERSION}-${RELEASE}.${CHOST%%-*}.rpm" "${BUILDER_TOPDIR}/exports/" || die "Failed to move rpm" -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'export' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-install b/libexec/build-make-install index fd0a4e9..915a2ff 100755 --- a/libexec/build-make-install +++ b/libexec/build-make-install @@ -1,9 +1,9 @@ #!/usr/bin/env build build_make_install() -{ +{( echo "installing: ${1}" - eval $(build-query --environ "${1}") + load_rules "${1}" if [ ! -f "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" ]; then die "archive does not exist for package '${NAME}'" @@ -29,7 +29,7 @@ build_make_install() ${ARCHIVE_DECOMPRESSOR} "${BUILDER_ATFDIR}/${CATEGORY}/${NAME}-${VERSION}-${RELEASE}.${ARCHIVE_FORMAT}" | tar x touch "${SYSROOT}/var/db/binpkgs/${CATEGORY}/${NAME}" -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'install' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-package b/libexec/build-make-package index 7ae2c4d..87cf024 100755 --- a/libexec/build-make-package +++ b/libexec/build-make-package @@ -21,7 +21,7 @@ build_make_archive_cleanup() } build_make_archive() -{ +{( trap build_make_archive_cleanup 0 echo "archiving: ${1}" @@ -61,7 +61,7 @@ build_make_archive() # see if anything # is stil going. wait -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'package' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-prep b/libexec/build-make-prep index 29d5d94..f9f74db 100755 --- a/libexec/build-make-prep +++ b/libexec/build-make-prep @@ -13,7 +13,7 @@ build_make_prep_cleanup() } build_make_prep() -{ +{( trap build_make_prep_cleanup 0 build_prep() { return; } @@ -86,7 +86,7 @@ build_make_prep() fi >> "${PKG_LOGFILE}" 2>&1 done fi -} +)} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'prep' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-source b/libexec/build-make-source index e4cf324..229c341 100755 --- a/libexec/build-make-source +++ b/libexec/build-make-source @@ -12,7 +12,7 @@ build_make_source_cleanup() } build_make_source() -{ +{( build-make-prep "${1}" trap build_make_source_cleanup 0 @@ -28,7 +28,7 @@ build_make_source() PKG_LOGFILE="${L}/source.log" mv "${S}" "${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" >> "${PKG_LOGFILE}" 2>&1 -} + )} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'source' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-make-test b/libexec/build-make-test index 00af7d1..e72dfd9 100755 --- a/libexec/build-make-test +++ b/libexec/build-make-test @@ -15,7 +15,7 @@ build_make_test_cleanup() pkg_test() { echo "test: no test defined"; } build_make_test() -{ +{( trap build_make_test_cleanup 0 echo "testing: ${1}" load_rules "${1}" @@ -24,7 +24,7 @@ build_make_test() cd "${W}" pkg_test >> "${PKG_LOGFILE}" 2>&1 -} + )} if test "${BUILDER_CALL_STACK}" = '__main__'; then simple_usage 'test' '[all|[<category>/]<package|all>]' "$@" diff --git a/libexec/build-makedeps b/libexec/build-makedeps index 4a77f19..7b9d167 100755 --- a/libexec/build-makedeps +++ b/libexec/build-makedeps @@ -44,9 +44,8 @@ for package in $(echo "${BUILDER_PKGDIR}"/*/*); do error "no rulesfile for package '${package}'" continue fi - if ! eval $(build-query --environ "${package}"); then - die "in package '${package}'" - fi + + load_rules "${package}" package_make="$(echo "${package}"|tr '/-' '__')" package_source="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" diff --git a/libexec/build-query b/libexec/build-query index 6715ddb..f84aca5 100755 --- a/libexec/build-query +++ b/libexec/build-query @@ -41,40 +41,6 @@ package options: END_OF_HELP } -parse_pkg_name() -{ - # Only allow a single '/' in the name - if [ "1${1##*/}" != "1${1#*/}" ]; then - return 1 - fi - - if [ "2${1#*/}" != "2${1}" ]; then - printf '%s' "${1}" - else - printf '%s' "${PROJECT}/${1}" - fi -} - -parse_name() -{ - if ! parse_pkg_name "${1}" > /dev/null 2>&1; then - return "$?" - fi - - set -- "$(parse_pkg_name "${1}")" - printf '%s' "${1#*/}" -} - -parse_category() -{ - if ! parse_pkg_name "${1}" > /dev/null 2>&1; then - return "$?" - fi - - set -- "$(parse_pkg_name "${1}")" - printf '%s' "${1%/*}" -} - RECURSE_RDEPENDS='false' recurse_bdeps() { @@ -134,7 +100,7 @@ while [ "$#" -gt "0" ]; do (-D|-destdir|--destdir) QUERY_ACTION="destdir";; (--exists) - QUERY_ACTION="exists";; + test -e "${BUILD_PKGDIR}/${1}/Buildrules" && exit 0 || exit 1;; (-e|-envdir|--envdir) QUERY_ACTION="envdir";; (-E|-environ|--environ) @@ -242,39 +208,15 @@ if test "$#" -eq "0"; then die "no package specified" fi -# We can aquire this data before we bother loading anything -NAME="$(parse_name "${1}")" -CATEGORY="$(parse_category "${1}")" -PKG_NAME="${CATEGORY}/${NAME}" +load_rules "${1}" -if [ ! -d "${BUILDER_PKGDIR}/${PKG_NAME}" ]; then - die "no such package '${1}'" -fi - -RULESFILE="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/Buildrules" -if [ ! -f "${RULESFILE}" ]; then - die "no rulesfile for package '${1}'" +# Allow the developer to hijack the SRC_URI with a checked out repository +# FIXME this causes problems for various dep targets +if [ -d "${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" ]; then + SOURCE_URI="file://${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" fi -export NAME CATEGORY PKG_NAME RULESFILE - -shift - -# These variables are used by the Buildrules and fundmentally make up the -# majority of their environ data -F="${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/files" -W="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/work" -L="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/log" -E="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/env" -T="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/tmp" -D="${BUILDER_TMPDIR}/${CATEGORY}/${NAME}/install" - -export F W L E T D - -# These requests can be answered without sourcing the Buildrules, everything -# else needs the Rulesfile sourced in case "${QUERY_ACTION}" in -(exists) exit 0;; # Simply break out (name) echo "${NAME}";exit 0;; (category) echo "${CATEGORY}";exit 0;; (pkgname) echo "${CATEGORY}/${NAME}";exit 0;; @@ -286,46 +228,8 @@ case "${QUERY_ACTION}" in (envdir) echo "${E}";exit 0;; (tmpdir) echo "${T}";exit 0;; (destdir) echo "${D}";exit 0;; -esac - -# These variables are only set within a Rulesfile and thus need to be cleared -# before sourcing it in. -VERSION= -RELEASE= -DESCRIPTION= -LICENSE= -SOURCE_URI= -PATCHES= -RDEPENDS= -BDEPENDS= - -if [ -f "${BUILDER_PKGDIR}/${CATEGORY}/.buildrules" ]; then - . "${BUILDER_PKGDIR}/${CATEGORY}/.buildrules" -fi -. "${RULESFILE}" - -# Allow the developer to hijack the SRC_URI with a checked out repository -if [ -d "${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" ]; then - SOURCE_URI="file://${BUILDER_PKGDIR}/${CATEGORY}/${NAME}/source" -fi - -if test -z "${RELEASE}"; then - RELEASE="${VERSION#*-}" - if ! test -z "${RELEASE}" && test "${RELEASE}" != "${VERSION}"; then - VERSION="${VERSION%-${RELEASE}}" - else - RELEASE='0' - fi -fi -export VERSION RELEASE DESCRIPTION LICENSE SOURCE_URI PATCHES BDEPENDS RDEPENDS -# Ironically, the source working directory can't be assigned until we source in -# the Buildrules due to the dependancy on the VERSION -S="${W}/${NAME}-${VERSION}" -export S - -case "${QUERY_ACTION}" in (srcdir) echo "${S}";; (src_uri) echo "${SOURCE_URI}";; (bdepends) echo "$(echo ${BDEPENDS})";; |