public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
* [PATCHv2 1/3] oe-setup-builddir: Correct when validation of the templates dir is run
@ 2022-09-06 14:58 Peter Kjellerstedt
  2022-09-06 14:58 ` [PATCHv2 2/3] oe-setup-builddir: Simplify error handling Peter Kjellerstedt
  2022-09-06 14:58 ` [PATCHv2 3/3] oe-setup-builddir: Avoid shellcheck warnings Peter Kjellerstedt
  0 siblings, 2 replies; 3+ messages in thread
From: Peter Kjellerstedt @ 2022-09-06 14:58 UTC (permalink / raw)
  To: openembedded-core

The validation of the templates directory is supposed to be run as long
as $TEMPLATECONF is defined, but it was only done if the directory did
not exist.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---

PATCHv2: Added a commit description.

 scripts/oe-setup-builddir | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/scripts/oe-setup-builddir b/scripts/oe-setup-builddir
index d3c7f943e7..70f2245b16 100755
--- a/scripts/oe-setup-builddir
+++ b/scripts/oe-setup-builddir
@@ -63,11 +63,11 @@ if [ -n "$TEMPLATECONF" ]; then
             echo >&2 "Error: TEMPLATECONF value points to nonexistent directory '$TEMPLATECONF'"
             exit 1
         fi
-        templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" $TEMPLATECONF)
-        if [ ! -f "$TEMPLATECONF/../../layer.conf" -o $templatesdir != "templates" ]; then
-            echo >&2 "Error: TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
-            exit 1
-        fi
+    fi
+    templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" $TEMPLATECONF)
+    if [ ! -f "$TEMPLATECONF/../../layer.conf" -o $templatesdir != "templates" ]; then
+        echo >&2 "Error: TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
+        exit 1
     fi
     OECORELAYERCONF="$TEMPLATECONF/bblayers.conf.sample"
     OECORELOCALCONF="$TEMPLATECONF/local.conf.sample"


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCHv2 2/3] oe-setup-builddir: Simplify error handling
  2022-09-06 14:58 [PATCHv2 1/3] oe-setup-builddir: Correct when validation of the templates dir is run Peter Kjellerstedt
@ 2022-09-06 14:58 ` Peter Kjellerstedt
  2022-09-06 14:58 ` [PATCHv2 3/3] oe-setup-builddir: Avoid shellcheck warnings Peter Kjellerstedt
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Kjellerstedt @ 2022-09-06 14:58 UTC (permalink / raw)
  To: openembedded-core

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---

PATCHv2: No changes.

 scripts/oe-setup-builddir | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/scripts/oe-setup-builddir b/scripts/oe-setup-builddir
index 70f2245b16..69c33049c7 100755
--- a/scripts/oe-setup-builddir
+++ b/scripts/oe-setup-builddir
@@ -7,10 +7,12 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 #
 
-if [ -z "$BUILDDIR" ]; then
-    echo >&2 "Error: The build directory (BUILDDIR) must be set!"
+die() {
+    echo Error: "$@" >&2
     exit 1
-fi
+}
+
+[ -n "$BUILDDIR" ] || die "The build directory (BUILDDIR) must be set!"
 
 if [ "$1" = '--help' -o "$1" = '-h' ]; then
     echo 'Usage: oe-setup-builddir'
@@ -22,15 +24,9 @@ fi
 
 mkdir -p "$BUILDDIR/conf"
 
-if [ ! -d "$BUILDDIR" ]; then
-    echo >&2 "Error: The builddir ($BUILDDIR) does not exist!"
-    exit 1
-fi
-
-if [ ! -w "$BUILDDIR" ]; then
-    echo >&2 "Error: Cannot write to $BUILDDIR, perhaps try sourcing with a writable path? i.e. . oe-init-build-env ~/my-build"
-    exit 1
-fi
+[ -d "$BUILDDIR" ] || die "The build directory ($BUILDDIR) does not exist!"
+[ -w "$BUILDDIR" ] ||
+    die "Cannot write to $BUILDDIR, perhaps try sourcing with a writable path? i.e. . oe-init-build-env ~/my-build"
 
 # Attempting removal of sticky,setuid bits from BUILDDIR, BUILDDIR/conf
 chmod -st "$BUILDDIR" 2>/dev/null || echo "WARNING: unable to chmod $BUILDDIR"
@@ -59,15 +55,12 @@ if [ -n "$TEMPLATECONF" ]; then
         if [ -d "$OEROOT/$TEMPLATECONF" ]; then
             TEMPLATECONF="$OEROOT/$TEMPLATECONF"
         fi
-        if [ ! -d "$TEMPLATECONF" ]; then
-            echo >&2 "Error: TEMPLATECONF value points to nonexistent directory '$TEMPLATECONF'"
-            exit 1
-        fi
+        [ -d "$TEMPLATECONF" ] ||
+            die "TEMPLATECONF value points to nonexistent directory '$TEMPLATECONF'"
     fi
     templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" $TEMPLATECONF)
     if [ ! -f "$TEMPLATECONF/../../layer.conf" -o $templatesdir != "templates" ]; then
