refactor and fix determining environment file name
added getting environment file, library path and build source from subcommands env_file,lib,build_srcmaster
parent
f8d0c78bf6
commit
4386cf8c29
45
build
45
build
|
@ -3,7 +3,7 @@
|
||||||
udbuild () {
|
udbuild () {
|
||||||
|
|
||||||
local targets=(dev arm64 amd64 publish multi default)
|
local targets=(dev arm64 amd64 publish multi default)
|
||||||
local log_dir; local no_prompt; local packages
|
local log_dir; local no_prompt; local packages; local befile
|
||||||
declare -A dimage; declare -A dinstall; declare -A dupdate
|
declare -A dimage; declare -A dinstall; declare -A dupdate
|
||||||
|
|
||||||
declare OPTION; declare OPTARG; declare OPTIND
|
declare OPTION; declare OPTARG; declare OPTIND
|
||||||
|
@ -18,16 +18,32 @@ BUILD_EFILE=""
|
||||||
case "$1" in
|
case "$1" in
|
||||||
try)
|
try)
|
||||||
shift 1; try_container "$@"; return $? ;;
|
shift 1; try_container "$@"; return $? ;;
|
||||||
load_env_file)
|
|
||||||
echo -e "@@@@@@ loading build environment file for external use @@@@@@"
|
env_file)
|
||||||
BUILD_EFILE=$(echo -- "$@" | grep -oP -- '(?<=-e )[^ ]*')
|
shift 1
|
||||||
if source_env_file "$BUILD_EFILE"; then
|
befile=$(echo -- "$@" | grep -oP -- '(?<=-e )[^ ]*')
|
||||||
echo -e "@@@@@@@@@@@@@@@@@ returning to calling script @@@@@@@@@@@@@@@"
|
env_file ${befile:-$BUILD_EFILE} ;
|
||||||
else
|
return $?
|
||||||
return 1
|
;;
|
||||||
fi
|
|
||||||
|
lib)
|
||||||
|
shift 1
|
||||||
|
echo $BDIR/lib/build.lib
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
|
||||||
|
build_src)
|
||||||
|
shift 1
|
||||||
|
befile=$(echo -- "$@" | grep -oP -- '(?<=-e )[^ ]*')
|
||||||
|
befile=${befile:-$BUILD_EFILE}
|
||||||
|
if befile=$(env_file $befile); then
|
||||||
|
[[ $befile ]] && source_env_file $befile
|
||||||
|
get_build_src
|
||||||
|
return $?
|
||||||
|
else
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
build_src) shift 1; get_build_src "$@"; return $? ;;
|
|
||||||
help)
|
help)
|
||||||
;&
|
;&
|
||||||
--help)
|
--help)
|
||||||
|
@ -142,9 +158,10 @@ done
|
||||||
|
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
|
||||||
|
|
||||||
[[ ! $BUILD_EFILE ]] && source_env_file
|
[[ ! $BUILD_EFILE ]] && source_env_file
|
||||||
|
|
||||||
if ! get_build_src; then
|
if ! get_build_src > /dev/null ; then
|
||||||
if [[ $no_prompt ]] ; then
|
if [[ $no_prompt ]] ; then
|
||||||
echo aborting the build...
|
echo aborting the build...
|
||||||
echo -e "\e[1;31mNOTE: use '_core_' to explicitly build with only the UCI core repo\e[1;37m"
|
echo -e "\e[1;31mNOTE: use '_core_' to explicitly build with only the UCI core repo\e[1;37m"
|
||||||
|
@ -229,6 +246,8 @@ if [[ ! $BUILD_SRC = "_core_" ]]; then
|
||||||
/bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1
|
/bin/cp -a ${BUILD_SRC:-src}/. $BDIR/.src > /dev/null 2>&1
|
||||||
/bin/cp -a $BDIR/.src/rootfs/opt/env/. $BDIR/core/rootfs/opt/env > /dev/null 2>&1
|
/bin/cp -a $BDIR/.src/rootfs/opt/env/. $BDIR/core/rootfs/opt/env > /dev/null 2>&1
|
||||||
fi
|
fi
|
||||||
|
ls -la $BDIR/.src/rootfs
|
||||||
|
ls -la $BDIR/.src/rootfs/root
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo run environment directory copied to core at $BDIR/core/$_env_dir
|
echo run environment directory copied to core at $BDIR/core/$_env_dir
|
||||||
|
@ -263,6 +282,8 @@ fi
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[[ -f $BDIR/.src/custom-core.sh ]] && /bin/cp $BDIR/.src/custom-core.sh $BDIR/core/
|
||||||
|
|
||||||
pushd "$BDIR" > /dev/null || return 3
|
pushd "$BDIR" > /dev/null || return 3
|
||||||
|
|
||||||
export BUILDING=true
|
export BUILDING=true
|
||||||
|
@ -276,7 +297,7 @@ popd > /dev/null || return 4
|
||||||
|
|
||||||
# cleanup
|
# cleanup
|
||||||
echo cleaning up..
|
echo cleaning up..
|
||||||
rm -rf $BDIR/.src $BDIR/core/build.env $BDIR/core/*-permits > /dev/null 2<&1
|
rm -rf $BDIR/.src $BDIR/core/build.env $BDIR/core/custom-core.sh $BDIR/core/*-permits > /dev/null 2<&1
|
||||||
echo done cleaning
|
echo done cleaning
|
||||||
# try in container
|
# try in container
|
||||||
if [[ ($TRY_CMD || $TARGET == "dev") ]]; then
|
if [[ ($TRY_CMD || $TARGET == "dev") ]]; then
|
||||||
|
|
|
@ -53,10 +53,14 @@ clean_env_file () {
|
||||||
}
|
}
|
||||||
|
|
||||||
env_file () {
|
env_file () {
|
||||||
env=${1:-.env}
|
local efile
|
||||||
[[ -f "${env}" ]] && { echo $env; return 0; } # || echo not $env
|
efile=$(echo -- "$@" | grep -oP -- '(?<=-e )[^ ]*')
|
||||||
[[ -f "${env}.env" ]] && { echo "${env}.env"; return 0; } # || echo not ${env}.env
|
if [[ ! $efile ]]; then
|
||||||
[[ -f "${env}/.env" ]] && { echo "${env}/.env"; return 0; } # || echo not ${env}/.env
|
[[ ! "$1" == *-* ]] && efile=${1:-.env}
|
||||||
|
fi
|
||||||
|
[[ -f "$(realpath "${efile}.env" 2> /dev/null)" ]] && { echo "${efile}.env"; return 0; } # || echo not ${efile}.env
|
||||||
|
[[ -f "$(realpath "${efile}/.env" 2> /dev/null)" ]] && { echo "${efile}/.env"; return 0; } # || echo not ${efile}/.env
|
||||||
|
[[ "${efile##*.}" == "env" ]] && [[ -f "$(realpath "${efile}" 2> /dev/null)" ]] && { echo $efile; return 0; } # || echo not $env
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +94,7 @@ read_env_file() {
|
||||||
|
|
||||||
source_env_file () {
|
source_env_file () {
|
||||||
local default;local efile
|
local default;local efile
|
||||||
if efile=$(env_file ${1:-$BUILD_EFILE}); then
|
if efile=$(env_file "${@:-$BUILD_EFILE}"); then
|
||||||
[[ $efile == ".env" ]] && default=true
|
[[ $efile == ".env" ]] && default=true
|
||||||
[[ ! $(isAbsPath $efile) ]] && efile=$(realpath $efile)
|
[[ ! $(isAbsPath $efile) ]] && efile=$(realpath $efile)
|
||||||
quiet echo -e "\e[1;37m********************\e[0;37m"
|
quiet echo -e "\e[1;37m********************\e[0;37m"
|
||||||
|
@ -236,24 +240,25 @@ unset BUILD_SRC
|
||||||
|
|
||||||
if check_dir $src; then
|
if check_dir $src; then
|
||||||
BUILD_SRC=$(realpath $src)
|
BUILD_SRC=$(realpath $src)
|
||||||
|
echo $BUILD_SRC
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo build source path \'$src\' not initially found, echo looking
|
quiet echo build source path \'$src\' not initially found, echo looking
|
||||||
echo in \$PWD,\$PWD/src/,../\$PWD/src for valid build source
|
quiet echo in \$PWD,\$PWD/src/,../\$PWD/src for valid build source
|
||||||
echo to avoid this search use BUILD_SRC= in an environment file
|
quiet echo to avoid this search use BUILD_SRC= in an environment file
|
||||||
spaths="$PWD $PWD/src $(dirname $PWD)/$src $(dirname $PWD)"
|
spaths="$PWD $PWD/src $(dirname $PWD)/$src $(dirname $PWD)"
|
||||||
for spath in $spaths; do
|
for spath in $spaths; do
|
||||||
echo checking for source in: $spath
|
quiet echo checking for source in: $spath
|
||||||
if check_dir $spath; then
|
if check_dir $spath; then
|
||||||
echo found valid source directory!
|
quiet echo found valid source directory!
|
||||||
echo using $spath
|
|
||||||
BUILD_SRC=$spath
|
BUILD_SRC=$spath
|
||||||
|
echo $BUILD_SRC
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo -e "\e[1;31mERROR: unable to find a build source directory as $src \e[1;37m"
|
quiet echo -e "\e[1;31mERROR: unable to find a build source directory as $src \e[1;37m"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue