improve formatting of OE run.do_configure etc scripts
cover improve formatting of OE run.do_configure etc scripts
Andre McCurdy (3):
build.py: minor shell_trap_code() formatting tweaks data.py: avoid double newlines at the end of functions in emit_var() data.py: sort variables being output by emit_func()
lib/bb/build.py | 5 ++--- lib/bb/data.py | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
1.9.1
PATCH 1/3 build.py: minor shell_trap_code() formatting tweaks
Fix quoting of $BASH_COMMAND and avoid wrapping at 80 columns (the script which follows is likely to contain some very long lines, so line wrapping in bb_exit_handler() looks somewhat out of place).
--- lib/bb/build.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
lib/bb/build.py +2 -3
@@ -277,9 +277,8 @@ bb_exit_handler() { case $ret in 0) ;; *) case $BASH_VERSION in - "") echo "WARNING: exit code $ret from a shell command.";; - *) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from - \"$BASH_COMMAND\"";; + "") echo "WARNING: exit code $ret from a shell command.";; + *) echo "WARNING: ${BASH_SOURCE[0]}:${BASH_LINENO[0]} exit $ret from '$BASH_COMMAND'";; esac exit $ret esac
Signature · 1 line
1.9.1
PATCH 2/3 data.py: avoid double newlines at the end of functions in emit_var()
In reply to Andre McCurdyA newline is always appended to the function body when it's written out, so strip any trailing newlines which may be there already.
--- lib/bb/data.py | 1 + 1 file changed, 1 insertion(+)
lib/bb/data.py +1 -0
@@ -227,6 +227,7 @@ def emit_var(var, o=sys.__stdout__, d = init(), all=False): if func: # NOTE: should probably check for unbalanced {} within the var + val = val.rstrip('\n') o.write("%s() {\n%s\n}\n" % (varExpanded, val)) return 1
Signature · 1 line
1.9.1
PATCH 3/3 data.py: sort variables being output by emit_func()
In reply to Andre McCurdySorting variables and separating those being exported from those being unset greatly improves the readability of OE run.do_configure, etc, shell scripts.
--- lib/bb/data.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bb/data.py +7 -1
@@ -270,7 +270,13 @@ def exported_vars(d): def emit_func(func, o=sys.__stdout__, d = init()): """Emits all items in the data store in a format such that it can be sourced by a shell.""" - keys = (key for key in d.keys() if not key.startswith("__") and not d.getVarFlag(key, "func")) + o.write('\n') + keys = sorted(key for key in d.keys() if not key.startswith("__") and not d.getVarFlag(key, "func") and not d.getVarFlag(key, 'unexport')) + for key in keys: + emit_var(key, o, d, False) + + o.write('\n') + keys = sorted(key for key in d.keys() if not key.startswith("__") and not d.getVarFlag(key, "func") and d.getVarFlag(key, 'unexport')) for key in keys: emit_var(key, o, d, False)
Signature · 1 line
1.9.1
Re: [PATCH 3/3] data.py: sort variables being output by emit_func()
Quoted 30 lines · Andre McCurdy
Sorting variables and separating those being exported from those being
unset greatly improves the readability of OE run.do_configure, etc, shell scripts.Signed-off-by Andre McCurdy <[email protected]>--- lib/bb/data.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)lib/bb/data.py +0
-0@@ -270,7 +270,13 @@ def exported_vars(d): def emit_func(func, o=sys.__stdout__, d = init()): """Emits all items in the data store in a format such that itcan be sourced by a shell."""
- keys = (key for key in
d.keys()if notkey.startswith("__")and
notd.getVarFlag(key, "func"))lib/bb/data.py +2
-0+ o.write('\n') + keys = sorted(key for key in d.keys() if not
key.startswith("__")and notd.getVarFlag(key, "func")and notd.getVarFlag(key, 'unexport'))lib/bb/data.py +5
-0+ for key in keys: + emit_var(key, o, d, False) + + o.write('\n') + keys = sorted(key for key in d.keys() if not
Quoted 4 lines
key.startswith("__")and notd.getVarFlag(key, "func")andd.getVarFlag(key, 'unexport'))
for key in keys:
emit_var(key, o, d, False)
FWIW d.keys() is very slow and best avoided if we can.
Since this code only generally runs at execution time rather than parsing, its probably not a big deal but thought I'd mention it.
Cheers,
Richard