build.py 2.7 KB

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