# coding=utf-8 import shutil import os import sys import stat import datetime import subprocess from datetime import datetime def copy_apps_files(script_dir, yaml_dir): pyFile = open(yaml_dir) data = pyFile.read() data_prebuild="" prebuildSrc_apps="" prebuildSrc_boot="" if "ALI_AOS_HAAS_EDU_K1" in data: # haasedu print("HaaS EDU platform") data_prebuild = "hardware/chip/haas1000/prebuild/data/" prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaSEdu", "python-apps") prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaSEdu", "pyamp") elif "ALI_AOS_HAAS200" in data: # haas200 print("HaaS 200 platform") data_prebuild = "hardware/chip/rtl872xd/prebuild/data/" prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaS200", "python-apps") prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaS200", "pyamp") else: # haas100 print("HaaS100 chip") data_prebuild="hardware/chip/haas1000/prebuild/data/" prebuildSrc_apps = os.path.join(script_dir, "tests/haas", "HaaS100", "python-apps") prebuildSrc_boot = os.path.join(script_dir, "tests/haas", "HaaS100", "pyamp") print('data_prebuild = %s' % data_prebuild) # get root dest path components_dest = os.path.dirname(script_dir) root_dest = os.path.dirname(components_dest) framework_dir = os.path.join(script_dir, "framework") prebuild_dest1 = os.path.dirname(framework_dir) prebuild_dest2 = os.path.dirname(prebuild_dest1) prebuild_dest = os.path.dirname(prebuild_dest2) # make /hardware/chip/haas1000/prebuild/data/lib/micropython/ path data_prebuild = os.path.join(prebuild_dest, data_prebuild) #cp python-boot prebuildDst_boot = os.path.join(data_prebuild, 'pyamp') print('prebuildSrc_boot = %s' % prebuildSrc_boot) print('prebuildDst_boot = %s' % prebuildDst_boot) if os.path.exists(prebuildDst_boot): shutil.rmtree(prebuildDst_boot) shutil.copytree(prebuildSrc_boot, prebuildDst_boot) #cp python-apps prebuildDst_apps = os.path.join(data_prebuild, 'python-apps') print('prebuildSrc_apps = %s' % prebuildSrc_apps) print('prebuildDst_apps = %s' % prebuildDst_apps) if os.path.exists(prebuildDst_apps): shutil.rmtree(prebuildDst_apps) shutil.copytree(prebuildSrc_apps, prebuildDst_apps) #cp framework to lib python_lib_framework="lib/micropython" prebuildSrc_framework = os.path.join(script_dir, "framework") prebuildDst_framework = os.path.join(root_dest, data_prebuild, python_lib_framework) print('prebuildSrc_framework = %s' % prebuildSrc_framework) print('prebuildDst_framework = %s' % prebuildDst_framework) if os.path.exists(prebuildDst_framework): shutil.rmtree(prebuildDst_framework) shutil.copytree(prebuildSrc_framework, prebuildDst_framework) #cp uasyncio to lib python_lib_ext_uasyncio="lib/micropython/uasyncio" prebuildSrc_ext_uasyncio = os.path.join(script_dir, "engine", "extmod", "uasyncio") prebuildDst_ext_uasyncio = os.path.join(data_prebuild, python_lib_ext_uasyncio) print('prebuildSrc_ext_uasyncio = %s' % prebuildSrc_ext_uasyncio) print('prebuildDst_ext_uasyncio = %s' % prebuildDst_ext_uasyncio) if os.path.exists(prebuildDst_ext_uasyncio): shutil.rmtree(prebuildDst_ext_uasyncio) shutil.copytree(prebuildSrc_ext_uasyncio, prebuildDst_ext_uasyncio) print(" ====== run external script success =======") """ Generate header file with macros defining MicroPython version info. This script works with Python 2.6, 2.7, 3.3 and 3.4. """ def make_version_header(filename): git_tag = 'v1.17' git_hash = '7c54b6428-dirty' build_date = datetime.now() if "SOURCE_DATE_EPOCH" in os.environ: build_date = datetime.datetime.utcfromtimestamp( int(os.environ["SOURCE_DATE_EPOCH"]) ).date() # Generate the file with the git and version info file_data = """\ // This file was generated by py/makeversionhdr.py #define MICROPY_GIT_TAG "%s" #define MICROPY_GIT_HASH "%s" #define MICROPY_BUILD_DATE "%s" """ % ( git_tag, git_hash, build_date.strftime("%Y-%m-%d, %H:%M:%S"), ) # Check if the file contents changed from last time write_file = True if os.path.isfile(filename): with open(filename, "r") as f: existing_data = f.read() if existing_data == file_data: write_file = False # Only write the file if we need to if write_file: print("GEN %s" % filename) with open(filename, "w") as f: f.write(file_data) if __name__ == "__main__": script_dir = os.path.dirname(sys.argv[0]) mpversion_file = os.path.join(script_dir, 'adapter', 'haas', 'genhdr', "mpversion.h") make_version_header(mpversion_file) copy_apps_files(script_dir, sys.argv[1])