build.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import os
  2. import sys
  3. import subprocess
  4. import shutil
  5. import re
  6. import getpass
  7. import glob
  8. def build(build_utils, job_n, product_name, root_dir, bin_dir):
  9. # 设置环境变量
  10. os.environ['ARCH'] = 'arm'
  11. 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-'
  12. os.environ["DESTDIR"] = f'{bin_dir}/Lora/sx1302_hal'
  13. os.environ["OBJDIR"] = f'{bin_dir}/Lora/sx1302_hal'
  14. # 调用make命令,指定工作目录
  15. # 注意:subprocess.run在Python 3.5及以上版本中可用
  16. # 如果你使用的是旧版本的Python,可能需要使用subprocess.call或其他方法
  17. os.makedirs(f'{bin_dir}/Lora/sx1302_hal/install', exist_ok=True)
  18. build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_DIR", f'{bin_dir}/Lora/sx1302_hal/install')
  19. build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_USR", getpass.getuser())
  20. subprocess.check_call(['make', f'--directory={root_dir}/Lora/sx1302_hal', f'--jobs={job_n}'])
  21. def build_install(build_utils, job_n, product_name, root_dir, bin_dir):
  22. # install test_loragw_*
  23. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/libloragw/test_loragw_*', f'{bin_dir}/Lora/sx1302_hal/install/')
  24. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/tools/reset_lgw.sh', f'{bin_dir}/Lora/sx1302_hal/install/', True)
  25. # install packet_forwarder
  26. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/lora_pkt_fwd', f'{bin_dir}/Lora/sx1302_hal/install/')
  27. 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)
  28. 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)
  29. 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)
  30. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_boot/boot', f'{bin_dir}/Lora/sx1302_hal/install/')
  31. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_chip_id/chip_id', f'{bin_dir}/Lora/sx1302_hal/install/')
  32. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_net_downlink/net_downlink', f'{bin_dir}/Lora/sx1302_hal/install/')
  33. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_spectral_scan/spectral_scan', f'{bin_dir}/Lora/sx1302_hal/install/')