Skip to contentSkip to conversation

improve formatting of OE run.do_configure etc scripts

PATCH In review Andre McCurdy 2 participants 5 messages Jan 28, 2016 – Jan 29, 2016

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 8852209..4a48a61 100644
@@ -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
#2 lore raw

PATCH 2/3 data.py: avoid double newlines at the end of functions in emit_var()

In reply to Andre McCurdy

A 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
index fac57da..70ba56b 100644
@@ -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
#3 lore raw

PATCH 3/3 data.py: sort variables being output by emit_func()

In reply to 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.

---
 lib/bb/data.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bb/data.py +7 -1
index 70ba56b..07f4bba 100644
@@ -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
#4 lore raw

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.

---
 lib/bb/data.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
lib/bb/data.py +0 -0
index 70ba56b..07f4bba 100644
@@ -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"))

lib/bb/data.py +2 -0
+    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'))

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 not d.getVarFlag(key, "func") and d.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