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]
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 + 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] + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.returncode == 0: + #os.remove(cpp_file_name) + #os.remove(output_binary) + 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): -- 2.34.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#209743): https://lists.openembedded.org/g/openembedded-core/message/209743 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]] -=-=-=-=-=-=-=-=-=-=-=-
