public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Adriaan Schmidt <adriaan.schmidt@siemens.com>
To: <isar-users@googlegroups.com>
Cc: Adriaan Schmidt <adriaan.schmidt@siemens.com>,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: [PATCH 2/3] isar-sstate: refactor exit codes and error messages
Date: Tue, 19 Jul 2022 08:16:27 +0200	[thread overview]
Message-ID: <20220719061628.192078-3-adriaan.schmidt@siemens.com> (raw)
In-Reply-To: <20220719061628.192078-1-adriaan.schmidt@siemens.com>

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(-)

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
-- 
2.30.2


  parent reply	other threads:[~2022-07-19  6:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-19  6:16 [PATCH 0/3] isar-sstate improvements Adriaan Schmidt
2022-07-19  6:16 ` [PATCH 1/3] fix(isar-sstate): catch errors in signature comparison Adriaan Schmidt
2022-07-19  7:05   ` Henning Schild
2022-07-19  8:11     ` Schmidt, Adriaan
2022-07-19  6:16 ` Adriaan Schmidt [this message]
2022-07-19  6:16 ` [PATCH 3/3] docs(isar-sstate): update documentation of lint command Adriaan Schmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220719061628.192078-3-adriaan.schmidt@siemens.com \
    --to=adriaan.schmidt@siemens.com \
    --cc=felix.moessbauer@siemens.com \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox