On 2025-01-13 3:44 p.m., Christos Gavros via lists.openembedded.org wrote:
Some users have reported issues which were caused because they were missing the
right libstdc++-version-dev in their system.
A new function with the name 'check_cpp_toolchain' was added in sanity.bbclass
in order to verify that the host system can compile and link successfully a
'hello world' c++ code.
In case the test fails , the build will abort
Fixes [YOCTO #bug-15712]
Thanks for the patch. It's a good start!
Repeating what I said on IRC about the patchtest errors:
Maybe shortlog: sanity: test for cpp toolchain
Drop the meta-oe prefix, this is oe-core and your email will
automagically get an oe-core prefix as you can see above.
YP BZ # is optional but patchtest documented the expected format.
Signed-off-by: Christos Gavros<[email protected]>
---
meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/meta/classes-global/sanity.bbclass
b/meta/classes-global/sanity.bbclass
index 7b8a497d5a..ca7f8117d6 100644
--- a/meta/classes-global/sanity.bbclass
+++ b/meta/classes-global/sanity.bbclass
@@ -780,6 +780,44 @@ def sanity_check_locale(d):
except locale.Error:
raise_sanity_error("Your system needs to support the en_US.UTF-8
locale.", d)
+def check_cpp_toolchain():
+ # it checks if the c++ compiling and linking works properly in the native
system
The bug talks about testing, "linking to libstdc++" so best to mention that
rather than have it implied.
+ import os
+ import subprocess
+ from tempfile import NamedTemporaryFile
+
+ try:
+ with NamedTemporaryFile(delete=False, suffix=".cpp") as cpp_file:
+ cpp_code = """
+ #include <iostream>
+ int main() {
+ std::cout << "Hello, World!" << std::endl;
+ return 0;
+ }
+ """
+ cpp_file.write(cpp_code.encode('utf-8'))
+ cpp_file_name = cpp_file.name
+
+ output_binary = cpp_file_name + ".out"
+ compile_command = ['g++', '-std=c++17', cpp_file_name, '-o',
output_binary]
Maybe use BUILD_CC here?
Oddly, that variable isn't in the docs but BUILD_CC_ARCH is:
https://docs.yoctoproject.org/ref-manual/variables.html#term-BUILD_CC_ARCH
CC-ing Antonin to see if that's a bug.
Yocto/OE supportsĀ or would like support more than just GCC mostly for
target
but it would be nice to use the compiler that BUILD_CC points to so that
there isn't
too much gcc hard-coded.
+ result = subprocess.run(compile_command, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
+
+ if result.returncode == 0:
+ #os.remove(cpp_file_name)
+ #os.remove(output_binary)
Did you mean to leave these two lines commented out?
If so why? Add a comment explaining why if needed.
../Randy
+ return False
+ else:
+ bb.fatal(f"C++ toolchain check failed during compilation or linking.
Error:\n{result.stderr.decode()}")
+ return True
+ except Exception as e:
+ bb.fatal(f"An unexpected issue occured during the C++ toolchain check
{str(e)}")
+ return True
+ finally:
+ if cpp_file_name and os.path.exists(cpp_file_name):
+ os.remove(cpp_file_name)
+ if output_binary and os.path.exists(output_binary):
+ os.remove(output_binary)
+
def check_sanity_everybuild(status, d):
import os, stat
# Sanity tests which test the users environment so need to run at each
build (or are so cheap
@@ -975,6 +1013,8 @@ def check_sanity_everybuild(status, d):
# forms, such as /bin/dash, bin/bash, /bin/bash.bash ...
if '/dash' not in real_sh and '/bash' not in real_sh:
status.addresult("Error, /bin/sh links to %s, must be dash or
bash\n" % real_sh)
+
+ check_cpp_toolchain()
def check_sanity(sanity_data):
class SanityStatus(object):
--
# Randy MacLeod
# Wind River Linux
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#209764):
https://lists.openembedded.org/g/openembedded-core/message/209764
Mute This Topic: https://lists.openembedded.org/mt/110595436/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-