Arrow / Mbed OS DAPLink Reset
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers copy_release_files.py Source File

copy_release_files.py

00001 #
00002 # DAPLink Interface Firmware
00003 # Copyright (c) 2009-2016, ARM Limited, All Rights Reserved
00004 # SPDX-License-Identifier: Apache-2.0
00005 #
00006 # Licensed under the Apache License, Version 2.0 (the "License"); you may
00007 # not use this file except in compliance with the License.
00008 # You may obtain a copy of the License at
00009 #
00010 # http://www.apache.org/licenses/LICENSE-2.0
00011 #
00012 # Unless required by applicable law or agreed to in writing, software
00013 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00014 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015 # See the License for the specific language governing permissions and
00016 # limitations under the License.
00017 #
00018 
00019 """
00020 Copy release files from the uvision build directories into a release package
00021 
00022 This script is intended to be called the script creating a daplink build.
00023 """
00024 from __future__ import absolute_import
00025 from __future__ import print_function
00026 
00027 import os
00028 import shutil
00029 import glob
00030 import argparse
00031 
00032 from subprocess import check_output, CalledProcessError
00033 
00034 COPY_PATTERN_LIST = [
00035     "%s_crc*.bin",
00036     "%s_crc*.hex",
00037     "%s_crc*.txt",
00038     ]
00039 OPTIONAL_COPY_PATTERN_LIST = [
00040     "%s.axf",
00041     "%s.elf",
00042     "%s_crc*.c",
00043     "%s.build_log.htm",
00044     "%s.map",
00045     "%s.htm",
00046     "%s_map.html",
00047 ]
00048 
00049 TOOL_DIR = { 
00050     'uvision' : { 'proj_dir': os.path.join('projectfiles', 'uvision') , 'rel_dir' : 'uvision_release', 'build_dir' : 'build' },
00051     'mbedcli' : { 'proj_dir': 'BUILD' , 'rel_dir' : 'mbedcli_release', 'build_dir' : 'ARM-CUSTOM_PROFILE' }        
00052 }
00053 
00054 def generate_info_files(dir):
00055 
00056     output_info_file = os.path.join(os.path.normpath(dir),'git_info.txt')
00057     output_requirements_file = os.path.join(os.path.normpath(dir),'build_requirements.txt')
00058 
00059     # Get the git SHA.
00060     try:
00061         git_sha = check_output("git rev-parse --verify HEAD", shell=True)
00062         git_sha = git_sha.decode().strip()
00063     except:
00064         print("ERROR - failed to get git SHA, do you have git.exe in your PATH environment variable?")
00065         return 1
00066 
00067     # Check are there any local, uncommitted modifications.
00068     try:
00069         check_output("git diff --no-ext-diff --quiet --exit-code", shell=True)
00070     except (CalledProcessError, OSError):
00071         git_has_changes = '1'
00072     else:
00073         git_has_changes = '0'
00074 
00075     # Get the requirements version.
00076     try:
00077         pip_freeze = check_output("pip list", shell=True).decode().strip()
00078     except:
00079         print("ERROR - failed requirements, pip not installed?")
00080         return 1
00081 
00082 
00083     # Create the version files
00084     try:
00085         with open(output_info_file, 'w+') as file:
00086             file.write(git_sha + '\n' + 'Uncommitted Changes:' + git_has_changes + '\n' )
00087         with open(output_requirements_file, 'w+') as file:
00088             file.write(pip_freeze)
00089     except IOError:
00090         print("Error - failed to write information and version files")
00091         return 1;
00092     return 0
00093 
00094 
00095 def main():
00096     """Copy imporant files for the current release"""
00097     parser = argparse.ArgumentParser(description='Copy imporant files for the current release')
00098     parser.add_argument('--project-tool', type=str, default='uvision', choices=['uvision', 'mbedcli'], help='Choose from uvision and mbedcli')
00099     args = parser.parse_args()
00100 
00101     self_path = os.path.abspath(__file__)
00102     tools_dir = os.path.dirname(self_path)
00103     daplink_dir = os.path.dirname(tools_dir)
00104 
00105     if os.path.basename(tools_dir) != "tools":
00106         print("Error - this script must be run from the tools directory")
00107         exit(-1)
00108 
00109     proj_dir = os.path.join(daplink_dir, TOOL_DIR[args.project_tool]['proj_dir'])
00110     rel_dir = os.path.join(daplink_dir, TOOL_DIR[args.project_tool]['rel_dir'])
00111     build_dir = TOOL_DIR[args.project_tool]['build_dir']
00112     # Make sure uvision dir is present
00113     if not os.path.isdir(proj_dir):
00114         print("Error - uvision directory '%s' missing" % proj_dir)
00115         exit(-1)
00116 
00117     # Clean release dir is present
00118     if os.path.isdir(rel_dir):
00119         shutil.rmtree(rel_dir)
00120 
00121     os.mkdir(rel_dir)
00122 
00123     generate_info_files(rel_dir)
00124     
00125     project_list = os.listdir(proj_dir)
00126     for project in project_list:
00127         src_dir = os.path.join(proj_dir, project, build_dir)
00128         dest_dir = os.path.join(rel_dir, project.lower())
00129 
00130         #only copy a built project
00131         if not os.path.exists(src_dir):
00132             continue
00133 
00134         # File must not have been copied already
00135         if os.path.exists(dest_dir):
00136             print("Error - package dir '%s' alread exists" % dest_dir)
00137             exit(-1)
00138         os.mkdir(dest_dir)
00139 
00140         for file_pattern in COPY_PATTERN_LIST:
00141             file_name = file_pattern % project.lower()
00142             file_source = os.path.join(src_dir, file_name)
00143             for file_wild in glob.glob(file_source):
00144                 shutil.copy(file_wild, dest_dir)
00145         for file_pattern in OPTIONAL_COPY_PATTERN_LIST:
00146             file_name = file_pattern % project.lower()
00147             file_source = os.path.join(src_dir, file_name)
00148             for file_wild in glob.glob(file_source):
00149                 shutil.copy(file_wild, dest_dir)
00150 
00151 main()