diff mbox series

ptest-cargo.bbclass: Support of cargo workspaces

Message ID 20230729050921.139912-1-frederic.martinsons@gmail.com
State Accepted, archived
Commit 67644c3fa7d012ad03d0a876a281d5abd5edf7fe
Headers show
Series ptest-cargo.bbclass: Support of cargo workspaces | expand

Commit Message

Frédéric Martinsons July 29, 2023, 5:09 a.m. UTC
From: Frederic Martinsons <frederic.martinsons@gmail.com>

For complex project, it is very common to have multiple
sub artifacts and so use workspaces, sometimes it has
even no root artifacts (but several bin or lib) and
virtual manifest is used for that.

Long story short, support this case in ptest-cargo class
to look for all test binaries in the current project
and no more those generated by the root Cargo.toml

Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com>
---
 meta/classes-recipe/ptest-cargo.bbclass | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/ptest-cargo.bbclass b/meta/classes-recipe/ptest-cargo.bbclass
index 5d53abe969..ff57be8525 100644
--- a/meta/classes-recipe/ptest-cargo.bbclass
+++ b/meta/classes-recipe/ptest-cargo.bbclass
@@ -16,6 +16,8 @@  python do_compile_ptest_cargo() {
     cargo_build_flags = d.getVar("CARGO_BUILD_FLAGS", True)
     rust_flags = d.getVar("RUSTFLAGS", True)
     manifest_path = d.getVar("MANIFEST_PATH", True)
+    project_manifest_path = os.path.normpath(manifest_path)
+    manifest_dir = os.path.dirname(manifest_path)
 
     env = os.environ.copy()
     env['RUSTFLAGS'] = rust_flags
@@ -46,13 +48,15 @@  python do_compile_ptest_cargo() {
             pass
         else:
             try:
-                # Filter the test packages coming from the current manifest
+                # Filter the test packages coming from the current project:
+                #    - test binaries from the root manifest
+                #    - test binaries from sub manifest of the current project if any
                 current_manifest_path = os.path.normpath(data['manifest_path'])
-                project_manifest_path = os.path.normpath(manifest_path)
-                if current_manifest_path == project_manifest_path:
+                common_path = os.path.commonpath([current_manifest_path, project_manifest_path])
+                if common_path in [manifest_dir, current_manifest_path]:
                     if (data['target']['test'] or data['target']['doctest']) and data['executable']:
                         test_bins.append(data['executable'])
-            except KeyError as e:
+            except (KeyError, ValueError) as e:
                 # skip lines that do not meet the requirements
                 pass