summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2019-10-03 17:28:19 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2019-10-03 18:48:11 +0200
commit013ae54851fa282d6636321f29abc445f2060530 (patch)
tree82b9492af633a27dff4ed7fb2253cddbb226baa5
parent90162a8149210a6cf883487209c40dc3c3f785d6 (diff)
downloadptxdist-013ae54851fa282d6636321f29abc445f2060530.tar.gz
ptxdist-013ae54851fa282d6636321f29abc445f2060530.tar.xz
ptxdist: improve variable printing
This adds a new 'printnext' command. It prints the value of the value of the variable. The print code is refactored to allow this. The make error must be parsed to determine which variable is undefined. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
-rwxr-xr-xbin/ptxdist34
-rw-r--r--doc/ref_parameter.inc9
-rw-r--r--rules/other/Toplevel.make48
3 files changed, 78 insertions, 13 deletions
diff --git a/bin/ptxdist b/bin/ptxdist
index 1c473809f..a04715b4b 100755
--- a/bin/ptxdist
+++ b/bin/ptxdist
@@ -1011,6 +1011,8 @@ Misc:
package-info <package> print some basic information about the package
print <var> print the contents of a variable, in the way
it is known by "make"
+ printnext <var> assumes that the contents of <var> is another
+ variable and print the contents of this variable
list-packages print a list of all selected packages
local-src <pkg> [<directory>] overwrite a package source with a locally provided
directory containing the sourcecode.
@@ -2089,10 +2091,16 @@ EOF
ptxd_make_log "${pkgs[@]/%/.${cmd}}"
exit
;;
+ printnext)
+ make_vars=( "${@}" )
+ set --
+ ;&
print)
- if [ ${#} -eq 0 ]; then
+ local tmpfd
+ if [ ${#} -eq 0 -a ${#make_vars[*]} -eq 0 ]; then
exit 1
fi
+ exec {tmpfd}>&1
while [ ${#} -gt 0 ]; do
if [[ ! ( "${1}" =~ "/" ) ]] && ([ -n "${!1}" ]) 2>/dev/null; then
if [ "${PTXDIST_VERBOSE}" = "1" ]; then
@@ -2100,19 +2108,23 @@ EOF
fi
echo "${!1}"
else
- local check
- if [ -z "${check}" ]; then
- check_config &&
- check_deps || exit 1
- check=1
- fi
- ptxd_make_log "/print-${1}" 2>/dev/null || {
- echo "${1} undefined" >&2
- exit 1
- }
+ make_vars[${#make_vars[*]}]="${1}"
fi
shift
done
+ if [ ${#make_vars[*]} -gt 0 ]; then
+ local prefix
+ check_config &&
+ check_deps || exit 1
+ if [ "${cmd}" = "print" ]; then
+ prefix="/print-"
+ else
+ prefix="/printnext-"
+ fi
+ ptxd_make_log "${make_vars[@]/#/${prefix}}" 2>&1 1>&${tmpfd} | \
+ sed 's/^.*##\(.*\)##.*$/\1 undefined/' >&2
+ check_pipe_status || exit 1
+ fi
exit
;;
test)
diff --git a/doc/ref_parameter.inc b/doc/ref_parameter.inc
index 18ea01ae2..74689b9d3 100644
--- a/doc/ref_parameter.inc
+++ b/doc/ref_parameter.inc
@@ -224,6 +224,15 @@ Misc Actions
with the given name. If none exists, it will run make on all selected package
rules, determine if a variable with the given name is known to make, and if
so, print it.
+ For make variables, <var> can contain '%'. In this case, all variables
+ that match the pattern are printed.
+ If the <var> is undefined, then an error will be generated unless '-k' is
+ used. In that case an empty value is returned.
+
+``printnext <var>``
+ assume that the contents of <var> is another variable and print the
+ contents of this variable. Shell variables are currently not checked here.
+ All other rules for ``print`` apply.
``list-packages``
print a list of all selected packages. This list does not include the
diff --git a/rules/other/Toplevel.make b/rules/other/Toplevel.make
index ef410043d..857500d11 100644
--- a/rules/other/Toplevel.make
+++ b/rules/other/Toplevel.make
@@ -136,9 +136,53 @@ include $(PTX_DGEN_DEPS_POST)
# just the "print" target
# ----------------------------------------------------------------------------
+#
+# expand variable names
+# - if $(1) contains '%' then return all matching variables
+# otherwise if $(1) is a defined variable, then return it
+# - if no match is found generate an error or return $(1) if make is
+# called with '-k'
+#
+define ptx/check-expand
+$(or $(filter $(1),$(.VARIABLES)),$(if $(filter k,$(MAKEFLAGS)),$(1),$(error ##$(1)##)))
+endef
+
+#
+# print the given variable
+# if PTXDIST_VERBOSE=1 then prefix it with '<name>='
+#
+define ptx/print-var
+$(info $(if $(filter 1,$(PTXDIST_VERBOSE)),$(1)=)$(call add_quote,$($(1))))
+endef
+
+#
+# expand $(1) to one or more variables and print each one
+#
+define ptx/print-vars
+$(foreach v,$(call ptx/check-expand,$(1)),$(call ptx/print-var,$(v)))
+endef
+
+#
+# Pattern target to allow printing variable
+# $(filter ..) is used to match against all existing variables so patterns
+# containing '%' can be uses to print multiple variables.
+# In verbose mode, '<name>=<value>' is printed.
+# Trying to print undefined variables results in an error unless '-k' is
+# used. In this case an empty value is printed.
+#
/print-%: FORCE
- @:$(foreach v,$(or $(filter $(*),$(.VARIABLES)),$(if $(filter k,$(MAKEFLAGS)),$(*),$(error $(*) undefined))),\
- $(info $(if $(filter 1,$(PTXDIST_VERBOSE)),$(v)=)$(call add_quote,$($(v)))))
+ @:$(call ptx/print-vars,$(*))
+
+#
+# As above but tread the variable value as another variable and prints
+# the value of this variable.
+# Patterns are expanded as above on both levels.
+# Printing stops at the first error.
+#
+/printnext-%: FORCE
+ @:$(foreach v,$(call ptx/check-expand,$(*)),\
+ $(foreach vv,$($(v)),\
+ $(call ptx/print-vars,$(vv))))
# for backwards compatibility
print-%: /print-%