1#!/usr/bin/env python3 2 3from distutils.command.build import build 4import os 5import fnmatch 6from pickletools import string1 7import shutil 8import datetime 9 10compiler_list = [ 11 'ndk-test', 12 'sanitize', 13 'arm-neon', 14] 15 16# Check the output directory 17def check_target_dir(): 18 target_dir = os.path.join(os.getcwd(),os.path.pardir,'target') 19 # print(target_dir) 20 if os.path.exists(target_dir) and os.path.isdir(target_dir): 21 # print('target directory exist') 22 for filename in os.listdir(target_dir): 23 if os.path.isdir(os.path.join(target_dir,filename)): 24 shutil.rmtree(os.path.join(target_dir,filename)) 25 else: 26 os.mkdir(target_dir) 27 28# Traverse the directory, find the test case that needs to be compiled and compile it 29def build_compiler(): 30 check_target_dir() 31 build_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 32 print('build_start:' + build_start) 33 comliler_dir = os.path.join(os.getcwd(),os.path.pardir) 34 # print(comliler_dir) 35 for name in compiler_list: 36 file_path = os.path.join(comliler_dir,name) 37 # print(file_path) 38 if os.path.isdir(file_path): 39 for f_name in os.listdir(file_path): 40 if fnmatch.fnmatch(f_name, 'build.py'): 41 os.chdir(file_path) 42 string_build = 'python {}'.format('build.py') 43 os.system(string_build) 44 return_dir = os.path.join(os.getcwd(),os.path.pardir,'script') 45 os.chdir(return_dir) 46 build_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 47 print('build_end:' + build_end) 48 copy_target() 49 del_Intermediate_file() 50 return 0 51 52# Copy the compiled target product to the target directory 53def copy_target(): 54 copy_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 55 print('copy_target_start:' + copy_start) 56 57 find_dir = os.path.join(os.getcwd(),os.path.pardir) 58 check_target_dir() 59 for name in compiler_list: 60 file_path = os.path.join(find_dir,name) 61 for curdir, dirs, files in os.walk(file_path): 62 for dirname in dirs: 63 if dirname == 'output': 64 if name == 'sanitize': 65 src = os.path.join(file_path,dirname) 66 copy_tar_out = os.path.join(find_dir,'target',name) 67 shutil.copytree(src,copy_tar_out) 68 shutil.rmtree(src) 69 else: 70 copy_tar_out = os.path.join(find_dir,'target',name,os.path.basename(curdir)) 71 # print(copy_tar_out) 72 if not os.path.isdir(copy_tar_out): 73 os.makedirs(copy_tar_out) 74 tar_out = os.path.join(curdir,dirname) 75 # print(tar_out) 76 # print(tar_out + '----->' + copy_tar_out) 77 for filename in os.listdir(tar_out): 78 src = os.path.join(tar_out, filename) 79 dst = os.path.join(copy_tar_out, filename) 80 # print(src + '----->' + dst) 81 shutil.copy(src, dst) 82 83 copy_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 84 print('copy_target_end:' + copy_end) 85 86 return 0 87 88# Remove intermediate files from source files 89def del_Intermediate_file(): 90 del_start = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 91 print('copy_target_start:' + del_start) 92 find_dir = os.path.join(os.getcwd(),os.path.pardir) 93 for name in compiler_list: 94 file_path = os.path.join(find_dir,name) 95 del_file_path = os.path.join(file_path) 96 for curdir, dirs, files in os.walk(del_file_path): 97 for dirname in dirs: 98 if dirname == 'build': 99 # print(os.path.join(curdir,dirname)) 100 shutil.rmtree(os.path.join(curdir,dirname)) 101 del_end = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') 102 print('copy_target_end:' + del_end) 103 104if __name__ == '__main__': 105 # check_target_dir() 106 build_compiler() 107 # copy_target() 108 # del_Intermediate_file() 109