[2/3] isar-sstate: refactor exit codes and error messages

Message ID 20220719061628.192078-3-adriaan.schmidt@siemens.com
State Superseded, archived
Headers show
Series isar-sstate improvements | expand

Commit Message

Schmidt, Adriaan July 18, 2022, 10:16 p.m. UTC
The behavior of isar-sstate in error conditions is not consistent.
This patch tries to fix that:
- If an operation cannot be performed because source/target cannot be accessed
  it's a WARNING (useful when running in CI, so scripts can continue).
- The exit code returned by the script is either 0 (no error), or 1 (error), but
  never -1.
- Issues found be the lint operation are not returned as WARNINGS.

Signed-off-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 scripts/isar-sstate | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

Patch

diff --git a/scripts/isar-sstate b/scripts/isar-sstate
index 9f5c17b0..b62aec47 100755
--- a/scripts/isar-sstate
+++ b/scripts/isar-sstate
@@ -602,10 +602,9 @@  def sstate_upload(source, target, verbose, **kwargs):
     if not os.path.isdir(source):
         print(f"WARNING: source {source} does not exist. Not uploading.")
         return 0
-
     if not target.exists() and not target.create():
-        print(f"ERROR: target {target} does not exist and could not be created.")
-        return -1
+        print(f"WARNING: target {target} does not exist and could not be created. Not uploading.")
+        return 0
 
     print(f"INFO: uploading {source} to {target}")
     os.chdir(source)
@@ -636,8 +635,7 @@  def sstate_clean(target, max_age, max_sig_age, verbose, **kwargs):
         seconds_per_unit = {'s': 1, 'm': 60, 'h': 3600, 'd': 86400, 'w': 604800}
         m = re.match(r'^(\d+)(w|d|h|m|s)?', x)
         if m is None:
-            print(f"ERROR: cannot parse MAX_AGE '{max_age}', needs to be a number followed by w|d|h|m|s")
-            sys.exit(-1)
+            return None
         unit = m.group(2)
         if unit is None:
             print("WARNING: MAX_AGE without unit, assuming 'days'")
@@ -645,12 +643,15 @@  def sstate_clean(target, max_age, max_sig_age, verbose, **kwargs):
         return int(m.group(1)) * seconds_per_unit[unit]
 
     max_age_seconds = convert_to_seconds(max_age)
+    if max_age_seconds is None:
+        print(f"ERROR: cannot parse MAX_AGE '{max_age}', needs to be a number followed by w|d|h|m|s")
+        return 1
     if max_sig_age is None:
         max_sig_age = max_age
     max_sig_age_seconds = max(max_age_seconds, convert_to_seconds(max_sig_age))
 
     if not target.exists():
-        print(f"INFO: cannot access target {target}. Nothing to clean.")
+        print(f"WARNING: cannot access target {target}. Nothing to clean.")
         return 0
 
     print(f"INFO: scanning {target}")
@@ -679,7 +680,7 @@  def sstate_clean(target, max_age, max_sig_age, verbose, **kwargs):
 
 def sstate_info(target, verbose, **kwargs):
     if not target.exists():
-        print(f"INFO: cannot access target {target}. No info to show.")
+        print(f"WARNING: cannot access target {target}. No info to show.")
         return 0
 
     print(f"INFO: scanning {target}")
@@ -720,11 +721,11 @@  def sstate_info(target, verbose, **kwargs):
 
 def sstate_analyze(source, target, **kwargs):
     if not os.path.isdir(source):
-        print(f"ERROR: source {source} does not exist. Nothing to analyze.")
-        return -1
+        print(f"WARNING: source {source} does not exist. Nothing to analyze.")
+        return 0
     if not target.exists():
-        print(f"ERROR: target {target} does not exist. Nothing to analyze.")
-        return -1
+        print(f"INFO: target {target} does not exist. Nothing to analyze.")
+        return 0
 
     source = SstateFileTarget(source)
     target.enable_cache()
@@ -795,8 +796,8 @@  def sstate_analyze(source, target, **kwargs):
 def sstate_lint(target, verbose, sources_dir, build_dir, exit_code, **kwargs):
     ADDITIONAL_IGNORED_VARNAMES = 'PP'.split()
     if not target.exists():
-        print(f"ERROR: target {target} does not exist. Nothing to analyze.")
-        return -1
+        print(f"WARNING: target {target} does not exist. Nothing to analyze.")
+        return 0
 
     cache_sigs = {s.hash: s for s in target.list_all() if s.suffix.endswith('.siginfo')}
 
@@ -839,7 +840,7 @@  def sstate_lint(target, verbose, sources_dir, build_dir, exit_code, **kwargs):
     if sum_hits == 0:
         print(f'no cachability issues found (scanned {len(cache_sigs)} signatures)')
     else:
-        print(f'warning: found cachability issues (scanned {len(cache_sigs)} signatures)')
+        print(f'found cachability issues (scanned {len(cache_sigs)} signatures)')
         print(f'-> absolute paths: sources-dir {hits_srcdir}, build-dir {hits_builddir}, other {hits_other}')
     if exit_code is not None:
         return exit_code