update: add --out option to mp-build
This commit is contained in:
@ -91,6 +91,7 @@ help_cmd() {
|
||||
echo_color " $BOLD--no-cache$RESET: don't check cache"
|
||||
echo_color " $BOLD--no-opts$RESET: don't show/list options"
|
||||
echo_color " $BOLD--cores$RESET: how many cores to use for the build"
|
||||
echo_color " $BOLD--out$RESET: directory for the output archive"
|
||||
echo
|
||||
info "Licensed under GPLv3, see <https://www.gnu.org/licenses/> for more information"
|
||||
}
|
||||
@ -149,6 +150,7 @@ OPT_NO_STDOUT=0 # PACKAGE() function output is ENABLED
|
||||
OPT_NO_CACHE=0 # cache is ENABLED
|
||||
OPT_NO_OPTS=0 # showing/listing options is ENABLED
|
||||
OPT_CORES=$(nproc) # use ALL CPU cores
|
||||
OPT_OUT="DEFAULT" # use the package dist directory for output
|
||||
|
||||
# parses all the options
|
||||
for arg in "$@"; do
|
||||
@ -166,7 +168,15 @@ for arg in "$@"; do
|
||||
"--no-opts")
|
||||
OPT_NO_OPTS=1 ;;
|
||||
"--cores"*)
|
||||
OPT_CORES=$(echo "${arg}" | cut -d "=" -f2) ;;
|
||||
OPT_CORES="$(echo "${arg}" | cut -d '=' -f2)" ;;
|
||||
"--out"*)
|
||||
OPT_OUT="$(echo "${arg}" | cut -d '=' -f2)"
|
||||
OPT_OUT="$(echo "${OPT_OUT}" | sed "s/'//g")"
|
||||
OPT_OUT="$(echo "${OPT_OUT}" | sed 's/"//g')"
|
||||
if [ ! -d "${OPT_OUT}" ]; then
|
||||
error "Failed to access to the output directory (${OPT_OUT})"
|
||||
exit 1
|
||||
fi ;;
|
||||
--*)
|
||||
error "Unknown option: ${arg}"
|
||||
exit 1 ;;
|
||||
@ -206,7 +216,8 @@ if [ $OPT_NO_OPTS -eq 0 ]; then
|
||||
print " $BOLD NO_SDTOUT = $(itoyn $OPT_NO_STDOUT)"
|
||||
print " $BOLD NO_CACHE = $(itoyn $OPT_NO_CACHE)"
|
||||
print " $BOLD NO_OPTS = $(itoyn $OPT_NO_OPTS)"
|
||||
print " $BOLD CORES = $OPT_CORES"
|
||||
print " $BOLD CORES = ${OPT_CORES}"
|
||||
print " $BOLD OUT = ${OPT_OUT}"
|
||||
fi
|
||||
|
||||
cd "${TARGET}"
|
||||
@ -236,6 +247,11 @@ fi
|
||||
pkgpath="$(realpath .)"
|
||||
cachepath="$(realpath '.cache')"
|
||||
distpath="$(realpath 'dist')"
|
||||
if [ "${OPT_OUT}" == "DEFAULT" ]; then
|
||||
outpath="${distpath}"
|
||||
else
|
||||
outpath="${OPT_OUT}"
|
||||
fi
|
||||
rootpath="$(realpath 'root')"
|
||||
|
||||
mkdir -p "${rootpath}"
|
||||
@ -249,7 +265,7 @@ if [ $OPT_NO_CACHE -eq 0 ] && [ -f "${cachepath}/last" ]; then
|
||||
package_cache=$(sed -n '1p' "${cachepath}/last")
|
||||
changes_cache=$(sed -n '2p' "${cachepath}/last")
|
||||
|
||||
if [[ "${package_cache}" == "${package_hash}" ]] && [[ "${changes_cache}" == "${changes_hash}" ]]; then
|
||||
if [ -f "${outpath}/${NAME}_${VERSION}.mpf" ] && [[ "${package_cache}" == "${package_hash}" ]] && [[ "${changes_cache}" == "${changes_hash}" ]]; then
|
||||
info "Found build in the cache (add --no-cache if you want to rebuild anyway)"
|
||||
success "Build was successful"
|
||||
exit 0
|
||||
@ -431,6 +447,12 @@ clean_dist
|
||||
info "Cleaning the root directory"
|
||||
rm -rf "${rootpath}"
|
||||
|
||||
# move archive to out directory
|
||||
if [ "$(realpath "${distpath}/${archive}")" != "$(realpath "${outpath}")" ]; then
|
||||
mv "${distpath}/${archive}" "${outpath}" 2> /dev/null
|
||||
check_ret "Failed to move the archive to the output directory"
|
||||
fi
|
||||
|
||||
# update the cache
|
||||
unset_indent
|
||||
info "Updating the package cache"
|
||||
|
Reference in New Issue
Block a user