build bsp. cd {rtt_root} scons -C bsp/{bsp} --pyconfig-silent > /dev/null cd {rtt_root}/bsp/{bsp} pkgs --update > /dev/null pkgs --list cd {rtt_root} scons -C bsp/{bsp} -j{nproc} {scons_args} cd {rtt_root}/bsp/{bsp} scons -c > /dev/null rm -rf package
(bsp, scons_args='',name='default', pre_build_commands=None, post_build_command=None,build_check_result = None,bsp_build_env=None)
| 51 | |
| 52 | |
| 53 | def build_bsp(bsp, scons_args='',name='default', pre_build_commands=None, post_build_command=None,build_check_result = None,bsp_build_env=None): |
| 54 | """ |
| 55 | build bsp. |
| 56 | |
| 57 | cd {rtt_root} |
| 58 | scons -C bsp/{bsp} --pyconfig-silent > /dev/null |
| 59 | |
| 60 | cd {rtt_root}/bsp/{bsp} |
| 61 | pkgs --update > /dev/null |
| 62 | pkgs --list |
| 63 | |
| 64 | cd {rtt_root} |
| 65 | scons -C bsp/{bsp} -j{nproc} {scons_args} |
| 66 | |
| 67 | cd {rtt_root}/bsp/{bsp} |
| 68 | scons -c > /dev/null |
| 69 | rm -rf packages |
| 70 | |
| 71 | """ |
| 72 | success = True |
| 73 | # 设置环境变量 |
| 74 | if bsp_build_env is not None: |
| 75 | print("Setting environment variables:") |
| 76 | for key, value in bsp_build_env.items(): |
| 77 | print(f"{key}={value}") |
| 78 | os.environ[key] = value # 设置环境变量 |
| 79 | os.chdir(rtt_root) |
| 80 | os.makedirs(f'{rtt_root}/output/bsp/{bsp}', exist_ok=True) |
| 81 | if os.path.exists(f"{rtt_root}/bsp/{bsp}/Kconfig"): |
| 82 | os.chdir(rtt_root) |
| 83 | run_cmd(f'scons -C bsp/{bsp} --pyconfig-silent', output_info=True) |
| 84 | |
| 85 | os.chdir(f'{rtt_root}/bsp/{bsp}') |
| 86 | run_cmd('pkgs --update-force', output_info=True) |
| 87 | run_cmd('pkgs --list') |
| 88 | |
| 89 | nproc = multiprocessing.cpu_count() |
| 90 | if pre_build_commands is not None: |
| 91 | print("Pre-build commands:") |
| 92 | print(pre_build_commands) |
| 93 | for command in pre_build_commands: |
| 94 | print(command) |
| 95 | output, returncode = run_cmd(command, output_info=True) |
| 96 | print(output) |
| 97 | if returncode != 0: |
| 98 | print(f"Pre-build command failed: {command}") |
| 99 | print(output) |
| 100 | os.chdir(rtt_root) |
| 101 | # scons 编译命令 |
| 102 | cmd = f'scons -C bsp/{bsp} -j{nproc} {scons_args}' # --debug=time for debug time |
| 103 | output, res = run_cmd(cmd, output_info=True) |
| 104 | if build_check_result is not None: |
| 105 | if res != 0 or not check_output(output, build_check_result): |
| 106 | print("Build failed or build check result not found") |
| 107 | print(output) |
| 108 | if res != 0: |
| 109 | success = False |
| 110 | else: |
no test coverage detected