import os import sys import subprocess import shutil import re import getpass import glob def build(build_utils, job_n, product_name, root_dir, bin_dir): # 设置环境变量 os.environ['ARCH'] = 'arm' os.environ['CROSS_COMPILE'] = f'{root_dir}/buildtools/toolchains/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-' os.environ["DESTDIR"] = f'{bin_dir}/Lora/sx1302_hal' os.environ["OBJDIR"] = f'{bin_dir}/Lora/sx1302_hal' # 调用make命令,指定工作目录 # 注意:subprocess.run在Python 3.5及以上版本中可用 # 如果你使用的是旧版本的Python,可能需要使用subprocess.call或其他方法 os.makedirs(f'{bin_dir}/Lora/sx1302_hal/install', exist_ok=True) build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_DIR", f'{bin_dir}/Lora/sx1302_hal/install') build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_USR", getpass.getuser()) subprocess.check_call(['make', f'--directory={root_dir}/Lora/sx1302_hal', f'--jobs={job_n}']) def build_install(build_utils, job_n, product_name, root_dir, bin_dir): # install test_loragw_* build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/libloragw/test_loragw_*', f'{bin_dir}/Lora/sx1302_hal/install/') build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/tools/reset_lgw.sh', f'{bin_dir}/Lora/sx1302_hal/install/', True) # install packet_forwarder build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/lora_pkt_fwd', f'{bin_dir}/Lora/sx1302_hal/install/') build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_conf.json.sx1250.*', f'{bin_dir}/Lora/sx1302_hal/install/', True) build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_config.json.sx1255.*', f'{bin_dir}/Lora/sx1302_hal/install/', True) build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_config.json.sx1257.*', f'{bin_dir}/Lora/sx1302_hal/install/', True) build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_boot/boot', f'{bin_dir}/Lora/sx1302_hal/install/') build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_chip_id/chip_id', f'{bin_dir}/Lora/sx1302_hal/install/') build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_net_downlink/net_downlink', f'{bin_dir}/Lora/sx1302_hal/install/') build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_spectral_scan/spectral_scan', f'{bin_dir}/Lora/sx1302_hal/install/')