1# coding=utf-8 2import shutil 3import os 4import sys 5import stat 6import datetime 7import subprocess 8from datetime import datetime 9 10def copy_apps_files(script_dir, yaml_dir): 11 12 pyFile = open(yaml_dir) 13 data = pyFile.read() 14 15 data_prebuild="" 16 prebuildSrc_apps="" 17 prebuildSrc_boot="" 18 if "ALI_AOS_HAAS_EDU_K1" in data: # haasedu 19 print("HaaS EDU platform") 20 data_prebuild = "hardware/chip/haas1000/prebuild/data/" 21 prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaSEdu", "python-apps") 22 prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaSEdu", "pyamp") 23 24 elif "ALI_AOS_HAAS200" in data: # haas200 25 print("HaaS 200 platform") 26 data_prebuild = "hardware/chip/rtl872xd/prebuild/data/" 27 prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaS200", "python-apps") 28 prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaS200", "pyamp") 29 else: # haas100 30 print("HaaS100 chip") 31 data_prebuild="hardware/chip/haas1000/prebuild/data/" 32 prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaS100", "python-apps") 33 prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaS100", "pyamp") 34 35 print('data_prebuild = %s' % data_prebuild) 36 37 # get root dest path 38 components_dest = os.path.dirname(script_dir) 39 root_dest = os.path.dirname(components_dest) 40 41 42 framework_dir = os.path.join(script_dir, "framework") 43 prebuild_dest1 = os.path.dirname(framework_dir) 44 prebuild_dest2 = os.path.dirname(prebuild_dest1) 45 prebuild_dest = os.path.dirname(prebuild_dest2) 46 47 # make /hardware/chip/haas1000/prebuild/data/lib/micropython/ path 48 data_prebuild = os.path.join(prebuild_dest, data_prebuild) 49 50 51 #cp python-boot 52 prebuildDst_boot = os.path.join(data_prebuild, 'pyamp') 53 print('prebuildSrc_boot = %s' % prebuildSrc_boot) 54 print('prebuildDst_boot = %s' % prebuildDst_boot) 55 56 if os.path.exists(prebuildDst_boot): 57 shutil.rmtree(prebuildDst_boot) 58 shutil.copytree(prebuildSrc_boot, prebuildDst_boot) 59 60 #cp python-apps 61 prebuildDst_apps = os.path.join(data_prebuild, 'python-apps') 62 print('prebuildSrc_apps = %s' % prebuildSrc_apps) 63 print('prebuildDst_apps = %s' % prebuildDst_apps) 64 65 if os.path.exists(prebuildDst_apps): 66 shutil.rmtree(prebuildDst_apps) 67 shutil.copytree(prebuildSrc_apps, prebuildDst_apps) 68 69 #cp framework to lib 70 python_lib_framework="lib/micropython" 71 prebuildSrc_framework = os.path.join(script_dir, "framework") 72 prebuildDst_framework = os.path.join(root_dest, data_prebuild, python_lib_framework) 73 print('prebuildSrc_framework = %s' % prebuildSrc_framework) 74 print('prebuildDst_framework = %s' % prebuildDst_framework) 75 76 if os.path.exists(prebuildDst_framework): 77 shutil.rmtree(prebuildDst_framework) 78 shutil.copytree(prebuildSrc_framework, prebuildDst_framework) 79 80 #cp uasyncio to lib 81 python_lib_ext_uasyncio="lib/micropython/uasyncio" 82 prebuildSrc_ext_uasyncio = os.path.join(script_dir, "engine", "extmod", "uasyncio") 83 prebuildDst_ext_uasyncio = os.path.join(data_prebuild, python_lib_ext_uasyncio) 84 print('prebuildSrc_ext_uasyncio = %s' % prebuildSrc_ext_uasyncio) 85 print('prebuildDst_ext_uasyncio = %s' % prebuildDst_ext_uasyncio) 86 87 if os.path.exists(prebuildDst_ext_uasyncio): 88 shutil.rmtree(prebuildDst_ext_uasyncio) 89 shutil.copytree(prebuildSrc_ext_uasyncio, prebuildDst_ext_uasyncio) 90 91 92 print(" ====== run external script success =======") 93 94""" 95Generate header file with macros defining MicroPython version info. 96This script works with Python 2.6, 2.7, 3.3 and 3.4. 97""" 98def make_version_header(filename): 99 100 git_tag = 'v1.17' 101 git_hash = '7c54b6428-dirty' 102 103 build_date = datetime.now() 104 if "SOURCE_DATE_EPOCH" in os.environ: 105 build_date = datetime.datetime.utcfromtimestamp( 106 int(os.environ["SOURCE_DATE_EPOCH"]) 107 ).date() 108 109 # Generate the file with the git and version info 110 file_data = """\ 111// This file was generated by py/makeversionhdr.py 112#define MICROPY_GIT_TAG "%s" 113#define MICROPY_GIT_HASH "%s" 114#define MICROPY_BUILD_DATE "%s" 115""" % ( 116 git_tag, 117 git_hash, 118 build_date.strftime("%Y-%m-%d, %H:%M:%S"), 119 ) 120 121 # Check if the file contents changed from last time 122 write_file = True 123 if os.path.isfile(filename): 124 with open(filename, "r") as f: 125 existing_data = f.read() 126 if existing_data == file_data: 127 write_file = False 128 129 # Only write the file if we need to 130 if write_file: 131 print("GEN %s" % filename) 132 with open(filename, "w") as f: 133 f.write(file_data) 134 135if __name__ == "__main__": 136 137 script_dir = os.path.dirname(sys.argv[0]) 138 mpversion_file = os.path.join(script_dir, 'adapter', 'haas', 'genhdr', "mpversion.h") 139 140 make_version_header(mpversion_file) 141 copy_apps_files(script_dir, sys.argv[1]) 142