def create_gen_build_flavor_cmm (): common_dir = os.path.dirname(os.path.dirname(__file__)) destn_dir = join_paths(os.path.dirname(__file__), "app") if not os.path.exists(destn_dir): os.makedirs(destn_dir) lg.log("update_common_info.py: Calling gen_cmm_data3 to create " + join_paths(destn_dir, "gen_buildflavor.cmm")) lg.log_exec( ["python", "app/gen_cmm_data3.py", os.path.dirname(common_dir), join_paths(destn_dir, "gen_buildflavor.cmm")] )
def create_gen_build_flavor_cmm (): common_dir = os.path.dirname(os.path.dirname(__file__)) destn_dir = join_paths(os.path.dirname(__file__), "app") if not os.path.exists(destn_dir): os.makedirs(destn_dir) lg.log("update_common_info.py: Calling gen_cmm_data3 to create " + join_paths(destn_dir, "gen_buildflavor.cmm")) lg.log_exec( ["python", "app/gen_cmm_data3.py", os.path.dirname(common_dir), join_paths(destn_dir, "gen_buildflavor.cmm")] )
def use_fatgen_toget_partitionsize (): lg.log("fatgen_tool path:" + fatgen_tool) if os.path.exists( fatgen_tool ): lg.log('fatgen tool exists, using it to create new NON-HLOS.bin') #get modem partition size from partition.xml try: modem_partition_size = getModemPartitionSize('../config/partition.xml') str_modem_partition_size = str( modem_partition_size ) #print str_modem_partition_size except ModemPartitionSizeNotFoundException , ex: sys.exit('ModemPartitionSizeNotFoundException raised')
def use_fatgen_toget_partitionsize (): lg.log("fatgen_tool path:" + fatgen_tool) if os.path.exists( fatgen_tool ): lg.log('fatgen tool exists, using it to create new NON-HLOS.bin') #get modem partition size from partition.xml try: modem_partition_size = ml.getPartitionSize('../config/partition.xml','modem') str_modem_partition_size = str( modem_partition_size ) #print str_modem_partition_size except ml.PartitionSizeNotFoundException , ex: sys.exit(ex.partition_name + ' PartitionSizeNotFoundException raised')
def use_cpfatfs(): for flavor in bin_file_dests: fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin') #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created #if NON-HLOS.bin already exists, fatgen.py doesn't create it #deleting this file so that it is created each time if os.path.exists( fat_file_dest ): os.remove( fat_file_dest ) lg.log("Existing " + fat_file_dest + " has been deleted.") if (fatgen_build): # Create NON-HLOS.bin of container size as specified in partition.xml modem_partition_size = use_fatgen_toget_partitionsize () ret_code_fatgen_tool = lg.log_exec(['python',fatgen_tool,'-f','-s',modem_partition_size,'-n',fat_file_dest],verbose=0) if ret_code_fatgen_tool != 0: err_msg = 'update_common_info.py:'+'python'+' '+fatgen_tool+' '+'-f'+' '+'-s'+' '+modem_partition_size+' '+'-n'+' '+fat_file_dest +':Faled' lg.log(err_msg) raise Exception(err_msg) else: # Copy fat.bin to our root directory. Assume fat.bin is in same directory as cpfatfs.exe shutil.copy(cpfatfs_path + fat_file_src, fat_file_dest) os.chmod(fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH) fat_dest_dir = 'image' for fat_file in mi.get_files(attr = 'fat_file', flavor = flavor): lg.log('update_common_info.py:' + 'cpfatfs' + ' ' + fat_file + ' ' + fat_file_dest,verbose=0) ret_code_cpfatfs_tool = lg.log_exec([cpfatfs_tool, fat_file_dest, fat_dest_dir, fat_file],verbose=0) if ret_code_cpfatfs_tool != 0: err_msg = 'update_common_info.py:' + cpfatfs_tool +' '+ fat_file_dest +' '+ fat_dest_dir+' '+fat_file+':Failed' lg.log(err_msg) raise Exception(err_msg)
def use_cpfatfs(): for flavor in bin_file_dests: fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin') #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created #if NON-HLOS.bin already exists, fatgen.py doesn't create it #deleting this file so that it is created each time if os.path.exists( fat_file_dest ): os.remove( fat_file_dest ) lg.log("Existing " + fat_file_dest + " has been deleted.") if (fatgen_build): # Create NON-HLOS.bin of container size as specified in partition.xml modem_partition_size = use_fatgen_toget_partitionsize () ret_code_fatgen_tool = lg.log_exec(['python',fatgen_tool,'-f','-s',modem_partition_size,'-n',fat_file_dest],verbose=0) if ret_code_fatgen_tool != 0: err_msg = 'update_common_info.py:'+'python'+' '+fatgen_tool+' '+'-f'+' '+'-s'+' '+modem_partition_size+' '+'-n'+' '+fat_file_dest +':Faled' lg.log(err_msg) raise Exception(err_msg) else: # Copy fat.bin to our root directory. Assume fat.bin is in same directory as cpfatfs.exe shutil.copy(cpfatfs_path + fat_file_src, fat_file_dest) os.chmod(fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH) fat_dest_dir = 'image' for fat_file in mi.get_files(attr = 'fat_file', flavor = flavor): lg.log('update_common_info.py:' + 'cpfatfs' + ' ' + fat_file + ' ' + fat_file_dest,verbose=0) ret_code_cpfatfs_tool = lg.log_exec([cpfatfs_tool, fat_file_dest, fat_dest_dir, fat_file],verbose=0) if ret_code_cpfatfs_tool != 0: err_msg = 'update_common_info.py:' + cpfatfs_tool +' '+ fat_file_dest +' '+ fat_dest_dir+' '+fat_file+':Failed' lg.log(err_msg) raise Exception(err_msg)
def workflow_setenv(step_dict): # Preprocess the standard items in the step preprocess_step(step_dict, flavor) var = step_dict["var"] new_value = ml.evaluate_params(step_dict, step_dict["value"]) cur_value = "%"+var+"%" if cur_value in new_value: if var in os.environ: # try fetching current value only when present new_value = new_value.replace(cur_value, os.environ[var], 1) # only one else: # just keep the new value pass lg.log("Setting OS environment variable") lg.log(var + " = " + new_value) os.environ[var] = new_value
def gen_product_json( flavor): bid_file = os.path.join(os.path.dirname(__file__), 'Product_Info.json') lg.log("Creating the file Product_Info.json to hold the buildID information at " + bid_file) Product_Info = {} Image_Info = {} BuildID = mi.get_build_id('common', 'builds_flat') Product_Info['Version'] = '1.0' Product_Info['Product_Build_ID'] = BuildID Product_Info['Product_Flavor'] = flavor build_ids = mi.get_build_list() build_ids = build_ids for tag in build_ids: Image_Info[tag] = mi.get_build_id(tag) #Image_Info = OrderedDict(sorted(Image_Info.items(), key=lambda t: t[0])) Product_Info['Image_Build_IDs'] = Image_Info with open(bid_file, 'w') as outfile: json.dump(Product_Info, outfile, sort_keys=True,indent = 4)
def gen_product_json( flavor): bid_file = os.path.join(os.path.dirname(__file__), 'Product_Info.json') lg.log("Creating the file Product_Info.json to hold the buildID information at " + bid_file) Product_Info = {} Image_Info = {} BuildID = mi.get_build_id('common', 'builds_flat') Product_Info['Version'] = '1.0' Product_Info['Product_Build_ID'] = BuildID Product_Info['Product_Flavor'] = flavor build_ids = mi.get_build_list() build_ids = build_ids for tag in build_ids: Image_Info[tag] = mi.get_build_id(tag) #Image_Info = OrderedDict(sorted(Image_Info.items(), key=lambda t: t[0])) Product_Info['Image_Build_IDs'] = Image_Info with open(bid_file, 'w') as outfile: json.dump(Product_Info, outfile, sort_keys=True,indent = 4)
def workflow_delete(step_dict): for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) # Once destination path is processed, try deleting it for key in step_dict_flavor: # Delete step should contain only keys of destinations to delete destn = ml.clean_wvars(step_dict_flavor[key]) try: if os.path.isdir(destn): shutil.rmtree(destn) lg.log("update_common_info.py: Deleted the directory " + destn); else: os.remove(destn) lg.log("update_common_info.py: Deleted the file " + destn); except: lg.log("update_common_info.py: Unable to delete " + destn); # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def workflow_delete(step_dict): for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) # Once destination path is processed, try deleting it for key in step_dict_flavor: # Delete step should contain only keys of destinations to delete destn = clean_vars(step_dict_flavor[key]) try: if os.path.isdir(destn): shutil.rmtree(destn) lg.log("update_common_info.py: Deleted the directory " + destn); else: os.remove(destn) lg.log("update_common_info.py: Deleted the file " + destn); except: lg.log("update_common_info.py: Unable to delete " + destn); # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
import re from glob import glob print "build_main.py: Executing from", os.getcwd() import lib.meta_log as lg import lib.meta_lib as ml import lib.update_meta as um import lib.validate_contents_template as vct from xml.etree import ElementTree as et #---------------------------------------------------------# # Find our parameters # #---------------------------------------------------------# lg=lg.Logger('build_main') lg.log("build_main.py:Finding Parameters") param_file_fn = 'latest_args.txt' params = sys.argv[1:] #Flag to check if script needs to be exited after contents template validation exit_after_vct = False if len(params) > 0: # For script help: consider if '-help' is 1st argument if params[0].startswith('-help'): print __doc__ sys.exit() # Atleast 1 new argument is provided # Ignore latest_args.txt and overwrite param_file = open(param_file_fn, 'w') for p in params:
def workflow_exec(step_dict): # Execution step should specify the tool name to run if not ('tool_name' in step_dict or 'params' in step_dict): lg.log("update_common_info.py: Invalid exec step! Tool name or command not specified") else: for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) # After preprocess check if the tool is available and execute if step_dict_flavor['tool_name']: lg.log("build.py: --------------------------------------------------") lg.log("build.py: Calling " + step_dict_flavor['tool_name'].split('/')[-1] + " " + (flavor or "")) # Check if the step has file_vars or files and loop accordingly if ('src_file_vars' in step_dict_flavor.keys()) and (len(step_dict_flavor['src_file_vars']) > 0): src_file_vars = step_dict_flavor['src_file_vars'] for key in src_file_vars.keys(): step_dict_flavor['src_file_var'] = key for file in src_file_vars[key]: step_dict_flavor['src_file'] = file params = ml.evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py","match_si_var.py","fat_creation.py","ext_tool_wrapper.py") ))): err_msg = "build.py: "+params+":Failed" lg.log(err_msg) raise Exception(err_msg) elif ('src_files' in step_dict_flavor.keys()) and (len(step_dict_flavor['src_files']) > 0): src_files = step_dict_flavor['src_files'] for src_file in src_files: step_dict_flavor['src_file'] = src_file params = ml.evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py","match_si_var.py","fat_creation.py","ext_tool_wrapper.py") ))): err_msg = "build.py: "+params+":Failed" lg.log("err_msg") raise Exception(err_msg) else: params = ml.evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py","match_si_var.py","fat_creation.py","ext_tool_wrapper.py") ))): err_msg = "build.py: "+params+":Failed" lg.log(err_msg) raise Exception(err_msg) if ('start_dir' in step_dict_flavor.keys()): # cd'd to exec_dir in preprocessing, so revert back os.chdir(step_dict_flavor['start_dir']) del step_dict_flavor['start_dir'] # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def workflow_copy(step_dict): # Execution step should specify the tool name to run if not ('destn_dir' in step_dict or 'src_files' in step_dict): lg.log("update_common_info.py: Invalid copy step! Source Files or Destination not specified") else: for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) lg.log("build.py: --------------------------------------------------") lg.log("build.py: Starting copy") if ('src_files' in step_dict_flavor.keys()): src_files = step_dict_flavor['src_files'] destn_dir = step_dict_flavor['destn_dir'] # Copy each file in the list for src_file in src_files: # Directory vs File if ('@' in src_file): src_file = ml.evaluate_params(step_dict_flavor,src_file) if (os.path.isdir(src_file)): lg.log("update_common_info: Copying directory tree " + src_file + " to " + destn_dir) copytree(src_file, destn_dir) else: for file in glob(src_file): # for wildcards lg.log("Copying " + file + " to " + destn_dir) shutil.copy(file, destn_dir) if ('src_file_vars' in step_dict_flavor.keys()) and (len(step_dict_flavor['src_file_vars']) > 0): src_file_vars = step_dict_flavor['src_file_vars'] for key in src_file_vars.keys(): destn_dir = step_dict_flavor['destn_dir'] for src_file in src_file_vars[key]: # Directory vs File if (os.path.isfile(src_file)): # No wildcards destloc = destn_dir if(key.lower() != 'true'): # Rename file based on attribute value destloc = os.path.join(destn_dir, key) base_dir = os.path.dirname(destloc) if os.path.exists(base_dir) is False: os.mkdir(base_dir) lg.log("Copying " + src_file + " to " + destloc) shutil.copy(src_file, destloc) elif (os.path.isdir(src_file)): lg.log("update_common_info: Copying directory tree " + src_file + " to " + destn_dir) copytree(src_file, destn_dir) else: for file in glob(src_file): # for wildcards lg.log("Copying " + file + " to " + destn_dir) shutil.copy(file, destn_dir) lg.log("build.py: --------------------------------------------------\n") # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def preprocess_step (step_dict_flavor, flavor): # If step is "exec" process the tool name to get path if ('tool_name' in step_dict_flavor): tool_name = step_dict['tool_name'] tool_build = mi.get_tool_build(tool_name, 'workflow') if tool_build: # If valid build exists, get the full path to tool tool_pfn = join_paths(mi.get_build_path(tool_build), mi.get_tool_path(tool_name, 'workflow'), tool_name) step_dict_flavor['tool_name'] = tool_pfn else: step_dict_flavor['tool_name'] = None # The tool for this exec step is not present. Need not proceed... return # If destination directory is specified, create if not found if ('destn_dir' in step_dict_flavor): destn_dir = ml.clean_wvars(step_dict_flavor['destn_dir']) if not os.path.exists(destn_dir): lg.log("update_common_info.py: Creating directory " + destn_dir) os.makedirs(destn_dir) # After evaluating map it back to the dictionary step_dict_flavor['destn_dir'] = destn_dir # If execution directory is specified, create and cd to it if ('exec_dir' in step_dict_flavor): exec_dir = ml.clean_wvars(step_dict_flavor['exec_dir']) if not os.path.exists(exec_dir): os.makedirs(exec_dir) # Save the current path and change to exec_dir start_dir = os.getcwd() step_dict_flavor['start_dir'] = start_dir os.chdir(exec_dir) step_dict_flavor['exec_dir'] = exec_dir lg.log("Changed working directory to " + step_dict_flavor['exec_dir']); for step_elem in step_dict_flavor.keys(): if step_elem.startswith('root_dir'): build = ml.clean_wvars(step_dict_flavor[step_elem]) root_dir_si = mi.get_build_path(build) step_dict_flavor[step_elem] = root_dir_si # Get list of source files based on the given key src_files = [] if ('src_files' in step_dict_flavor): src_files = step_dict_flavor['src_files'] if '$' in src_files: # If source_files is listed as var:value pair, use get_files and filter with provided attr # This will return a list of files filtered with flavor and attribute attr = ml.clean_wvars(src_files) src_files = mi.get_files(attr=attr, flavor=flavor) else: # Treat is just as a file or a directory path and make it a list src_files = [ml.clean_wvars(src_files)] step_dict_flavor['src_files'] = src_files src_file_vars = [] if ('src_file_vars' in step_dict_flavor): # If source is listed as file_vars, use get_file_vars # This will return a dictionary with var:[file] pairs attr = ml.clean_wvars(step_dict_flavor['src_file_vars']) src_file_vars = mi.get_file_vars(attr, flavor = flavor) step_dict_flavor['src_file_vars'] = src_file_vars
def preprocess_step (step_dict_flavor, flavor): # If step is "exec" process the tool name to get path if ('tool_name' in step_dict_flavor): tool_name = step_dict['tool_name'] tool_build = mi.get_tool_build(tool_name, 'workflow') if tool_build: # If valid build exists, get the full path to tool tool_pfn = join_paths(mi.get_build_path(tool_build), mi.get_tool_path(tool_name, 'workflow'), tool_name) step_dict_flavor['tool_name'] = tool_pfn else: step_dict_flavor['tool_name'] = None # The tool for this exec step is not present. Need not proceed... return # If destination directory is specified, create if not found if ('destn_dir' in step_dict_flavor): destn_dir = clean_vars(step_dict_flavor['destn_dir']) if not os.path.exists(destn_dir): lg.log("update_common_info.py: Creating directory " + destn_dir) os.makedirs(destn_dir) # After evaluating map it back to the dictionary step_dict_flavor['destn_dir'] = destn_dir # If execution directory is specified, create and cd to it if ('exec_dir' in step_dict_flavor): exec_dir = clean_vars(step_dict_flavor['exec_dir']) if not os.path.exists(exec_dir): os.makedirs(exec_dir) # Save the current path and change to exec_dir start_dir = os.getcwd() step_dict_flavor['start_dir'] = start_dir os.chdir(exec_dir) step_dict_flavor['exec_dir'] = exec_dir lg.log("Changed working directory to " + step_dict_flavor['exec_dir']); # If root directory is specified, get the root of that build if ('root_dir' in step_dict_flavor): if ('$[build' in step_dict_flavor['root_dir']): build = clean_vars(step_dict_flavor['root_dir']) root_dir = mi.get_build_path(build) step_dict_flavor['root_dir'] = root_dir # Get list of source files based on the given key src_files = [] if ('src_files' in step_dict_flavor): src_files = step_dict_flavor['src_files'] if '$' in src_files: # If source_files is listed as var:value pair, use get_files and filter with provided attr # This will return a list of files filtered with flavor and attribute attr = clean_vars(src_files) src_files = mi.get_files(attr=attr, flavor=flavor) else: # Treat is just as a file or a directory path and make it a list src_files = [clean_vars(src_files)] step_dict_flavor['src_files'] = src_files src_file_vars = [] if ('src_file_vars' in step_dict_flavor): # If source is listed as file_vars, use get_file_vars # This will return a dictionary with var:[file] pairs attr = clean_vars(step_dict_flavor['src_file_vars']) src_file_vars = mi.get_file_vars(attr, flavor = flavor) step_dict_flavor['src_file_vars'] = src_file_vars
if options.clean_build: ml.CleanBuild() sys.exit() # Create snapshot file list to track generated files list in build process. ml.SaveFilesSnapshot() #---------------------------------------------------------# # Get bearings # #---------------------------------------------------------# on_linux = sys.platform.startswith("linux") #---------------------------------------------------------# # Initialize logger and print some diagnostic info # #---------------------------------------------------------# lg = lg.Logger('update_common') lg.log("build.py: Platform is:" + sys.platform,verbose=0) lg.log("build.py: Python Version is:" + sys.version,verbose=0) lg.log("build.py: Current directory is:" + os.getcwd(),verbose=0) #---------------------------------------------------------------------# # Check "common/config/" folder if multi-variant contents XML exist # #---------------------------------------------------------------------# contents_xml = '../../contents.xml' var_contents_xml = '../config/contents.xml' #Default variant if os.path.exists(var_contents_xml) or len(options.variant_contents_xml) > 0: #Might be support multi-variant if len(options.variant_contents_xml) > 0: var_contents_xml = '../config/contents_' + options.variant_contents_xml + '.xml' if not os.path.exists(var_contents_xml): lg.log("Error : " + var_contents_xml + " not found!!!") sys.exit(1) lg.log("Selected variant: " + var_contents_xml)
# Can all options be checked in single shot? if not (options.cmm or options.non_hlos or options.hlos): options.cmm = True options.non_hlos = True options.hlos = True #---------------------------------------------------------# # Get bearings # #---------------------------------------------------------# on_linux = sys.platform.startswith("linux") #---------------------------------------------------------# # Initialize logger and print some diagnostic info # #---------------------------------------------------------# lg = lg.Logger('update_common') lg.log("build.py: Platform is:" + sys.platform,verbose=0) lg.log("build.py: Python Version is:" + sys.version,verbose=0) lg.log("build.py: Current directory is:" + os.getcwd(),verbose=0) #---------------------------------------------------------# # Load the Meta-Info file # #---------------------------------------------------------# lg.log("build.py: Loading the Meta-Info file",verbose=0) mi = ml.meta_info(logger=lg) #---------------------------------------------------------# # Get flavor information # #---------------------------------------------------------# flavors = mi.get_product_flavors() # Returns empty list [] if no flavors found
def workflow_copy(step_dict): # Execution step should specify the tool name to run if not ('destn_dir' in step_dict or 'src_files' in step_dict): lg.log("update_common_info.py: Invalid copy step! Source Files or Destination not specified") else: for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) lg.log("build.py: --------------------------------------------------") lg.log("build.py: Starting copy") if ('src_files' in step_dict_flavor.keys()): src_files = step_dict_flavor['src_files'] destn_dir = step_dict_flavor['destn_dir'] # Copy each file in the list for src_file in src_files: # Directory vs File if (os.path.isdir(src_file)): lg.log("update_common_info: Copying directory tree " + src_file + " to " + destn_dir) copytree(src_file, destn_dir) else: for file in glob(src_file): # for wildcards lg.log("Copying " + file + " to " + destn_dir) shutil.copy(file, destn_dir) lg.log("build.py: --------------------------------------------------\n") # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def workflow_exec(step_dict): # Execution step should specify the tool name to run if not ('tool_name' in step_dict or 'params' in step_dict): lg.log("update_common_info.py: Invalid exec step! Tool name or command not specified") else: for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) # After preprocess check if the tool is available and execute if step_dict_flavor['tool_name']: lg.log("build.py: --------------------------------------------------") lg.log("build.py: Calling " + step_dict_flavor['tool_name'].split('/')[-1] + " " + (flavor or "")) # Check if the step has file_vars or files and loop accordingly if ('src_file_vars' in step_dict_flavor.keys()) and (len(step_dict_flavor['src_file_vars']) > 0): src_file_vars = step_dict_flavor['src_file_vars'] for key in src_file_vars.keys(): step_dict_flavor['src_file_var'] = key for file in src_file_vars[key]: step_dict_flavor['src_file'] = file params = evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py") ))): err_msg = "build.py: "+params+":Failed" lg.log(err_msg) raise Exception(err_msg) elif ('src_files' in step_dict_flavor.keys()) and (len(step_dict_flavor['src_files']) > 0): src_files = step_dict_flavor['src_files'] for src_file in src_files: if (src_file.find('Product_Info.json') != -1) and (bool(options.product_json) == True): #Create Product_Info.json for each flavor gen_product_json(flavor); step_dict_flavor['src_file'] = src_file params = evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py") ))): err_msg = "build.py: "+params+":Failed" lg.log("err_msg") raise Exception(err_msg) else: params = evaluate_params(step_dict_flavor) lg.log("build.py: --------------------------------------------------\n") return_code = lg.log_exec(params) if (return_code != 0 and (('tool_name' in step_dict) and (step_dict['tool_name'] in ("fatadd.py","fatgen.py","ptool.py","pil-splitter.py","checksparse.py") ))): err_msg = "build.py: "+params+":Failed" lg.log(err_msg) raise Exception(err_msg) if ('start_dir' in step_dict_flavor.keys()): # cd'd to exec_dir in preprocessing, so revert back os.chdir(step_dict_flavor['start_dir']) del step_dict_flavor['start_dir'] # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def workflow_copy(step_dict): # Execution step should specify the tool name to run if not ('destn_dir' in step_dict or 'src_files' in step_dict): lg.log("update_common_info.py: Invalid copy step! Source Files or Destination not specified") else: for flavor in flavors: # Make a copy of step_dict for current flavor (step_dict_flavor, flavor_flag) = create_flavor_dict(step_dict, flavor) # Preprocess the standard items in the step preprocess_step(step_dict_flavor, flavor) lg.log("build.py: --------------------------------------------------") lg.log("build.py: Starting copy") if ('src_files' in step_dict_flavor.keys()): src_files = step_dict_flavor['src_files'] destn_dir = step_dict_flavor['destn_dir'] # Copy each file in the list for src_file in src_files: # Directory vs File if (os.path.isdir(src_file)): lg.log("update_common_info: Copying directory tree " + src_file + " to " + destn_dir) copytree(src_file, destn_dir) else: for file in glob(src_file): # for wildcards lg.log("Copying " + file + " to " + destn_dir) shutil.copy(file, destn_dir) lg.log("build.py: --------------------------------------------------\n") # Don't have to repeat if the step doesn't contain flavor info if (len(flavors) > 0) and (not flavor_flag): break
def use_fat_add (): for flavor in bin_file_dests: fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin') #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created #if NON-HLOS.bin already exists, fatgen.py doesn't create it #deleting this file so that it is created each time if os.path.exists( fat_file_dest ): os.remove( fat_file_dest ) lg.log("Existing " + fat_file_dest + " has been deleted.") if (fatgen_build): # Create NON-HLOS.bin of container size as specified in partition.xml modem_partition_size = use_fatgen_toget_partitionsize () ret_code_fatgen_tool = lg.log_exec(['python',fatgen_tool,'-f','-s',modem_partition_size,'-n',fat_file_dest],verbose=0) if ret_code_fatgen_tool != 0: err_msg = 'update_common_info.py:'+'python'+' '+fatgen_tool+' '+'-f'+' '+'-s'+' '+modem_partition_size+' '+'-n'+' '+fat_file_dest +':Faled' lg.log(err_msg) raise Exception(err_msg) else: # Copy fat.bin to our root directory. Assume fat.bin is in same directory as cpfatfs.exe shutil.copy(fatadd_path + fat_file_src, fat_file_dest) os.chmod(fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH) # Add each "fat_file" from contents.xml fatFiles = mi.get_files(attr = 'fat_file', flavor=flavor) # Create sub directories in NON-HLOS.bin for each "sub_dir" from contents.xml subDirFiles = mi.get_files(attr = 'sub_dir', flavor=flavor,abs=False) subDirFatFiles = {} if len(subDirFiles) > 0: for relfile in subDirFiles: for absfile in fatFiles: tempabsfile = absfile if on_linux == False: tempabsfile = absfile.replace('/','\\') if tempabsfile.find(relfile) != -1: subDirFatFiles[absfile] = os.path.dirname(relfile) for fat_file in fatFiles: fat_dest_dir = 'image' lg.log(fat_file) if fat_file in subDirFatFiles: fat_dest_dir = os.path.join(fat_dest_dir,subDirFatFiles[fat_file]) lg.log('update_common_info.py:' + 'fatadd' + ' ' + fat_file + ' ' + fat_file_dest,verbose=0) ret_code_fatadd_tool = lg.log_exec(['python',fatadd_tool,'-n',fat_file_dest,'-f' + fat_file,'-d'+ fat_dest_dir],verbose=0) if ret_code_fatadd_tool != 0: err_msg = 'update_common_info.py:' + 'python'+' '+fatadd_tool+' '+'-n'+' '+fat_file_dest+' '+'-f' + ' '+fat_file+' '+'-d'+' '+ fat_dest_dir+':Failed' lg.log(err_msg) raise Exception(err_msg) # Add ver_info.txt fat_dest_dir = 'verinfo' bid_file = os.path.join(os.path.dirname(__file__), 'Ver_Info.txt') if os.path.exists(bid_file): lg.log('update_common_info.py:' + 'fatadd' + ' ' + bid_file + ' ' + fat_file_dest,verbose=0) ret_code_fatadd_tool = lg.log_exec(['python',fatadd_tool,'-n',fat_file_dest,'-f' + bid_file,'-d'+ fat_dest_dir],verbose=0) if ret_code_fatadd_tool != 0: err_msg = 'update_common_info.py:' + 'python'+' '+fatadd_tool+' '+'-n'+' '+fat_file_dest+' '+'-f' + bid_file+' '+'-d'+ fat_dest_dir+':Failed' lg.log(err_msg) raise Exception(err_msg)
# Can all options be checked in single shot? if not (options.cmm or options.non_hlos or options.hlos): options.cmm = True options.non_hlos = True options.hlos = True #---------------------------------------------------------# # Get bearings # #---------------------------------------------------------# on_linux = sys.platform.startswith("linux") #---------------------------------------------------------# # Initialize logger and print some diagnostic info # #---------------------------------------------------------# lg = lg.Logger('update_common') lg.log("build.py: Platform is:" + sys.platform,verbose=0) lg.log("build.py: Python Version is:" + sys.version,verbose=0) lg.log("build.py: Current directory is:" + os.getcwd(),verbose=0) #---------------------------------------------------------# # Load the Meta-Info file # #---------------------------------------------------------# lg.log("build.py: Loading the Meta-Info file",verbose=0) mi = ml.meta_info(logger=lg) #---------------------------------------------------------# # Get flavor information # #---------------------------------------------------------# flavors = mi.get_product_flavors() # Returns empty list [] if no flavors found
def use_fat_add (): for flavor in bin_file_dests: fat_file_dest = os.path.join(bin_file_dests[flavor], 'NON-HLOS.bin') #if NON-HLOS.bin exists delete it, a new NON-HLOS.bin will be created #if NON-HLOS.bin already exists, fatgen.py doesn't create it #deleting this file so that it is created each time if os.path.exists( fat_file_dest ): os.remove( fat_file_dest ) lg.log("Existing " + fat_file_dest + " has been deleted.") if (fatgen_build): # Create NON-HLOS.bin of container size as specified in partition.xml modem_partition_size = use_fatgen_toget_partitionsize () ret_code_fatgen_tool = lg.log_exec(['python',fatgen_tool,'-f','-s',modem_partition_size,'-n',fat_file_dest],verbose=0) if ret_code_fatgen_tool != 0: err_msg = 'update_common_info.py:'+'python'+' '+fatgen_tool+' '+'-f'+' '+'-s'+' '+modem_partition_size+' '+'-n'+' '+fat_file_dest +':Faled' lg.log(err_msg) raise Exception(err_msg) else: # Copy fat.bin to our root directory. Assume fat.bin is in same directory as cpfatfs.exe shutil.copy(fatadd_path + fat_file_src, fat_file_dest) os.chmod(fat_file_dest, stat.S_IREAD | stat.S_IWRITE | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH) # Add each "fat_file" from contents.xml fatFiles = mi.get_files(attr = 'fat_file', flavor=flavor) # Create sub directories in NON-HLOS.bin for each "sub_dir" from contents.xml subDirFiles = mi.get_files(attr = 'sub_dir', flavor=flavor,abs=False) subDirFatFiles = {} if len(subDirFiles) > 0: for relfile in subDirFiles: for absfile in fatFiles: tempabsfile = absfile if on_linux == False: tempabsfile = absfile.replace('/','\\') if tempabsfile.find(relfile) != -1: subDirFatFiles[absfile] = os.path.dirname(relfile) for fat_file in fatFiles: fat_dest_dir = 'image' print fat_file if fat_file in subDirFatFiles: fat_dest_dir = os.path.join(fat_dest_dir,subDirFatFiles[fat_file]) lg.log('update_common_info.py:' + 'fatadd' + ' ' + fat_file + ' ' + fat_file_dest,verbose=0) ret_code_fatadd_tool = lg.log_exec(['python',fatadd_tool,'-n',fat_file_dest,'-f' + fat_file,'-d'+ fat_dest_dir],verbose=0) if ret_code_fatadd_tool != 0: err_msg = 'update_common_info.py:' + 'python'+' '+fatadd_tool+' '+'-n'+' '+fat_file_dest+' '+'-f' + ' '+fat_file+' '+'-d'+' '+ fat_dest_dir+':Failed' lg.log(err_msg) raise Exception(err_msg) # Add ver_info.txt fat_dest_dir = 'verinfo' bid_file = os.path.join(os.path.dirname(__file__), 'Ver_Info.txt') if os.path.exists(bid_file): lg.log('update_common_info.py:' + 'fatadd' + ' ' + bid_file + ' ' + fat_file_dest,verbose=0) ret_code_fatadd_tool = lg.log_exec(['python',fatadd_tool,'-n',fat_file_dest,'-f' + bid_file,'-d'+ fat_dest_dir],verbose=0) if ret_code_fatadd_tool != 0: err_msg = 'update_common_info.py:' + 'python'+' '+fatadd_tool+' '+'-n'+' '+fat_file_dest+' '+'-f' + bid_file+' '+'-d'+ fat_dest_dir+':Failed' lg.log(err_msg) raise Exception(err_msg)