From 0079cb176a470615cfa87443bfa485d7fc281ffe Mon Sep 17 00:00:00 2001 From: Mark Ferrell Date: Tue, 8 Apr 2014 08:45:26 -0700 Subject: Properly support arguments to sub commands * We needed some way to detect when a sub-command was being called by the make engine vs by a user so we could properly handle the 'help' command. This involved a lot of decoupling of the make handling out of the top-level 'build' tool and placing it into a newly created 'build-make'. * While we where at it we cleaned up the handling of various targets in makedeps so that 'all/all' is now a valid target, and subsequently, the default target. --- libexec/build-help | 5 +- libexec/build-make | 112 +++++++++++++++++++++++++++++++++++++++++++++ libexec/build-make-export | 2 +- libexec/build-make-package | 2 +- libexec/build-make-source | 2 +- libexec/build-makedeps | 56 ++++++++++------------- 6 files changed, 144 insertions(+), 35 deletions(-) create mode 100755 libexec/build-make (limited to 'libexec') diff --git a/libexec/build-help b/libexec/build-help index e6f2dc5..d1eefdf 100755 --- a/libexec/build-help +++ b/libexec/build-help @@ -4,7 +4,10 @@ while test "$#" -gt '0'; do case "${1}" in (--) shift; break;; (-*) die "unknown option '${1}'";; - (*) exec build "${1}" --help;; + (*) if test -x "${BUILDER_LIBDIR}/build-make-${1}"; then + exec build "make-${1}" --help + fi + exec build "${1}" --help;; esac done diff --git a/libexec/build-make b/libexec/build-make new file mode 100755 index 0000000..07c2634 --- /dev/null +++ b/libexec/build-make @@ -0,0 +1,112 @@ +#!/usr/bin/env build + +while test "$#" -gt '0'; do + case "${1}" in + (-h|-help|--help) usage; exit 0;; + (--) shift; break;; + (-*) error "unknown optopn '${1}'" + echo "try 'build help make'" >&2 + exit 1;; + (*) break;; + esac +done + +if test "$#" -eq '0'; then + error 'no make action specified' + echo "try 'build help make'" >&2 + exit 1 +fi + +BUILDER_MAKE_ACTION="${1}" +shift + +# This allows 'build install --help' to work. +for arg; do + case "${arg}" in + (-h|-help|--help) exec build make-"${BUILDER_MAKE_ACTION}" --help;; + esac +done + +# If no target is given, then base our target on the current working directory, +# falling back to "${PROJECT}/all" as our default. +if test "$#" -eq '0'; then + # Are we somewhere within the pkg structure. If this test succeeds + # then we are at least in a category directory within the pkgdir. Just + # being in pkgdir is not enough to change our default argument list + # handling. + NAME="${TARGET}" + if [ "${PWD##${BUILDER_PKGDIR}/}" != "${PWD}" ]; then + category="${PWD##${BUILDER_PKGDIR}/}" + if [ "${category%%/*}" != "${category}" ]; then + name="${category#*/}" + category="${category%%/*}" + NAME="${category}/${name%%/*}" + else + NAME="${category}/all" + fi + unset category + unset name + fi + set -- "${NAME}" +fi + +# FIXME move this to a sub-command to be used by other tools. +for package in "$@"; do + # If all is specified anywhere in the argument list than just discard + # everything else. + case "${package}" in + (-*|all) continue;; + esac + + # FIXME we need a resolver for things like all/all and /all + CATEGORY="${package%%/*}" + if [ "${CATEGORY}" != 'all' ]; then + if [ ! -d "${BUILDER_PKGDIR}/${CATEGORY}" ]; then + die "invalid package category '${CATEGORY}'" + fi + if [ "${package##*/}" != "all" ]; then + if ! build-query --exists "${package}"; then + exit 1 + fi + fi + fi +done + +# sort/uniq the argument list +# FIXME need a way to "resolve" the package list instead of possibly clobbering +# it. +set -- $(for package in "$@"; do echo "${package}" ; done | sort | uniq) + +# build the Makefile +trap cleanup EXIT +test -d "${BUILDER_TMPDIR}" || mkdir -p "${BUILDER_TMPDIR}" +BUILDER_MAKEFILE="$(mktemp "${BUILDER_TMPDIR}/builder_makefile.XXXXXXXX")" +if [ ! -f "${BUILDER_MAKEFILE}" ]; then + die "failed to generate build dependencies" +fi +export BUILDER_MAKEFILE +"${BUILDER_LIBDIR}/build-makedeps" || die "failed generate build dependencies" + +packages= +for package in "$@"; do + case "${package}" in + (*/all);; + (*) package="$(build-query --pkgname "${package}")";; + esac + package="$(echo "${package}"|tr '/-' '__')" + packages="${packages} ${package}_${BUILDER_MAKE_ACTION}" +done +set -- ${packages} +unset packages + +# The 'tee' command will discard the exit status from 'make', so we have to +# jump through a few hoops to capture the exit status in a portable fashion. +BUILDER_PIPE="`mktemp "${BUILDER_TMPDIR}/builder_pipe.XXXXXXXX"`" +test -f "${BUILDER_PIPE}" || die 'failed to generate log-pipe placeholder' +rm -f "${BUILDER_PIPE}" && mkfifo "${BUILDER_PIPE}" || die 'failed to create log-pipe' +tee "${BUILDER_TMPDIR}/builder.log" < "${BUILDER_PIPE}" & +BUILDER_LOGGER="$!" +make -r -f "${BUILDER_MAKEFILE}" "${@}" > "${BUILDER_PIPE}" 2>&1 +exit $? + +# vim: filetype=sh diff --git a/libexec/build-make-export b/libexec/build-make-export index d611088..9cc7f67 100755 --- a/libexec/build-make-export +++ b/libexec/build-make-export @@ -32,7 +32,7 @@ fi cd "${T}" for url in ${SOURCE_URI}; do - file="$(build-fetch --name "${url}")" + file="$(build-make-fetch --name "${url}")" test -f "${BUILDER_SRCDIR}/${file}" || die "source does not exist '${file}'" cp "${BUILDER_SRCDIR}/${file}" "${NAME}-${VERSION}.builder/" done diff --git a/libexec/build-make-package b/libexec/build-make-package index 27940fe..24e364f 100755 --- a/libexec/build-make-package +++ b/libexec/build-make-package @@ -69,7 +69,7 @@ if [ -d "${SOURCE_DIR}" -o -L "${SOURCE_DIR}" ]; then else # FIXME this stuff needs a lot of work for url in ${SOURCE_URI}; do - file="$(build-fetch --name "${url}")" + file="$(build-make-fetch --name "${url}")" if [ ! -f "${BUILDER_SRCDIR}/${file}" ]; then die "source does not exist '${file}'" fi diff --git a/libexec/build-make-source b/libexec/build-make-source index 4b9e14c..975fa27 100755 --- a/libexec/build-make-source +++ b/libexec/build-make-source @@ -34,7 +34,7 @@ build_source_args() build_source() { - file="$(build-fetch --name "${1}")" + file="$(build-make-fetch --name "${1}")" if [ ! -f "${BUILDER_SRCDIR}/${file}" ]; then die "source does not exist '${file}'" fi diff --git a/libexec/build-makedeps b/libexec/build-makedeps index d19a499..73802f3 100755 --- a/libexec/build-makedeps +++ b/libexec/build-makedeps @@ -2,11 +2,11 @@ cat >"${BUILDER_MAKEFILE}" <> "${BUILDER_MAKEFILE}" all_clean: ${PACKAGES_CLEAN} exports_clean all_distclean: sysroot_clean artifacts_clean tmpdir_clean exports_clean +all_all_distclean: all_distclean +all_all_clean: all_clean EOF # vim: filetype=sh -- cgit v1.2.3-70-g09d2