Add "postprocessing" to substituted variables

... and reduce the number of variables defined explicitly.

Signed-off-by: Alexey Neyman <stilor@att.net>
This commit is contained in:
Alexey Neyman 2017-08-24 14:58:14 -07:00
parent 2d7efa5591
commit 4c1a12f5dd
5 changed files with 111 additions and 96 deletions

View File

@ -77,13 +77,16 @@ find_end()
set_iter()
{
local name="${1}"
local -a temp
if [ "${info[iter_${name}]+set}" = "set" ]; then
error "Iterator over '${name}' is already set up"
fi
shift
debug "Setting iterator over '${name}' to '$*'"
temp=("$@")
info[iter_${name}]="$*"
info[#${name}]=${#temp[@]}
}
run_if()
@ -150,7 +153,7 @@ run_lines()
{
local start="${1}"
local end="${2}"
local l lnext s s1 v
local l lnext s s1 v vp pp p val
debug "Running lines ${start}..${end}"
l=${start}
@ -166,8 +169,34 @@ run_lines()
*@@*@@*)
v="${s#*@@}"
v="${v%%@@*}"
# $v now includes variable name + any postprocessing
vp="${v%%[|?]*}"
pp="${v#${vp}}"
# $vp is name of the variable proper, $pp is any postprocessing
if [ "${info[${vp}]+set}" != "set" ]; then
error "line ${l}: reference to undefined variable '${vp}'"
fi
if [ "${info[${v}]+set}" != "set" ]; then
error "line ${l}: reference to undefined variable '${v}'"
# We know the base variable, need to cache postprocessed value
val="${info[${vp}]}"
# Apply postprocessing(s)
while [ -n "${pp}" ]; do
case "${pp}" in
"|"*)
# Kconfigize
pp="${pp#|}"
val=${val//[^0-9A-Za-z_]/_}
val=${val^^}
;;
"?"*)
pp="${pp#?}"
p="${pp%%[|?]*}"
pp="${pp#${p}}"
val="${val:+${p}}"
;;
esac
done
info[${v}]="${val}"
fi
s1="${s1}${s%%@@*}\${info[${v}]}"
s="${s#*@@*@@}"
@ -221,15 +250,14 @@ run_template()
########################################
# Convert the argument to a Kconfig-style macro
kconfigize()
# Leave only relevant portion of the string
relevantize()
{
local v="${1}"
local p pb pa vx
local v="${1}"
shift
# If optional patterns are provided, find the first match
# and contract to the matching portion.
# Find the first match and contract to the matching portion.
for p in "$@"; do
pb=${p%|*}
pa=${p#*|}
@ -239,9 +267,7 @@ kconfigize()
break
fi
done
v=${v//[^0-9A-Za-z_]/_}
echo "${v^^}"
echo "${v}"
}
# Helper for cmp_versions: compare an upstream/debian portion of
@ -484,11 +510,11 @@ enter_fork()
info[mirrors]=
info[archive_filename]='@{pkg_name}-@{version}'
info[archive_dirname]='@{pkg_name}-@{version}'
info[versionlocked]=
info[origin]=
eval `read_package_desc ${fork}`
info[pfx]=`kconfigize ${fork}`
info[originpfx]=`kconfigize ${info[origin]}`
if [ -r "packages/${info[origin]}.help" ]; then
info[originhelp]=`sed 's/^/ /' "packages/${info[origin]}.help"`
else
@ -499,7 +525,6 @@ enter_fork()
info[vcs]=${info[repository]%% *}
info[repository_url]=${info[repository]#* }
fi
info[versionlocked]=`kconfigize "${info[versionlocked]}"`
versions=`cd packages/${fork} && \
for f in */version.desc; do [ -r "${f}" ] && echo "${f%/version.desc}"; done`
@ -525,16 +550,11 @@ enter_fork()
enter_version()
{
local -A ver_postfix=( \
[,yes,,]=" (OBSOLETE)" \
[,,yes,]=" (EXPERIMENTAL)" \
[,yes,yes,]=" (OBSOLETE,EXPERIMENTAL)" )
local version="${1}"
eval `read_version_desc ${info[fork]} ${version}`
info[ver]=${version}
info[kcfg]=`kconfigize ${version} ${info[relevantpattern]}`
info[ver_postfix]=${ver_postfix[,${info[obsolete]},${info[experimental]},]}
info[ver_sel]=`relevantize ${version} ${info[relevantpattern]}`
}
enter_milestone()
@ -543,7 +563,6 @@ enter_milestone()
local cmp
info[ms]=${ms}
info[ms_kcfg]=`kconfigize ${ms}`
if [ -n "${info[ver]}" ]; then
info[version_cmp_milestone]=`cmp_versions ${info[ver]} ${info[ms]}`
fi
@ -579,9 +598,7 @@ gen_packages()
# Base definitions for the whole config file
info=( \
[master]=${p} \
[masterpfx]=`kconfigize ${p}` \
[nforks]=${pkg_nforks[${p}]} \
[all_milestones]=${pkg_milestones[${p}]} \
[relevantpattern]=${pkg_relevantpattern[${p}]} \
)
set_iter fork ${pkg_forks[${p}]}
@ -615,7 +632,6 @@ enter_choice()
local l
info[choice]="${choice}"
info[kcfg_choice]=`kconfigize "${choice}"`
# Not local, we need these arrays be set in enter_dependency/enter_help
deplines=( )
@ -653,7 +669,6 @@ gen_selection()
msg "Generating ${dir}.in"
exec >"${config_gen_dir}/${dir}.in"
info=( \
[prefix]=`kconfigize ${dir}` \
[dir]=${dir} \
[label]="${label}" \
)

View File

@ -2,11 +2,11 @@
# DO NOT EDIT! This file is automatically generated.
#
choice GEN_CHOICE_@@prefix@@
choice GEN_CHOICE_@@dir|@@
bool "@@label@@"
#!foreach choice
config @@prefix@@_@@kcfg_choice@@
config @@dir|@@_@@choice|@@
bool "@@choice@@"
#!foreach dependency
@@depline@@
@ -19,14 +19,14 @@ config @@prefix@@_@@kcfg_choice@@
#!end-foreach
endchoice
config @@prefix@@
config @@dir|@@
string
#!foreach choice
default "@@choice@@" if @@prefix@@_@@kcfg_choice@@
default "@@choice@@" if @@dir|@@_@@choice|@@
#!end-foreach
#!foreach choice
if @@prefix@@_@@kcfg_choice@@
if @@dir|@@_@@choice|@@
source "config/@@dir@@/@@choice@@.in"
endif
#!end-foreach

View File

@ -3,7 +3,7 @@
#
#!foreach choice
menuconfig @@prefix@@_@@kcfg_choice@@
menuconfig @@dir|@@_@@choice|@@
bool "@@choice@@"
#!foreach dependency
@@depline@@
@ -13,7 +13,7 @@ menuconfig @@prefix@@_@@kcfg_choice@@
@@helpline@@
#!end-foreach
if @@prefix@@_@@kcfg_choice@@
if @@dir|@@_@@choice|@@
source "config/@@dir@@/@@choice@@.in"
endif

View File

@ -3,7 +3,7 @@
#
# The component directory name
config @@masterpfx@@_DIR_NAME
config @@master|@@_DIR_NAME
string
default "@@master@@"
@ -13,7 +13,7 @@ choice
bool "Show @@master@@ versions from"
#!foreach fork
config @@masterpfx@@_USE_@@originpfx@@
config @@master|@@_USE_@@origin|@@
bool "@@origin@@"
#!if [ -n "@@only_obsolete@@" ]
depends on OBSOLETE
@ -27,20 +27,20 @@ config @@masterpfx@@_USE_@@originpfx@@
#!end-foreach
endchoice
config @@masterpfx@@_USE
config @@master|@@_USE
string
#!foreach fork
default "@@pfx@@" if @@masterpfx@@_USE_@@originpfx@@
default "@@fork|@@" if @@master|@@_USE_@@origin|@@
#!end-foreach
#!end-if
#!foreach fork
#!if [ "@@nforks@@" -ge 2 ]
if @@masterpfx@@_USE_@@originpfx@@
if @@master|@@_USE_@@origin|@@
#!end-if
config @@pfx@@_PKG_NAME
config @@fork|@@_PKG_NAME
string
default "@@pkg_name@@"
@ -51,16 +51,16 @@ config @@pfx@@_PKG_NAME
choice
bool "Source of @@pkg_label@@"
#!if [ -n "@@all_versions@@" ]
config @@pfx@@_SRC_RELEASE
#!if [ "@@#version@@" -gt 0 ]
config @@fork|@@_SRC_RELEASE
bool "Released tarball"
help
Download a released tarball.
#!end-if
config @@pfx@@_SRC_DEVEL
config @@fork|@@_SRC_DEVEL
bool "Vendor/custom repository"
#!if [ -n "@@all_versions@@" ]
#!if [ "@@#version@@" -gt 0 ]
depends on EXPERIMENTAL
#!end-if
help
@ -69,39 +69,39 @@ config @@pfx@@_SRC_DEVEL
Default is the vendor repository at @@repository_url@@
#!end-if
if @@pfx@@_SRC_DEVEL
if @@fork|@@_SRC_DEVEL
choice
bool "VCS type"
#!if [ -n "@@repository@@" ]
default @@pfx@@_DEVEL_VCS_@@vcs@@
default @@fork|@@_DEVEL_VCS_@@vcs@@
#!end-if
help
Version control system from which the sources will be checked out.
The default value points to the development repository for @@pkg_label@@.
config @@pfx@@_DEVEL_VCS_git
config @@fork|@@_DEVEL_VCS_git
bool "Git"
config @@pfx@@_DEVEL_VCS_svn
config @@fork|@@_DEVEL_VCS_svn
bool "Subversion"
config @@pfx@@_DEVEL_VCS_hg
config @@fork|@@_DEVEL_VCS_hg
bool "Mercurial"
config @@pfx@@_DEVEL_VCS_cvs
config @@fork|@@_DEVEL_VCS_cvs
bool "CVS"
endchoice
config @@pfx@@_DEVEL_VCS
config @@fork|@@_DEVEL_VCS
string
default "git" if @@pfx@@_DEVEL_VCS_git
default "svn" if @@pfx@@_DEVEL_VCS_svn
default "hg" if @@pfx@@_DEVEL_VCS_hg
default "cvs" if @@pfx@@_DEVEL_VCS_cvs
default "git" if @@fork|@@_DEVEL_VCS_git
default "svn" if @@fork|@@_DEVEL_VCS_svn
default "hg" if @@fork|@@_DEVEL_VCS_hg
default "cvs" if @@fork|@@_DEVEL_VCS_cvs
config @@pfx@@_DEVEL_URL
config @@fork|@@_DEVEL_URL
string "Repository URL"
#!if [ -n "@@repository@@" ]
default "@@repository_url@@"
@ -112,7 +112,7 @@ config @@pfx@@_DEVEL_URL
For CVS, enter both the value of CVS root and the module name, separated
by a space.
config @@pfx@@_DEVEL_BRANCH
config @@fork|@@_DEVEL_BRANCH
string "Branch/tag to check out"
default "@@repository_branch@@"
help
@ -122,7 +122,7 @@ config @@pfx@@_DEVEL_BRANCH
stable branches. You likely need to change the repository URL, rather than
enter anything here.
config @@pfx@@_DEVEL_REVISION
config @@fork|@@_DEVEL_REVISION
string "Revision/changeset"
default "@@repository_cset@@"
help
@ -131,7 +131,7 @@ config @@pfx@@_DEVEL_REVISION
CVS: enter the date in "YYYY/MM/DD HH:MM:SS" format (UTC) to check out certain date.
Subversion: enter the revision.
config @@pfx@@_DEVEL_SUBDIR
config @@fork|@@_DEVEL_SUBDIR
string "Subdirectory in the repository"
default "@@repository_subdir@@"
help
@ -139,7 +139,7 @@ config @@pfx@@_DEVEL_SUBDIR
repository, but rather from some subdirectory. If it is the case,
specify this subdirectory here.
config @@pfx@@_DEVEL_BOOTSTRAP
config @@fork|@@_DEVEL_BOOTSTRAP
string "Bootstrap command"
default "@@bootstrap@@"
help
@ -150,15 +150,15 @@ config @@pfx@@_DEVEL_BOOTSTRAP
endif
config @@pfx@@_SRC_CUSTOM
config @@fork|@@_SRC_CUSTOM
bool "Custom location"
depends on EXPERIMENTAL
help
Custom directory or tarball.
if @@pfx@@_SRC_CUSTOM
if @@fork|@@_SRC_CUSTOM
config @@pfx@@_CUSTOM_LOCATION
config @@fork|@@_CUSTOM_LOCATION
string "Custom source location"
help
Path to the directory or tarball with the sources.
@ -174,7 +174,7 @@ endchoice
#!// where we need to identify a range of releases on a branch, for example,
#!// "all FOO releases after 4.9.1 but before 4.9.3".
#!//
#!if [ -n "@@all_versions@@" -a -z "@@versionlocked@@" ]
#!if [ "@@#version@@" -gt 0 -a -z "@@versionlocked@@" ]
choice
bool "Version of @@pkg_label@@"
help
@ -184,18 +184,18 @@ choice
Based on this version, crosstool-NG may apply some version-specific
quirks while building @@pkg_label@@.
config @@pfx@@_VERY_NEW
config @@fork|@@_VERY_NEW
bool "newer than anything below"
depends on EXPERIMENTAL
depends on @@pfx@@_SRC_DEVEL || @@pfx@@_SRC_CUSTOM
depends on @@fork|@@_SRC_DEVEL || @@fork|@@_SRC_CUSTOM
#!foreach milestone
select @@masterpfx@@_@@ms_kcfg@@_or_later
depends on !@@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_older
select @@master|@@_@@ms|@@_or_later
depends on !@@master|@@_REQUIRE_@@ms|@@_or_older
#!end-foreach
#!foreach version
config @@pfx@@_V_@@kcfg@@
bool "@@ver@@@@ver_postfix@@"
config @@fork|@@_V_@@ver_sel|@@
bool "@@ver@@@@obsolete? (OBSOLETE)@@@@experimental? (EXPERIMENTAL)@@"
#!if [ "@@obsolete@@" = "yes" ]
depends on OBSOLETE
#!end-if
@ -204,26 +204,26 @@ config @@pfx@@_V_@@kcfg@@
#!end-if
#!foreach milestone
#!if [ "@@version_cmp_milestone@@" -ge 0 ]
select @@masterpfx@@_@@ms_kcfg@@_or_later
select @@master|@@_@@ms|@@_or_later
#!end-if
#!if [ "@@version_cmp_milestone@@" -le 0 ]
select @@masterpfx@@_@@ms_kcfg@@_or_older
select @@master|@@_@@ms|@@_or_older
#!end-if
#!if [ "@@version_cmp_milestone@@" -gt 0 ]
depends on !@@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_older
depends on !@@master|@@_REQUIRE_@@ms|@@_or_older
#!end-if
#!if [ "@@version_cmp_milestone@@" -lt 0 ]
depends on !@@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_later
depends on !@@master|@@_REQUIRE_@@ms|@@_or_later
#!end-if
#!end-foreach
#!end-foreach
config @@pfx@@_VERY_OLD
config @@fork|@@_VERY_OLD
bool "older than anything above"
depends on OBSOLETE && EXPERIMENTAL
depends on @@pfx@@_SRC_DEVEL || @@pfx@@_SRC_CUSTOM
depends on @@fork|@@_SRC_DEVEL || @@fork|@@_SRC_CUSTOM
#!foreach milestone
depends on !@@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_later
depends on !@@master|@@_REQUIRE_@@ms|@@_or_later
#!end-foreach
endchoice
@ -231,46 +231,46 @@ endchoice
#!if [ -n "@@versionlocked@@" ]
#!foreach version
config @@pfx@@_V_@@kcfg@@
config @@fork|@@_V_@@ver_sel|@@
def_bool y
depends on @@versionlocked@@_V_@@kcfg@@
depends on @@versionlocked|@@_V_@@ver_sel|@@
#!end-foreach
#!end-if
config @@pfx@@_VERSION
config @@fork|@@_VERSION
string
#!foreach version
default "@@ver@@" if @@pfx@@_V_@@kcfg@@
default "@@ver@@" if @@fork|@@_V_@@ver_sel|@@
#!end-foreach
default "unknown"
#!if [ -n "@@all_versions@@" ]
config @@pfx@@_MIRRORS
#!if [ "@@#version@@" -gt 0 ]
config @@fork|@@_MIRRORS
string
#!foreach version
default "@@mirrors@@" if @@pfx@@_V_@@kcfg@@
default "@@mirrors@@" if @@fork|@@_V_@@ver_sel|@@
#!end-foreach
default "@@mirrors@@"
config @@pfx@@_ARCHIVE_FILENAME
config @@fork|@@_ARCHIVE_FILENAME
string
#!foreach version
default "@@archive_filename@@" if @@pfx@@_V_@@kcfg@@
default "@@archive_filename@@" if @@fork|@@_V_@@ver_sel|@@
#!end-foreach
default "@@archive_filename@@"
config @@pfx@@_ARCHIVE_DIRNAME
config @@fork|@@_ARCHIVE_DIRNAME
string
#!foreach version
default "@@archive_dirname@@" if @@pfx@@_V_@@kcfg@@
default "@@archive_dirname@@" if @@fork|@@_V_@@ver_sel|@@
#!end-foreach
default "@@archive_dirname@@"
config @@pfx@@_ARCHIVE_FORMATS
config @@fork|@@_ARCHIVE_FORMATS
string
#!foreach version
default "@@archive_formats@@" if @@pfx@@_V_@@kcfg@@
default "@@archive_formats@@" if @@fork|@@_V_@@ver_sel|@@
#!end-foreach
default "@@archive_formats@@"
@ -284,18 +284,18 @@ endif
#!foreach milestone
#!// Milestones selected by a chosen version of this package
config @@masterpfx@@_@@ms_kcfg@@_or_later
config @@master|@@_@@ms|@@_or_later
bool
config @@masterpfx@@_@@ms_kcfg@@_or_older
config @@master|@@_@@ms|@@_or_older
bool
#!// Milestone requirements selected by other packages that restrict
#!// the choices in this package
config @@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_later
config @@master|@@_REQUIRE_@@ms|@@_or_later
bool
config @@masterpfx@@_REQUIRE_@@ms_kcfg@@_or_older
config @@master|@@_REQUIRE_@@ms|@@_or_older
bool
#!end-foreach

View File

@ -2,12 +2,12 @@
#!foreach version
run_pkgversion \
master=@@master@@ \
masterpfx=@@masterpfx@@ \
originpfx=@@originpfx@@ \
masterpfx=@@master|@@ \
originpfx=@@origin|@@ \
pkg_name=@@pkg_name@@ \
pfx=@@pfx@@ \
versionlocked=@@versionlocked@@ \
pfx=@@fork|@@ \
versionlocked=@@versionlocked|@@ \
ver=@@ver@@ \
kcfg=@@kcfg@@
kcfg=@@ver_sel|@@
#!end-foreach
#!end-foreach