diff options
author | Mark Ferrell <major@homeonderanged.org> | 2014-04-08 08:49:23 -0700 |
---|---|---|
committer | Mark Ferrell <major@homeonderanged.org> | 2014-04-08 08:49:23 -0700 |
commit | cb63919358fd9f0f2f0274a92329743ace0cbcee (patch) | |
tree | 491dcb17c3e8ca52fec3c5482f44a62265d10287 | |
parent | 0079cb176a470615cfa87443bfa485d7fc281ffe (diff) |
Add 'import()' functionality
* Added support for a sub-cmd to "import" the contents of another command.
This requires special rewrites to the sub-commands to be viable.
-rwxr-xr-x | build | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -46,6 +46,31 @@ cleanup() test -p "${BUILDER_PIPE}" && rm -f "${BUILDER_PIPE}" } +## import +# import a builder library. +# During import a library can check 'BUILDER_CALL_STACK' to see if it equals +# '__main__'. If it does, then the library is being executed directly. +# Further more, builder-libraries can do load-time tests in order to perform +# various one-time optimizations. +# +# Note: this is borrowed from 'shlib' almost verbatim w/ the only change being +# the variable names. +import() +{ + set -- "${1}" "`echo "${1}" | tr '-' '_'`" + test -f "${BUILDER_LIBDIR}/${1}" || die "library does not exist '${1}'" + eval "test -z '\${BUILDER_IMPORT_${2}}'" || return + BUILDER_CALL_STASH="${BUILDER_CALL_STACK}" + BUILDER_CALL_STACK="${BUILDER_CALL_STACK} ${1}" . "${BUILDER_CALL_LIBDIR}/${1}" + eval "BUILDER_IMPORT_${2}='${BUILDER_LIBDIR}/${1}" + if [ -z "${BUILDER_IMPORTED}" ]; then + BUILDER_IMPORTED="${1}" + else + BUILDER_IMPORTED="${BUILDER_IMPORTED} ${1}" + fi + BUILDER_CALL_STACK="${BUILDER_CALL_STASH}" +} + ## load_rules <package> # load the Buildrules of a package into the current program space load_rules() @@ -155,6 +180,10 @@ if [ -z "${TOPDIR}" ]; then exit 1 fi +# We are being executed as 'build <cmd>' +BUILDER_CALL_STACK='__main__' +export BUILDER_CALL_STACK + # set the builtin defaults based on TOPDIR. We export TOPDIR as BUILDER_TOPDIR # to avoid stepping on the potential usage of TOPDIR within package Makefiles BUILDER_TOPDIR="${TOPDIR}" |