build.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import os
  2. import sys
  3. import subprocess
  4. import shutil
  5. import re
  6. import getpass
  7. import glob
  8. def has_build(module_name):
  9. build_module = ['openssl']
  10. if module_name in build_module:
  11. return True
  12. else:
  13. return False
  14. def build(module_name, build_utils, src_dir, bin_dir, install_dir, job_n):
  15. # 设置环境变量
  16. os.environ['ARCH'] = 'arm'
  17. root_dir = os.environ["PRODUCT_ROOT_DIR"]
  18. 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-'
  19. if module_name == 'openssl':
  20. build_utils.copy_files_ignoring_hidden(src_dir, bin_dir)
  21. build_utils.exec_command(['./config', 'no-asm', f'--prefix={install_dir}', f'--cross-compile-prefix={root_dir}/buildtools/toolchains/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-', f'--openssldir={install_dir}'], "config", bin_dir, exit=False)
  22. build_utils.exec_command(['sed', '-i', 's/-m64//g', f'{bin_dir}/Makefile'], "sed", bin_dir, exit=True)
  23. return build_utils.exec_command(['make', f'--directory={bin_dir}', f'--jobs={job_n}'], "make", bin_dir, exit=False)
  24. elif module_name == 'sx1302':
  25. os.environ['ARCH'] = 'arm'
  26. 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-'
  27. # os.environ["DESTDIR"] = f'{bin_dir}/Lora/sx1302_hal'
  28. os.environ["OBJDIR"] = f'{bin_dir}/Lora/sx1302_hal'
  29. # 调用make命令,指定工作目录
  30. # 注意:subprocess.run在Python 3.5及以上版本中可用
  31. # 如果你使用的是旧版本的Python,可能需要使用subprocess.call或其他方法
  32. os.makedirs(f'{bin_dir}/Lora/sx1302_hal/install', exist_ok=True)
  33. build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_DIR", f'{bin_dir}/Lora/sx1302_hal/install')
  34. build_utils.replace_value_in_file(f'{root_dir}/Lora/sx1302_hal/target.cfg', "TARGET_USR", getpass.getuser())
  35. return subprocess.check_call(['make', f'--directory={root_dir}/Lora/sx1302_hal', f'--jobs={job_n}'])
  36. # subprocess.check_call(['make', f'--directory={root_dir}/system/quectel-cm', f'--jobs={job_n}'])
  37. def build_install(module_name, build_utils, bin_dir, install_dir, job_n):
  38. if module_name == 'openssl':
  39. build_utils.exec_command(['make', 'install', f'--directory={bin_dir}', f'--jobs={job_n}'], "make", bin_dir, exit=False)
  40. elif module_name == 'sx1302':
  41. # install test_loragw_*
  42. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/libloragw/test_loragw_*', f'{install_dir}/Lora/sx1302_hal/')
  43. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/tools/reset_lgw.sh', f'{install_dir}/Lora/sx1302_hal/', True)
  44. # install packet_forwarder
  45. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/lora_pkt_fwd', f'{install_dir}/Lora/sx1302_hal/')
  46. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_conf.json.sx1250.*', f'{install_dir}/Lora/sx1302_hal/', True)
  47. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_config.json.sx1255.*', f'{install_dir}/Lora/sx1302_hal/', True)
  48. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/packet_forwarder/global_config.json.sx1257.*', f'{install_dir}/Lora/sx1302_hal/', True)
  49. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_boot/boot', f'{install_dir}/Lora/sx1302_hal/')
  50. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_chip_id/chip_id', f'{install_dir}/Lora/sx1302_hal/')
  51. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_net_downlink/net_downlink', f'{install_dir}/Lora/sx1302_hal/')
  52. build_utils.move_matching_files(f'{root_dir}/Lora/sx1302_hal/util_spectral_scan/spectral_scan', f'{install_dir}/Lora/sx1302_hal/')
  53. return True