[3/9] isar-sstate: lint: check for absolute paths in SRC_URI

Message ID 20240402172813.418770-4-chris.larson@siemens.com
State Superseded, archived
Headers show
Series Add more signature cachability tests to the testsuite | expand

Commit Message

kergoth@gmail.com April 2, 2024, 5:28 p.m. UTC
From: Christopher Larson <chris.larson@seimens.com>

In addition to the current checks for variables starting with an
absolute path, particularly those within the build or sources
directories, we should also check for absolute paths in SRC_URI
file entries.

Signed-off-by: Christopher Larson <chris.larson@siemens.com>
---
 scripts/isar-sstate | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

MOESSBAUER, Felix April 3, 2024, 6:56 a.m. UTC | #1
On Tue, 2024-04-02 at 17:28 +0000, kergoth@gmail.com wrote:
> From: Christopher Larson <chris.larson@seimens.com>
> 
> In addition to the current checks for variables starting with an
> absolute path, particularly those within the build or sources
> directories, we should also check for absolute paths in SRC_URI
> file entries.

Good idea. Thanks for adding.

Acked-by: Felix Moessbauer <felix.moessbauer@siemens.com>

> 
> Signed-off-by: Christopher Larson <chris.larson@siemens.com>
> ---
>  scripts/isar-sstate | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/scripts/isar-sstate b/scripts/isar-sstate
> index c14c2843..9b20cb8e 100755
> --- a/scripts/isar-sstate
> +++ b/scripts/isar-sstate
> @@ -839,6 +839,23 @@ def sstate_lint(target, verbose, sources_dir,
> build_dir, exit_code, pedantic, **
>                  continue
>              # remove leading whitespaces possibly added by appending
>              val = val.lstrip()
> +            if name == 'SRC_URI':
> +                src_uri = val.split()
> +                for entry in src_uri:
> +                    if entry.startswith('file:///'):
> +                        entry_path = entry[7:]
> +                        if entry_path.startswith(build_dir):
> +                            pn_issues.append(f'\033[0;31m-> path in
> build-dir:   SRC_URI entry "{entry}"\033[0m')
> +                            hits_builddir += 1
> +                        elif entry_path.startswith(sources_dir):
> +                            pn_issues.append(f'\033[0;31m-> path in
> sources-dir: SRC_URI entry "{entry}"\033[0m')
> +                            hits_srcdir += 1
> +                        else:
> +                            hits_other += 1
> +                            if verbose:
> +                                pn_issues.append(f'\033[0;34m->
> other absolute path: SRC_URI entry "{entry}"\033[0m')
> +                continue
> +
>              if not val[0] == '/':
>                  continue
>              if val.startswith(build_dir):
> -- 
> 2.39.2
>

Patch

diff --git a/scripts/isar-sstate b/scripts/isar-sstate
index c14c2843..9b20cb8e 100755
--- a/scripts/isar-sstate
+++ b/scripts/isar-sstate
@@ -839,6 +839,23 @@  def sstate_lint(target, verbose, sources_dir, build_dir, exit_code, pedantic, **
                 continue
             # remove leading whitespaces possibly added by appending
             val = val.lstrip()
+            if name == 'SRC_URI':
+                src_uri = val.split()
+                for entry in src_uri:
+                    if entry.startswith('file:///'):
+                        entry_path = entry[7:]
+                        if entry_path.startswith(build_dir):
+                            pn_issues.append(f'\033[0;31m-> path in build-dir:   SRC_URI entry "{entry}"\033[0m')
+                            hits_builddir += 1
+                        elif entry_path.startswith(sources_dir):
+                            pn_issues.append(f'\033[0;31m-> path in sources-dir: SRC_URI entry "{entry}"\033[0m')
+                            hits_srcdir += 1
+                        else:
+                            hits_other += 1
+                            if verbose:
+                                pn_issues.append(f'\033[0;34m-> other absolute path: SRC_URI entry "{entry}"\033[0m')
+                continue
+
             if not val[0] == '/':
                 continue
             if val.startswith(build_dir):