yu.dong | c33b307 | 2024-08-21 23:14:49 -0700 | [diff] [blame^] | 1 | #!/usr/bin/python
|
| 2 |
|
| 3 | import sys
|
| 4 | import json
|
| 5 | import os
|
| 6 | import shutil
|
| 7 | import glob
|
| 8 | import re
|
| 9 | from collections import OrderedDict
|
| 10 |
|
| 11 | def check_file_exist (file):
|
| 12 | if not os.path.exists(file):
|
| 13 | printstr = "Error: " + file + " does not exist, please check!\n"
|
| 14 | print(printstr)
|
| 15 | exit (1)
|
| 16 |
|
| 17 | debug = sys.argv[1] # True/False
|
| 18 | project = sys.argv[2] # project name
|
| 19 | flavor = sys.argv[3] # flavor name
|
| 20 | dsp_project = sys.argv[4] # dsp project name
|
| 21 | dsp_flavor = sys.argv[5] # dsp flavor name
|
| 22 | modis_uesim = sys.argv[6] # check modis or uesim
|
| 23 | inputTarget = sys.argv[7] # currect Target Name
|
| 24 | outputTarget = sys.argv[8] # output Target Name
|
| 25 | chk_append_opt = sys.argv[9].split(',') # special option
|
| 26 | targetName = os.path.basename(inputTarget)
|
| 27 |
|
| 28 |
|
| 29 | input_json = "tools/genTargetFile/all_dep.json"
|
| 30 | build_fdr = "build/" + project + "/" + flavor
|
| 31 | if modis_uesim == 'target':
|
| 32 | outputFdr = build_fdr + "/bin/json"
|
| 33 | else:
|
| 34 | outputFdr = build_fdr + "/" + modis_uesim + "/_BUILD_XGEN/bin/json"
|
| 35 |
|
| 36 | encode_enable = True
|
| 37 | if sys.version_info[0] >= 3:
|
| 38 | encode_enable = False
|
| 39 |
|
| 40 | if debug:
|
| 41 | print ("\n**********************************************************")
|
| 42 | print("Project Name = %s" % project)
|
| 43 | print("Flavor Name = %s" % flavor)
|
| 44 | print("DSP Project Name = %s" % dsp_project)
|
| 45 | print("DSP Flavor Name = %s" % dsp_flavor)
|
| 46 | print("Input Target = %s" % inputTarget)
|
| 47 | print("Output Target = %s" % outputTarget)
|
| 48 | print("Target NAme = %s" % targetName)
|
| 49 | print ("")
|
| 50 |
|
| 51 | input_target_jason = "tools/genTargetFile/json/" + targetName + ".json"
|
| 52 | TargetFileList = []
|
| 53 | PrerequisiteList = []
|
| 54 |
|
| 55 | if targetName != "genJson.det":
|
| 56 | check_file_exist(input_target_jason)
|
| 57 | str = outputTarget + ': ' + input_target_jason
|
| 58 | TargetFileList = [str]
|
| 59 | PrerequisiteList = [input_target_jason]
|
| 60 | if debug:
|
| 61 | InputFileList = [input_target_jason]
|
| 62 | OutputFileList = []
|
| 63 | with open(input_target_jason , 'r') as reader:
|
| 64 | JsonData = json.loads(reader.read(), object_pairs_hook=OrderedDict)
|
| 65 |
|
| 66 | for option in chk_append_opt:
|
| 67 | for Script_List in JsonData[option]:
|
| 68 | if Script_List != "NONE":
|
| 69 | check_file_exist(Script_List)
|
| 70 | str = outputTarget + ': ' + Script_List
|
| 71 | TargetFileList.append(str)
|
| 72 | PrerequisiteList.append(Script_List)
|
| 73 | JsonInputList = JsonData[option][Script_List]['InputFile']['common']
|
| 74 | if modis_uesim == 'target':
|
| 75 | JsonInputList += JsonData[option][Script_List]['InputFile']['target']
|
| 76 | else:
|
| 77 | JsonInputList += JsonData[option][Script_List]['InputFile']['modis_uesim']
|
| 78 | for File_List in JsonInputList:
|
| 79 | File_List = File_List.replace('$proj',project).replace('$flavor',flavor).replace('$dsp_proj',dsp_project).replace('$dsp_flavor',dsp_flavor).replace('$modis_uesim',modis_uesim)
|
| 80 | Glob_File_List = glob.glob(File_List)
|
| 81 | if Glob_File_List:
|
| 82 | for file in Glob_File_List:
|
| 83 | FinalInput = file
|
| 84 | str = outputTarget + ': ' + FinalInput
|
| 85 | TargetFileList.append(str)
|
| 86 | PrerequisiteList.append(FinalInput)
|
| 87 | if debug:
|
| 88 | InputFileList.append(FinalInput)
|
| 89 | else:
|
| 90 | check_file_exist(File_List)
|
| 91 |
|
| 92 | if debug:
|
| 93 | if modis_uesim == 'target':
|
| 94 | JsonOutputList = JsonData[option][Script_List]['OutputFile']['target']
|
| 95 | else:
|
| 96 | JsonOutputList = JsonData[option][Script_List]['OutputFile']['modis_uesim']
|
| 97 | for File_List in JsonOutputList:
|
| 98 | File_List = File_List.replace('$proj',project).replace('$flavor',flavor).replace('$dsp_proj',dsp_project).replace('$dsp_flavor',dsp_flavor).replace('$modis_uesim',modis_uesim)
|
| 99 | for file in glob.glob(File_List):
|
| 100 | FinalOutput = file
|
| 101 | OutputFileList.append(FinalOutput)
|
| 102 |
|
| 103 | with open(outputTarget , 'a+') as writer:
|
| 104 | writer.write('\n')
|
| 105 | for item in TargetFileList:
|
| 106 | if debug:
|
| 107 | print(item)
|
| 108 | writer.write(item + '\n')
|
| 109 | writer.write('\n')
|
| 110 | for item in PrerequisiteList:
|
| 111 | if debug:
|
| 112 | print(item)
|
| 113 | writer.write(item + ':\n')
|
| 114 |
|
| 115 | if debug:
|
| 116 | print("\nInputFile:")
|
| 117 | for item in InputFileList:
|
| 118 | print(item)
|
| 119 |
|
| 120 | print("\nOutputFile:")
|
| 121 | for item in OutputFileList:
|
| 122 | print(item)
|
| 123 | print ("**********************************************************\n")
|