sanity: test for c toolchain
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 sanity: test for c toolchain
Users reported issues caused by missing the right libstdc++-version-dev. A new function 'check_c_toolchain' added in sanity.bbclass to test linking libstdc++ Fixes [YOCTO #<15712>]
---v1->v2
* use shortlog
* drop the meta-oe prefix
* fix format for bug reference
* change function description including libstdc++
* use BUILD_CC instead of specific compiler
* lines in comments are removed
* patch message less than 200 char
* bb.fatal is removed
* follow pattern of other functions in class
* use docstring instead of # in functions description
* make the print out message more clear
* fix comment style where the function is called
* change "hello world" from C++ to C program
* use gcc instead of g++
--- meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
meta/classes-global/sanity.bbclass +40 -0
@@ -780,6 +780,43 @@ 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_c_toolchain(d): + """ + it checks if the c compiling and linking to libstdc++ works properly in the native system + """ + import os + import subprocess + from tempfile import NamedTemporaryFile + + try: + with NamedTemporaryFile(delete=False, suffix=".c") as c_file: + c_code = """ + #include <stdio.h> + int main() { + printf(\"Hello, World!\\n\"); + return 0; + } + """ + c_file.write(c_code.encode('utf-8')) + c_file_name = c_file.name + + build_cc = d.getVar('BUILD_CC').strip() + output_binary = c_file_name + ".out" + compile_command = [build_cc, c_file_name, '-o', output_binary,'-lstdc++'] + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.returncode == 0: + return None + else: + return f"C toolchain check failed to link against libstdc++. Please ensure libstdc++ and headers are installed. Error:\n{result.stderr.decode()}" + except Exception as e: + return f"An unexpected issue occurred during the C toolchain check: {str(e)}" + finally: + if c_file_name and os.path.exists(c_file_name): + os.remove(c_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
@@ -976,6 +1013,9 @@ def check_sanity_everybuild(status, d): 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 if linking with lstdc++ is failing + status.addresult(check_c_toolchain(d)) + def check_sanity(sanity_data): class SanityStatus(object): def __init__(self):
Signature · 1 line
2.34.1
Patchtest results for [PATCH v2] sanity: test for c toolchain
Thank you for your submission. Patchtest identified one or more issues with the patch. Please see the log below for more information:
---
Testing patch /home/patchtest/share/mboxes/v2-sanity-test-for-c-toolchain.patch
FAIL: test bugzilla entry format: Bugzilla issue ID is not correctly formatted - specify it with format: "[YOCTO #<bugzilla ID>]" (test_mbox.TestMbox.test_bugzilla_entry_format)
PASS: test Signed-off-by presence (test_mbox.TestMbox.test_signed_off_by_presence)
PASS: test author valid (test_mbox.TestMbox.test_author_valid)
PASS: test commit message presence (test_mbox.TestMbox.test_commit_message_presence)
PASS: test commit message user tags (test_mbox.TestMbox.test_commit_message_user_tags)
PASS: test max line length (test_metadata.TestMetadata.test_max_line_length)
PASS: test mbox format (test_mbox.TestMbox.test_mbox_format)
PASS: test non-AUH upgrade (test_mbox.TestMbox.test_non_auh_upgrade)
PASS: test shortlog format (test_mbox.TestMbox.test_shortlog_format)
PASS: test shortlog length (test_mbox.TestMbox.test_shortlog_length)
PASS: test target mailing list (test_mbox.TestMbox.test_target_mailing_list)
SKIP: pretest pylint: No python related patches, skipping test (test_python_pylint.PyLint.pretest_pylint)
SKIP: pretest src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.pretest_src_uri_left_files)
SKIP: test CVE check ignore: No modified recipes or older target branch, skipping test (test_metadata.TestMetadata.test_cve_check_ignore)
SKIP: test CVE tag format: No new CVE patches introduced (test_patch.TestPatch.test_cve_tag_format)
SKIP: test Signed-off-by presence: No new CVE patches introduced (test_patch.TestPatch.test_signed_off_by_presence)
SKIP: test Upstream-Status presence: No new CVE patches introduced (test_patch.TestPatch.test_upstream_status_presence_format)
SKIP: test lic files chksum modified not mentioned: No modified recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_modified_not_mentioned)
SKIP: test lic files chksum presence: No added recipes, skipping test (test_metadata.TestMetadata.test_lic_files_chksum_presence)
SKIP: test license presence: No added recipes, skipping test (test_metadata.TestMetadata.test_license_presence)
SKIP: test pylint: No python related patches, skipping test (test_python_pylint.PyLint.test_pylint)
SKIP: test series merge on head: Merge test is disabled for now (test_mbox.TestMbox.test_series_merge_on_head)
SKIP: test src uri left files: No modified recipes, skipping pretest (test_metadata.TestMetadata.test_src_uri_left_files)
SKIP: test summary presence: No added recipes, skipping test (test_metadata.TestMetadata.test_summary_presence)
---
Please address the issues identified and
submit a new revision of the patch, or alternatively, reply to this email with an explanation of why the patch should be accepted. If you believe these results are due to an error in patchtest, please submit a bug at https://bugzilla.yoctoproject.org/ (use the 'Patchtest' category under 'Yocto Project Subprojects'). For more information on specific failures, see: https://wiki.yoctoproject.org/wiki/Patchtest. Thank you!
Hi Christos,
This look like a solid v2 :)
Le 15/01/2025 à 20:39, Christos Gavros via lists.openembedded.org a écrit :
Quoted 3 lines
Users reported issues caused by missing the right libstdc++-version-dev. A new function '
check_c_toolchain' added in sanity.bbclass to test linking libstdc++ Fixes [YOCTO #<15712>]
Proper way to tag this bugzilla ticket is "Fixes [YOCTO #15712]"
See
https://docs.yoctoproject.org/dev/contributor-guide/submit-changes.html#implement-and-commit-changes
(or any of the previous commits including this tag.
Now, I notice that the patchtest message is a bit misleading.
With the tag fixed, you can add my reviewed-by tag:
Quoted 90 lines
Signed-off-by Christos Gavros <[email protected]>---
v1->v2
* use shortlog
* drop the meta-oe prefix
* fix format for bug reference
* change function description including libstdc++
* useBUILD_CCinstead of specific compiler
* lines in comments are removed
* patch message less than 200 char
* bb.fatal is removed
* follow pattern of other functions in class
* use docstring instead of # in functions description
* make the print out message more clear
* fix comment style where the function is called
* change "hello world" from C++ to C program
* use gcc instead of g++--- meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)meta/classes-global/sanity.bbclass +40
-1@@ -780,6 +780,43 @@ 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_c_toolchain(d): + """ + it checks if the c compiling and linking to libstdc++ works properly in the native system + """ + import os + import subprocess + from tempfile import NamedTemporaryFile + + try: + with NamedTemporaryFile(delete=False, suffix=".c") as c_file: + c_code = """ + #include <stdio.h> + int main() { + printf(\"Hello, World!\\n\"); + return 0; + } + """ + c_file.write(c_code.encode('utf-8')) + c_file_name = c_file.name + + build_cc = d.getVar('BUILD_CC').strip() + output_binary = c_file_name + ".out" + compile_command = [build_cc, c_file_name, '-o', output_binary,'-lstdc++'] + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.returncode == 0: + return None + else: + return f"C toolchain check failed to link against libstdc++. Please ensure libstdc++ and headers are installed. Error:\n{result.stderr.decode()}" + except Exception as e: + return f"An unexpected issue occurred during the C toolchain check: {str(e)}" + finally: + if c_file_name and os.path.exists(c_file_name): + os.remove(c_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@@ -976,6 +1013,9 @@ def check_sanity_everybuild(status, d): 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 if linking with lstdc++ is failing + status.addresult(check_c_toolchain(d)) + def check_sanity(sanity_data): class SanityStatus(object): def __init__(self): -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#209924): https://lists.openembedded.org/g/openembedded-core/message/209924
Mute This Topic: https://lists.openembedded.org/mt/110634330/4316185
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
Yoann Congal Smile ECS - Tech Expert
Oops forgot something
Le 15/01/2025 à 20:39, Christos Gavros via lists.openembedded.org a écrit :
Quoted 31 lines
Users reported issues caused by missing the right libstdc++-version-dev. A new function '
check_c_toolchain' added in sanity.bbclass to test linking libstdc++ Fixes [YOCTO #<15712>]Signed-off-by Christos Gavros <[email protected]>---
v1->v2
* use shortlog
* drop the meta-oe prefix
* fix format for bug reference
* change function description including libstdc++
* useBUILD_CCinstead of specific compiler
* lines in comments are removed
* patch message less than 200 char
* bb.fatal is removed
* follow pattern of other functions in class
* use docstring instead of # in functions description
* make the print out message more clear
* fix comment style where the function is called
* change "hello world" from C++ to C program
* use gcc instead of g++--- meta/classes-global/sanity.bbclass | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)meta/classes-global/sanity.bbclass +0
-0@@ -780,6 +780,43 @@ def sanity_check_locale(d): except locale.Error:
meta/classes-global/sanity.bbclass def sanity_check_locale(d): · line 790
Quoted 10 lines
meta/classes-global/sanity.bbclass +8
-0raise_sanity_error("Your system needs to support the en_US.UTF-8 locale.", d) +def check_c_toolchain(d): + """ + it checks if the c compiling and linking to libstdc++ works properly in the native system + """ + import os + import subprocess + from tempfile import NamedTemporaryFile +
^^^^
I forgot to tell you that you have whitespaces here
Quoted 33 lines
meta/classes-global/sanity.bbclass +29
-0+ try: + with NamedTemporaryFile(delete=False, suffix=".c") as c_file: + c_code = """ + #include <stdio.h> + int main() { + printf(\"Hello, World!\\n\"); + return 0; + } + """ + c_file.write(c_code.encode('utf-8')) + c_file_name = c_file.name + + build_cc = d.getVar('BUILD_CC').strip() + output_binary = c_file_name + ".out" + compile_command = [build_cc, c_file_name, '-o', output_binary,'-lstdc++'] + result = subprocess.run(compile_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + if result.returncode == 0: + return None + else: + return f"C toolchain check failed to link against libstdc++. Please ensure libstdc++ and headers are installed. Error:\n{result.stderr.decode()}" + except Exception as e: + return f"An unexpected issue occurred during the C toolchain check: {str(e)}" + finally: + if c_file_name and os.path.exists(c_file_name): + os.remove(c_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
meta/classes-global/sanity.bbclass def check_sanity_everybuild(status, d): · line 1016
Quoted 4 lines
meta/classes-global/sanity.bbclass +1
-0@@ -976,6 +1013,9 @@ def check_sanity_everybuild(status, d): 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 if linking with lstdc++ is failing
and here ----------------------------------------^
Quoted 16 lines
meta/classes-global/sanity.bbclass +2
-1+ status.addresult(check_c_toolchain(d)) + def check_sanity(sanity_data): class SanityStatus(object): def __init__(self): -=-=-=-=-=-=-=-=-=-=-=-Links: You receive all messages sent to this group.
View/Reply Online (#209924): https://lists.openembedded.org/g/openembedded-core/message/209924
Mute This Topic: https://lists.openembedded.org/mt/110634330/4316185
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Signature · 2 lines
Yoann Congal Smile ECS - Tech Expert