From 961ea1938204e4fc9199c2ff5933caaa1e3d0710 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Thu, 24 Aug 2017 15:29:55 -0700 Subject: [PATCH] Allow loops to skip entries if certain variable is kept Signed-off-by: Alexey Neyman --- bootstrap | 44 +++++++++++++++++++++++----- maintainer/kconfig-versions.template | 8 ++--- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/bootstrap b/bootstrap index e702dbbc..45fad9c8 100755 --- a/bootstrap +++ b/bootstrap @@ -91,7 +91,7 @@ set_iter() run_if() { - local cond="${1}" + local cond="$*" local endline find_end "if" @@ -125,8 +125,9 @@ do_foreach() for k in "${!info[@]}"; do saveinfo["${k}"]=${info["${k}"]} done - eval "enter_${var} ${v}" - eval "$@" + if eval "enter_${var} ${v}"; then + eval "$@" + fi info=() for k in "${!saveinfo[@]}"; do info["${k}"]=${saveinfo["${k}"]} @@ -136,19 +137,48 @@ do_foreach() run_foreach() { - local var="${1}" local endline + local var="${1}" + shift if [ "${info[iter_${var}]+set}" != "set" ]; then error "line ${l}: iterator over '${var}' is not defined" fi find_end "foreach" debug "Loop over '${var}', lines ${l}..${endline}" - do_foreach ${var} run_lines $[l + 1] $[endline - 1] + do_foreach ${var} run_lines_if $[l + 1] $[endline - 1] "$*" lnext=$[endline + 1] debug "Continue at line ${lnext}" } +run_lines_if() +{ + local start="${1}" + local end="${2}" + shift 2 + local cond="$*" + local a prev + + for a in ${cond}; do + if [ -n "${prev}" ]; then + case "${prev}" in + if-differs) + if [ "${info[${a}]}" = "${saveinfo[${a}]}" ]; then + return + fi + ;; + *) + error "line ${l}: unknown condition '${prev}' for loop" + ;; + esac + prev= + else + prev=${a} + fi + done + run_lines "${start}" "${end}" +} + run_lines() { local start="${1}" @@ -215,10 +245,10 @@ run_lines() debug "Evaluate: ${s}" case "${s}" in "#!if "*) - run_if "${s#* }" + run_if ${s#* } ;; "#!foreach "*) - run_foreach "${s#* }" + run_foreach ${s#* } ;; "#!//"*) # Comment, do nothing diff --git a/maintainer/kconfig-versions.template b/maintainer/kconfig-versions.template index 8bf4affe..0e0ceb08 100644 --- a/maintainer/kconfig-versions.template +++ b/maintainer/kconfig-versions.template @@ -248,28 +248,28 @@ config @@fork|@@_VERSION #!if [ "@@#version@@" -gt 0 ] config @@fork|@@_MIRRORS string -#!foreach version +#!foreach version if-differs mirrors default "@@mirrors@@" if @@fork|@@_V_@@ver_sel|@@ #!end-foreach default "@@mirrors@@" config @@fork|@@_ARCHIVE_FILENAME string -#!foreach version +#!foreach version if-differs archive_filename default "@@archive_filename@@" if @@fork|@@_V_@@ver_sel|@@ #!end-foreach default "@@archive_filename@@" config @@fork|@@_ARCHIVE_DIRNAME string -#!foreach version +#!foreach version if-differs archive_dirname default "@@archive_dirname@@" if @@fork|@@_V_@@ver_sel|@@ #!end-foreach default "@@archive_dirname@@" config @@fork|@@_ARCHIVE_FORMATS string -#!foreach version +#!foreach version if-differs archive_formats default "@@archive_formats@@" if @@fork|@@_V_@@ver_sel|@@ #!end-foreach default "@@archive_formats@@"