Skip to contentSkip to conversation

sanity.bbclass: uppercase check for machine and distro

PATCH In review Yeoh Ee Peng 2 participants 2 messages Sep 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sanity.bbclass: uppercase check for machine and distro

Uppercase in machine and distro will result in unexpected behavior.

QA check will produce error message if it verified that machine or distro is uppercase.

---
 meta/classes/sanity.bbclass | 9 +++++++++
 1 file changed, 9 insertions(+)
meta/classes/sanity.bbclass +9 -0
index 1feb794..82efaef 100644
@@ -694,6 +694,13 @@ def sanity_check_locale(d):
     except locale.Error:
         raise_sanity_error("You system needs to support the en_US.UTF-8 locale.", d)
 
+def check_name_uppercase(type, name):
+    import re
+    messages = ""
+    if re.search('[A-Z]', name):
+        messages = messages + "%s: '%s' is uppercase. Please correct it to lowercase to avoid unexpected behavior.\n" % (type, name)
+    return messages
+    
 def check_sanity_everybuild(status, d):
     import os, stat
     # Sanity tests which test the users environment so need to run at each build (or are so cheap
@@ -723,6 +730,7 @@ def check_sanity_everybuild(status, d):
     # need to take into account DISTRO renaming DISTRO
     distro = d.getVar('DISTRO')
     if distro and distro != "nodistro":
+        status.addresult(check_name_uppercase('DISTRO', d.getVar('DISTRO')))    
         if not ( check_conf_exists("conf/distro/${DISTRO}.conf", d) or check_conf_exists("conf/distro/include/${DISTRO}.inc", d) ):
             status.addresult("DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % d.getVar("DISTRO"))
 
@@ -743,6 +751,7 @@ def check_sanity_everybuild(status, d):
     # Check that the MACHINE is valid, if it is set
     machinevalid = True
     if d.getVar('MACHINE'):
+        status.addresult(check_name_uppercase('MACHINE', d.getVar('MACHINE')))
         if not check_conf_exists("conf/machine/${MACHINE}.conf", d):
             status.addresult('MACHINE=%s is invalid. Please set a valid MACHINE in your local.conf, environment or other configuration file.\n' % (d.getVar('MACHINE')))
             machinevalid = False
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 lines · Yeoh Ee Peng

Uppercase in machine and distro will result in unexpected behavior.

Wouldn't other checks make sense as well; e.g. underscore or starting with "pn-" ?

I'd prefer a whitelist check instead of an ever growing number of blacklist checks.

// Martin

Quoted 43 lines

QA check will produce error message if it verified that machine or distro is uppercase.

---
  meta/classes/sanity.bbclass | 9 +++++++++
  1 file changed, 9 insertions(+)
meta/classes/sanity.bbclass +9 -0
index 1feb794..82efaef 100644
@@ -694,6 +694,13 @@ def sanity_check_locale(d):
      except locale.Error:
          raise_sanity_error("You system needs to support the en_US.UTF-8 locale.", d)
 
+def check_name_uppercase(type, name):
+    import re
+    messages = ""
+    if re.search('[A-Z]', name):
+        messages = messages + "%s: '%s' is uppercase. Please correct it to lowercase to avoid unexpected behavior.\n" % (type, name)
+    return messages
+
  def check_sanity_everybuild(status, d):
      import os, stat
      # Sanity tests which test the users environment so need to run at each build (or are so cheap
@@ -723,6 +730,7 @@ def check_sanity_everybuild(status, d):
      # need to take into account DISTRO renaming DISTRO
      distro = d.getVar('DISTRO')
      if distro and distro != "nodistro":
+        status.addresult(check_name_uppercase('DISTRO', d.getVar('DISTRO')))
          if not ( check_conf_exists("conf/distro/${DISTRO}.conf", d) or check_conf_exists("conf/distro/include/${DISTRO}.inc", d) ):
              status.addresult("DISTRO '%s' not found. Please set a valid DISTRO in your local.conf\n" % d.getVar("DISTRO"))
 
@@ -743,6 +751,7 @@ def check_sanity_everybuild(status, d):
      # Check that the MACHINE is valid, if it is set
      machinevalid = True
      if d.getVar('MACHINE'):
+        status.addresult(check_name_uppercase('MACHINE', d.getVar('MACHINE')))
          if not check_conf_exists("conf/machine/${MACHINE}.conf", d):
              status.addresult('MACHINE=%s is invalid. Please set a valid MACHINE in your local.conf, environment or other configuration file.\n' % (d.getVar('MACHINE')))
              machinevalid = False
Signature · 8 lines
MARTIN HUNDEBØLL, Prevas A/S
Software Developer

Hedeager 3, DK-8200 Aarhus N
Phone +45 87438070
Mobile +45 25562438
[email protected]
www.prevas.com