-        echo >&2 "Error: TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
-        exit 1
+        die "TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
     fi
     OECORELAYERCONF="$TEMPLATECONF/bblayers.conf.sample"
     OECORELOCALCONF="$TEMPLATECONF/local.conf.sample"


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCHv2 3/3] oe-setup-builddir: Avoid shellcheck warnings
  2022-09-06 14:58 [PATCHv2 1/3] oe-setup-builddir: Correct when validation of the templates dir is run Peter Kjellerstedt
  2022-09-06 14:58 ` [PATCHv2 2/3] oe-setup-builddir: Simplify error handling Peter Kjellerstedt
@ 2022-09-06 14:58 ` Peter Kjellerstedt
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Kjellerstedt @ 2022-09-06 14:58 UTC (permalink / raw)
  To: openembedded-core

This avoid the following warnings:

* SC2086: Double quote to prevent globbing and word splitting.
* SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
* SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
* SC2236: Use -n instead of ! -z.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
---

PATCHv2: No changes.

 scripts/oe-setup-builddir | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/scripts/oe-setup-builddir b/scripts/oe-setup-builddir
index 69c33049c7..b06880c9cb 100755
--- a/scripts/oe-setup-builddir
+++ b/scripts/oe-setup-builddir
@@ -14,7 +14,7 @@ die() {
 
 [ -n "$BUILDDIR" ] || die "The build directory (BUILDDIR) must be set!"
 
-if [ "$1" = '--help' -o "$1" = '-h' ]; then
+if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
     echo 'Usage: oe-setup-builddir'
     echo ''
     echo "OpenEmbedded setup-builddir - setup build directory $BUILDDIR"
@@ -32,19 +32,19 @@ mkdir -p "$BUILDDIR/conf"
 chmod -st "$BUILDDIR" 2>/dev/null || echo "WARNING: unable to chmod $BUILDDIR"
 chmod -st "$BUILDDIR/conf" 2>/dev/null || echo "WARNING: unable to chmod $BUILDDIR/conf"
 
-cd "$BUILDDIR"
+cd "$BUILDDIR" || die "Failed to change directory to $BUILDDIR!"
 
-if [ -f "$BUILDDIR/conf/templateconf.cfg" -a -z "$TEMPLATECONF" ]; then
+if [ -z "$TEMPLATECONF" ] && [ -f "$BUILDDIR/conf/templateconf.cfg" ]; then
     TEMPLATECONF=$(cat "$BUILDDIR/conf/templateconf.cfg")
     # The following two are no longer valid; unsetting them will automatically get them replaced
     # with correct ones.
-    if [ $TEMPLATECONF = "meta/conf" -o $TEMPLATECONF = "meta-poky/conf" ]; then
+    if [ "$TEMPLATECONF" = meta/conf ] || [ "$TEMPLATECONF" = meta-poky/conf ]; then
         unset TEMPLATECONF
-        rm $BUILDDIR/conf/templateconf.cfg
+        rm "$BUILDDIR/conf/templateconf.cfg"
     fi
 fi
 
-. "$OEROOT"/.templateconf
+. "$OEROOT/.templateconf"
 
 # 
 # $TEMPLATECONF can point to a directory for the template local.conf & bblayers.conf
@@ -58,8 +58,8 @@ if [ -n "$TEMPLATECONF" ]; then
         [ -d "$TEMPLATECONF" ] ||
             die "TEMPLATECONF value points to nonexistent directory '$TEMPLATECONF'"
     fi
-    templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" $TEMPLATECONF)
-    if [ ! -f "$TEMPLATECONF/../../layer.conf" -o $templatesdir != "templates" ]; then
+    templatesdir=$(python3 -c "import sys; print(sys.argv[1].strip('/').split('/')[-2])" "$TEMPLATECONF")
+    if [ "$templatesdir" != templates ] || [ ! -f "$TEMPLATECONF/../../layer.conf" ]; then
         die "TEMPLATECONF value (which is $TEMPLATECONF) must point to meta-some-layer/conf/templates/template-name"
     fi
     OECORELAYERCONF="$TEMPLATECONF/bblayers.conf.sample"
@@ -111,7 +111,7 @@ unset OECORELOCALCONF
 unset OECORELAYERCONF
 
 # Ending the first-time run message. Show the YP Documentation banner.
-if [ ! -z "$SHOWYPDOC" ]; then
+if [ -n "$SHOWYPDOC" ]; then
     cat <<EOM
 The Yocto Project has extensive documentation about OE including a reference
 manual which can be found at:


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-06 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-06 14:58 [PATCHv2 1/3] oe-setup-builddir: Correct when validation of the templates dir is run Peter Kjellerstedt
2022-09-06 14:58 ` [PATCHv2 2/3] oe-setup-builddir: Simplify error handling Peter Kjellerstedt
2022-09-06 14:58 ` [PATCHv2 3/3] oe-setup-builddir: Avoid shellcheck warnings Peter Kjellerstedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox