summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/ptest-cargo.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/ptest-cargo.bbclass')
-rw-r--r--meta/classes-recipe/ptest-cargo.bbclass54
1 files changed, 34 insertions, 20 deletions
diff --git a/meta/classes-recipe/ptest-cargo.bbclass b/meta/classes-recipe/ptest-cargo.bbclass
index c46df362bf..ece25ff1eb 100644
--- a/meta/classes-recipe/ptest-cargo.bbclass
+++ b/meta/classes-recipe/ptest-cargo.bbclass
@@ -12,16 +12,17 @@ python do_compile_ptest_cargo() {
12 import subprocess 12 import subprocess
13 import json 13 import json
14 14
15 cargo = bb.utils.which(d.getVar("PATH"), d.getVar("CARGO", True)) 15 cargo = bb.utils.which(d.getVar("PATH"), d.getVar("CARGO"))
16 cargo_build_flags = d.getVar("CARGO_BUILD_FLAGS", True) 16 cargo_build_flags = d.getVar("CARGO_BUILD_FLAGS")
17 rust_flags = d.getVar("RUSTFLAGS", True) 17 packageconfig_confargs = d.getVar("PACKAGECONFIG_CONFARGS")
18 manifest_path = d.getVar("CARGO_MANIFEST_PATH", True) 18 rust_flags = d.getVar("RUSTFLAGS")
19 manifest_path = d.getVar("CARGO_MANIFEST_PATH")
19 project_manifest_path = os.path.normpath(manifest_path) 20 project_manifest_path = os.path.normpath(manifest_path)
20 manifest_dir = os.path.dirname(manifest_path) 21 manifest_dir = os.path.dirname(manifest_path)
21 22
22 env = os.environ.copy() 23 env = os.environ.copy()
23 env['RUSTFLAGS'] = rust_flags 24 env['RUSTFLAGS'] = rust_flags
24 cmd = f"{cargo} build --tests --message-format json {cargo_build_flags}" 25 cmd = f"{cargo} build --tests --message-format json {cargo_build_flags} {packageconfig_confargs}"
25 bb.note(f"Building tests with cargo ({cmd})") 26 bb.note(f"Building tests with cargo ({cmd})")
26 27
27 try: 28 try:
@@ -66,7 +67,7 @@ python do_compile_ptest_cargo() {
66 if not test_bins: 67 if not test_bins:
67 bb.fatal("Unable to find any test binaries") 68 bb.fatal("Unable to find any test binaries")
68 69
69 cargo_test_binaries_file = d.getVar('CARGO_TEST_BINARIES_FILES', True) 70 cargo_test_binaries_file = d.getVar('CARGO_TEST_BINARIES_FILES')
70 bb.note(f"Found {len(test_bins)} tests, write their paths into {cargo_test_binaries_file}") 71 bb.note(f"Found {len(test_bins)} tests, write their paths into {cargo_test_binaries_file}")
71 with open(cargo_test_binaries_file, "w") as f: 72 with open(cargo_test_binaries_file, "w") as f:
72 for test_bin in test_bins: 73 for test_bin in test_bins:
@@ -76,11 +77,12 @@ python do_compile_ptest_cargo() {
76 77
77python do_install_ptest_cargo() { 78python do_install_ptest_cargo() {
78 import shutil 79 import shutil
80 import textwrap
79 81
80 dest_dir = d.getVar("D", True) 82 dest_dir = d.getVar("D")
81 pn = d.getVar("PN", True) 83 pn = d.getVar("PN")
82 ptest_path = d.getVar("PTEST_PATH", True) 84 ptest_path = d.getVar("PTEST_PATH")
83 cargo_test_binaries_file = d.getVar('CARGO_TEST_BINARIES_FILES', True) 85 cargo_test_binaries_file = d.getVar('CARGO_TEST_BINARIES_FILES')
84 rust_test_args = d.getVar('RUST_TEST_ARGS') or "" 86 rust_test_args = d.getVar('RUST_TEST_ARGS') or ""
85 87
86 ptest_dir = os.path.join(dest_dir, ptest_path.lstrip('/')) 88 ptest_dir = os.path.join(dest_dir, ptest_path.lstrip('/'))
@@ -97,17 +99,29 @@ python do_install_ptest_cargo() {
97 test_paths.append(os.path.join(ptest_path, os.path.basename(test_bin))) 99 test_paths.append(os.path.join(ptest_path, os.path.basename(test_bin)))
98 100
99 ptest_script = os.path.join(ptest_dir, "run-ptest") 101 ptest_script = os.path.join(ptest_dir, "run-ptest")
100 if os.path.exists(ptest_script): 102 script_exists = os.path.exists(ptest_script)
101 with open(ptest_script, "a") as f: 103 with open(ptest_script, "a") as f:
102 f.write(f"\necho \"\"\n") 104 if not script_exists:
103 f.write(f"echo \"## starting to run rust tests ##\"\n")
104 for test_path in test_paths:
105 f.write(f"{test_path} {rust_test_args}\n")
106 else:
107 with open(ptest_script, "a") as f:
108 f.write("#!/bin/sh\n") 105 f.write("#!/bin/sh\n")
109 for test_path in test_paths: 106 f.write("rc=0\n")
110 f.write(f"{test_path} {rust_test_args}\n") 107 else:
108 f.write(f"\necho \"\"\n")
109 f.write(f"echo \"## starting to run rust tests ##\"\n")
110 for test_path in test_paths:
111 script = textwrap.dedent(f"""\
112 if ! {test_path} {rust_test_args}
113 then
114 rc=1
115 echo "FAIL: {test_path}"
116 else
117 echo "PASS: {test_path}"
118 fi
119 """)
120 f.write(script)
121
122 f.write("exit $rc\n")
123
124 if not script_exists:
111 os.chmod(ptest_script, 0o755) 125 os.chmod(ptest_script, 0o755)
112 126
113 # this is chown -R root:root ${D}${PTEST_PATH} 127 # this is chown -R root:root ${D}${PTEST_PATH}