extract_utils: target_file() and target_args() cleanup
* Strip target_args from target_file at callee instead of at caller * WARNING! Changes (improperly documented) behavior of prefix_match() function, which is expected to not strip target_args(), and the root cause why stripping target_args was currently done at caller. Will be addressed in next patch. Change-Id: I820d2350aa64ff41374809fcb22f812257132652 Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
This commit is contained in:
committed by
Michael Bestas
parent
297cc3756f
commit
2e35c3376a
@@ -101,41 +101,47 @@ function setup_vendor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# target_file:
|
# input: spec in the form of "src[:dst][;args]"
|
||||||
#
|
# output: "dst" if present, "src" otherwise.
|
||||||
# $1: colon delimited list
|
|
||||||
#
|
|
||||||
# Returns destination filename without args
|
|
||||||
#
|
#
|
||||||
function target_file() {
|
function target_file() {
|
||||||
local LINE="$1"
|
local SPEC="$1"
|
||||||
local SPLIT=(${LINE//:/ })
|
local SPLIT=(${SPEC//:/ })
|
||||||
local COUNT=${#SPLIT[@]}
|
local ARGS="$(target_args ${SPEC})"
|
||||||
if [ "$COUNT" -gt "1" ]; then
|
local DST=
|
||||||
if [[ "${SPLIT[1]}" =~ .*/.* ]]; then
|
case ${#SPLIT[@]} in
|
||||||
printf '%s\n' "${SPLIT[1]}"
|
1)
|
||||||
return 0
|
# The spec doesn't have a : delimiter
|
||||||
fi
|
DST="${SPLIT[0]}"
|
||||||
fi
|
;;
|
||||||
printf '%s\n' "${SPLIT[0]}"
|
*)
|
||||||
|
# The spec actually has a src:dst format
|
||||||
|
DST="${SPLIT[1]}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
# Remove target_args suffix, if present
|
||||||
|
echo "${DST%;${ARGS}}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# target_args:
|
# input: spec in the form of "src[:dst][;args]"
|
||||||
#
|
# output: "args" if present, "" otherwise.
|
||||||
# $1: semicolon delimited list
|
|
||||||
#
|
|
||||||
# Returns optional arguments (last value) for given target
|
|
||||||
#
|
#
|
||||||
function target_args() {
|
function target_args() {
|
||||||
local LINE="$1"
|
local SPEC="$1"
|
||||||
local SPLIT=(${LINE//;/ })
|
local SPLIT=(${SPEC//;/ })
|
||||||
local COUNT=${#SPLIT[@]}
|
local ARGS=
|
||||||
if [ "$COUNT" -gt "1" ]; then
|
case ${#SPLIT[@]} in
|
||||||
if [[ ! "${SPLIT[$COUNT-1]}" =~ .*/.* ]]; then
|
1)
|
||||||
printf '%s\n' "${SPLIT[$COUNT-1]}"
|
# No ";" delimiter in the spec.
|
||||||
fi
|
;;
|
||||||
fi
|
*)
|
||||||
|
# The "args" are whatever comes after the ";" character.
|
||||||
|
# Basically the spec stripped of whatever is to the left of ";".
|
||||||
|
ARGS="${SPEC#${SPLIT[0]};}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
echo "${ARGS}"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -219,7 +225,7 @@ function write_product_copy_files() {
|
|||||||
LINEEND=""
|
LINEEND=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TARGET=$(echo $(target_file "$FILE") | sed 's/\;.*//')
|
TARGET=$(target_file "$FILE")
|
||||||
if [ "$TREBLE_COMPAT" == "true" ] || [ "$TREBLE_COMPAT" == "1" ]; then
|
if [ "$TREBLE_COMPAT" == "true" ] || [ "$TREBLE_COMPAT" == "1" ]; then
|
||||||
if prefix_match_file "vendor/" $TARGET ; then
|
if prefix_match_file "vendor/" $TARGET ; then
|
||||||
local OUTTARGET=$(truncate_file $TARGET)
|
local OUTTARGET=$(truncate_file $TARGET)
|
||||||
@@ -267,7 +273,7 @@ function write_packages() {
|
|||||||
local SRC=
|
local SRC=
|
||||||
|
|
||||||
for P in "${FILELIST[@]}"; do
|
for P in "${FILELIST[@]}"; do
|
||||||
FILE=$(echo $(target_file "$P") | sed 's/\;.*//')
|
FILE=$(target_file "$P")
|
||||||
ARGS=$(target_args "$P")
|
ARGS=$(target_args "$P")
|
||||||
|
|
||||||
BASENAME=$(basename "$FILE")
|
BASENAME=$(basename "$FILE")
|
||||||
@@ -949,7 +955,7 @@ function extract() {
|
|||||||
|
|
||||||
for (( i=1; i<COUNT+1; i++ )); do
|
for (( i=1; i<COUNT+1; i++ )); do
|
||||||
|
|
||||||
local FROM=$(echo $(target_file "${FILELIST[$i-1]}") | sed 's/\;.*//')
|
local FROM=$(target_file "${FILELIST[$i-1]}")
|
||||||
local ARGS=$(target_args "${FILELIST[$i-1]}")
|
local ARGS=$(target_args "${FILELIST[$i-1]}")
|
||||||
local SPLIT=(${FILELIST[$i-1]//:/ })
|
local SPLIT=(${FILELIST[$i-1]//:/ })
|
||||||
local FILE=$(echo "${SPLIT[0]#-}" | sed 's/\;.*//')
|
local FILE=$(echo "${SPLIT[0]#-}" | sed 's/\;.*//')
|
||||||
|
|||||||
Reference in New Issue
Block a user