def _set_target(self, expanded_dic, uvproj_dic, tool_name): pro_def = ProGenDef(tool_name) if not pro_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) mcu_def_dic = pro_def.get_tool_definition(expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Target definitions were not found for %s. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) logger.debug("Mcu definitions: %s" % mcu_def_dic) uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Device'] = mcu_def_dic['TargetOption']['Device'][0] uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['DeviceId'] = mcu_def_dic['TargetOption']['DeviceId'][0] try: uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Vendor'] = mcu_def_dic['TargetOption']['Vendor'][0] uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Cpu'] = mcu_def_dic['TargetOption']['Cpu'][0].encode('utf-8') uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['FlashDriverDll'] = str(mcu_def_dic['TargetOption']['FlashDriverDll'][0]).encode('utf-8') uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['SFDFile'] = mcu_def_dic['TargetOption']['SFDFile'][0] except KeyError: # TODO: remove for next patch logger.debug("Using old definitions which are faulty for uvision, please update >v0.1.3.") # overwrite the template if target has defined debugger # later progen can overwrite this if debugger is set in project data try: debugger_name = pro_def.get_debugger(expanded_dic['target'])['name'] uvproj_dic['Project']['Targets']['Target']['TargetOption']['DebugOption']['TargetDlls']['Driver'] = self.definitions.debuggers[debugger_name]['TargetDlls']['Driver'] uvproj_dic['Project']['Targets']['Target']['TargetOption']['Utilities']['Flash2'] = self.definitions.debuggers[debugger_name]['Utilities']['Flash2'] except (TypeError, KeyError) as err: pass # Support new device packs if 'PackID' in mcu_def_dic['TargetOption']: if tool_name != 'uvision5': # using software packs require v5 logger.info("The target might not be supported in %s, requires uvision5" % tool_name) uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['PackID'] = mcu_def_dic['TargetOption']['PackID'][0]
def _uvoptx_set_debugger(self, expanded_dic, uvoptx_dic, tool_name): pro_def = ProGenDef(tool_name) if not pro_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) mcu_def_dic = pro_def.get_tool_definition(expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Target definitions were not found for %s. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) logger.debug("Mcu definitions: %s" % mcu_def_dic) # set the same target name FlashDriverDll config as in uvprojx file try: uvoptx_dic['ProjectOpt']['Target']['TargetName'] = expanded_dic['name'] uvoptx_dic['ProjectOpt']['Target']['TargetOption']['TargetDriverDllRegistry']['SetRegEntry']['Name'] = str(mcu_def_dic['TargetOption']['FlashDriverDll'][0]).encode('utf-8') except KeyError: return # load debugger from target dictionary or use default debugger try: debugger_dic = pro_def.get_debugger(expanded_dic['target']) if debugger_dic is None: debugger_name = self.definitions.debuggers_default else: debugger_name = debugger_dic['name'] uvoptx_dic['ProjectOpt']['Target']['TargetOption']['DebugOpt']['nTsel'] = self.definitions.debuggers[debugger_name]['uvoptx']['DebugOpt']['nTsel'] uvoptx_dic['ProjectOpt']['Target']['TargetOption']['DebugOpt']['pMon'] = self.definitions.debuggers[debugger_name]['uvoptx']['DebugOpt']['pMon'] uvoptx_dic['ProjectOpt']['Target']['TargetOption']['TargetDriverDllRegistry']['SetRegEntry']['Key'] = self.definitions.debuggers[debugger_name]['uvoptx']['SetRegEntry']['Key'] except KeyError: raise RuntimeError("Debugger %s is not supported" % expanded_dic['debugger'])
def _set_target(self, expanded_dic, uvproj_dic, tool_name): pro_def = ProGenDef(tool_name) if not pro_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) mcu_def_dic = pro_def.get_tool_definition(expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Target definitions were not found for %s. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) logger.debug("Mcu definitions: %s" % mcu_def_dic) uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Device'] = mcu_def_dic['TargetOption']['Device'][0] uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['DeviceId'] = mcu_def_dic['TargetOption']['DeviceId'][0] try: uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Vendor'] = mcu_def_dic['TargetOption']['Vendor'][0] uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['Cpu'] = mcu_def_dic['TargetOption']['Cpu'][0].encode('utf-8') uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['FlashDriverDll'] = str(mcu_def_dic['TargetOption']['FlashDriverDll'][0]).encode('utf-8') uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['SFDFile'] = mcu_def_dic['TargetOption']['SFDFile'][0] uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['RegisterFile'] = mcu_def_dic['TargetOption']['RegisterFile'][0] except KeyError: pass # overwrite the template if target has defined debugger # later progen can overwrite this if debugger is set in project data try: debugger_name = pro_def.get_debugger(expanded_dic['target'])['name'] uvproj_dic['Project']['Targets']['Target']['TargetOption']['DebugOption']['TargetDlls']['Driver'] = self.definitions.debuggers[debugger_name]['uvproj']['TargetDlls']['Driver'] uvproj_dic['Project']['Targets']['Target']['TargetOption']['Utilities']['Flash2'] = self.definitions.debuggers[debugger_name]['uvproj']['Utilities']['Flash2'] except (TypeError, KeyError) as err: pass # Support new device packs if 'PackID' in mcu_def_dic['TargetOption']: if tool_name != 'uvision5': # using software packs require v5 logger.info("The target might not be supported in %s, requires uvision5" % tool_name) uvproj_dic['Project']['Targets']['Target']['TargetOption']['TargetCommonOption']['PackID'] = mcu_def_dic['TargetOption']['PackID'][0]
def _export_single_project(self): """ Processes groups and misc options specific for CoIDE, and run generator """ expanded_dic = self.workspace.copy() # TODO 0xc0170: fix misc , its a list with a dictionary if 'misc' in expanded_dic and bool(expanded_dic['misc']): print( "Using deprecated misc options for coide. Please use template project files." ) groups = self._get_groups() expanded_dic['groups'] = {} for group in groups: expanded_dic['groups'][group] = [] self._iterate(self.workspace, expanded_dic) # generic tool template specified or project if expanded_dic['template']: for template in expanded_dic['template']: template = join(getcwd(), template) if splitext(template)[1] == '.coproj' or re.match( '.*\.coproj.tmpl$', template): try: coproj_dic = xmltodict.parse(open(template)) except IOError: logger.info( "Template file %s not found. Using default template" % template) coproj_dic = self.definitions.coproj_file else: logger.info( "Template file %s contains unknown template extension (.coproj/.coproj.tmpl are valid). Using default one" % template) coproj_dic = self.definitions.coproj_file elif 'coide' in self.env_settings.templates.keys(): # template overrides what is set in the yaml files for template in self.env_settings.templates['coide']: template = join(getcwd(), template) if splitext(template)[1] == '.coproj' or re.match( '.*\.coproj.tmpl$', template): try: coproj_dic = xmltodict.parse(open(template)) except IOError: logger.info( "Template file %s not found. Using default template" % template) coproj_dic = self.definitions.coproj_file else: logger.info( "Template file %s contains unknown template extension (.coproj/.coproj.tmpl are valid). Using default one" % template) coproj_dic = self.definitions.coproj_file else: # setting values from the yaml files coproj_dic = self.definitions.coproj_file # set name and target try: coproj_dic['Project']['@name'] = expanded_dic['name'] except KeyError: raise RuntimeError("The coide template is not valid .coproj file") coproj_dic['Project']['Target']['@name'] = expanded_dic['name'] # library/exe coproj_dic['Project']['Target']['BuildOption']['Output']['Option'][0][ '@value'] = 0 if expanded_dic['output_type'] == 'exe' else 1 # Fill in progen data to the coproj_dic self._coproj_set_files(coproj_dic, expanded_dic) self._coproj_set_macros(coproj_dic, expanded_dic) self._coproj_set_includepaths(coproj_dic, expanded_dic) self._coproj_set_linker(coproj_dic, expanded_dic) # set target only if defined, otherwise use from template/default one if expanded_dic['target']: pro_def = ProGenDef('coide') if not pro_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported." % expanded_dic['target'].lower()) mcu_def_dic = pro_def.get_tool_definition( expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Mcu definitions were not found for %s. Please add them to https://github.com/0xc0170/project_generator_definitions" % expanded_dic['target'].lower()) self._normalize_mcu_def(mcu_def_dic) logger.debug("Mcu definitions: %s" % mcu_def_dic) # correct attributes from definition, as yaml does not allowed multiple keys (=dict), we need to # do this magic. for k, v in mcu_def_dic['Device'].items(): del mcu_def_dic['Device'][k] mcu_def_dic['Device']['@' + k] = str(v) memory_areas = [] for k, v in mcu_def_dic['MemoryAreas'].items(): # ??? duplicate use of k for k, att in v.items(): del v[k] v['@' + k] = str(att) memory_areas.append(v) coproj_dic['Project']['Target']['Device'].update( mcu_def_dic['Device']) # TODO 0xc0170: fix debug options # coproj_dic['Project']['Target']['DebugOption'].update(mcu_def_dic['DebugOption']) coproj_dic['Project']['Target']['BuildOption']['Link'][ 'MemoryAreas']['Memory'] = memory_areas # TODO 0xc0170: create a method and look at finding that option if we can reuse already defined method try: # find debugger definitions in the list of options index = 0 for option in coproj_dic['Project']['Target']['DebugOption'][ 'Option']: # ??? k, v not used ??? for k, v in option.items(): if option[ '@name'] == 'org.coocox.codebugger.gdbjtag.core.adapter': found = index index += 1 debugger_name = pro_def.get_debugger( expanded_dic['target'])['name'] coproj_dic['Project']['Target']['DebugOption']['Option'][ found]['@value'] = self.definitions.debuggers[ debugger_name]['Target']['DebugOption'][ 'org.coocox.codebugger.gdbjtag.core.adapter'] except (TypeError, KeyError) as err: pass # get debugger definitions if expanded_dic['debugger']: try: # find debugger definitions in the list of options index = 0 for option in coproj_dic['Project']['Target']['DebugOption'][ 'Option']: # ??? k, v not used ??? for k, v in option.items(): if option[ '@name'] == 'org.coocox.codebugger.gdbjtag.core.adapter': found = index index += 1 coproj_dic['Project']['Target']['DebugOption']['Option'][ found]['@value'] = self.definitions.debuggers[ expanded_dic['debugger']]['Target']['DebugOption'][ 'org.coocox.codebugger.gdbjtag.core.adapter'] except KeyError: raise RuntimeError("Debugger %s is not supported" % expanded_dic['debugger']) # Project file # somehow this xml is not compatible with coide, coide v2.0 changing few things, lets use jinja # for now, more testing to get xml output right. Jinja template follows the xml dictionary,which is # what we want anyway. # coproj_xml = xmltodict.unparse(coproj_dic, pretty=True) project_path, projfile = self.gen_file_jinja( 'coide.coproj.tmpl', coproj_dic, '%s.coproj' % expanded_dic['name'], expanded_dic['output_dir']['path']) return project_path, projfile
def _export_single_project(self): """ A single project export """ expanded_dic = self.workspace.copy() self._fix_paths(expanded_dic) # generic tool template specified or project if expanded_dic['template']: template_ewp = False template_ewd = False # process each template file for template in expanded_dic['template']: template = join(getcwd(), template) # we support .ewp or .ewp.tmpl templates if os.path.splitext(template)[1] == '.ewp' or re.match( '.*\.ewp.tmpl$', template): try: ewp_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file).read()) if os.path.splitext(template)[1] == '.ewd' or re.match( '.*\.ewd.tmpl$', template): try: ewd_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewd = True except IOError: logger.info("Template file %s not found" % template) ewd_dic = xmltodict.parse(open(self.ewd_file).read()) # handle non valid template files or not specified if not template_ewp and template_ewd: ewp_dic, _ = self._get_default_templates() elif not template_ewd and template_ewp: _, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() elif 'iar' in self.env_settings.templates.keys(): template_ewp = False template_ewd = False # template overrides what is set in the yaml files for template in self.env_settings.templates['iar']: template = join(getcwd(), template) if os.path.splitext(template)[1] == '.ewp' or re.match( '.*\.ewp.tmpl$', template): try: ewp_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file).read()) if os.path.splitext(template)[1] == '.ewd' or re.match( '.*\.ewd.tmpl$', template): # get ewd template try: ewd_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewd = True except IOError: logger.info("Template file %s not found" % template) ewd_dic = xmltodict.parse(open(self.ewd_file).read()) # handle non valid template files or not specified if not template_ewp and template_ewd: ewp_dic, _ = self._get_default_templates() elif not template_ewd and template_ewp: _, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() eww = None if self.workspace['singular']: # TODO 0xc0170: if we use here self.definitions.eww, travis fails. I cant reproduce it and dont see # eww used anywhere prior to exporting this. eww_dic = { u'workspace': { u'project': { u'path': u'' }, u'batchBuild': None } } # set eww self._eww_set_path_single_project(eww_dic, expanded_dic['name']) eww_xml = xmltodict.unparse(eww_dic, pretty=True) project_path, eww = self.gen_file_raw( eww_xml, '%s.eww' % expanded_dic['name'], expanded_dic['output_dir']['path']) try: ewp_configuration = ewp_dic['project']['configuration'][0] logging.debug( "Provided .ewp file has multiple configuration, we use only the first one" ) ewp_dic['project']['configuration'] = ewp_dic['project'][ 'configuration'][0] except KeyError: ewp_configuration = ewp_dic['project']['configuration'] try: ewp_configuration = ewp_dic['project']['configuration'][0] logging.debug( "Provided .ewp file has multiple configuration, we use only the first one" ) ewp_dic['project']['configuration'] = ewp_dic['project'][ 'configuration'][0] except KeyError: ewp_configuration = ewp_dic['project']['configuration'] # replace all None with empty strings '' self._clean_xmldict_ewp(ewp_configuration) #self._clean_xmldict_ewd(ewd_dic) try: self._ewp_set_name(ewp_configuration, expanded_dic['name']) except KeyError: raise RuntimeError("The IAR template is not valid .ewp file") # set ARM toolchain and project name\ self._ewp_set_toolchain(ewp_configuration, 'ARM') # set common things we have for IAR self._ewp_general_set(ewp_configuration['settings'], expanded_dic) self._ewp_iccarm_set(ewp_configuration['settings'], expanded_dic) self._ewp_aarm_set(ewp_configuration['settings'], expanded_dic) self._ewp_ilink_set(ewp_configuration['settings'], expanded_dic) self._ewp_files_set(ewp_dic, expanded_dic) # set target only if defined, otherwise use from template/default one if expanded_dic['target']: # get target definition (target + mcu) proj_def = ProGenDef('iar') if not proj_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported." % expanded_dic['target'].lower()) mcu_def_dic = proj_def.get_tool_definition( expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Mcu definitions were not found for %s. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) self._normalize_mcu_def(mcu_def_dic) logger.debug("Mcu definitions: %s" % mcu_def_dic) self._ewp_set_target(ewp_configuration['settings'], mcu_def_dic) try: debugger = proj_def.get_debugger(expanded_dic['target']) self._ewd_set_debugger( ewd_dic['project']['configuration']['settings'], debugger) except KeyError as err: # TODO: worth reporting? pass # overwrite debugger only if defined in the project file, otherwise use either default or from template if expanded_dic['debugger']: try: self._ewd_set_debugger( ewd_dic['project']['configuration']['settings'], expanded_dic['debugger']) except KeyError: raise RuntimeError("Debugger %s is not supported" % expanded_dic['debugger']) self._ewd_set_name(ewd_dic['project']['configuration'], expanded_dic['name']) # IAR uses ident 2 spaces, encoding iso-8859-1 ewp_xml = xmltodict.unparse(ewp_dic, encoding='iso-8859-1', pretty=True, indent=' ') project_path, ewp = self.gen_file_raw( ewp_xml, '%s.ewp' % expanded_dic['name'], expanded_dic['output_dir']['path']) ewd_xml = xmltodict.unparse(ewd_dic, encoding='iso-8859-1', pretty=True, indent=' ') project_path, ewd = self.gen_file_raw( ewd_xml, '%s.ewd' % expanded_dic['name'], expanded_dic['output_dir']['path']) return project_path, [ewp, eww, ewd]
def _export_single_project(self): """ Processes groups and misc options specific for CoIDE, and run generator """ expanded_dic = self.workspace.copy() # TODO 0xc0170: fix misc , its a list with a dictionary if 'misc' in expanded_dic and bool(expanded_dic['misc']): print ("Using deprecated misc options for coide. Please use template project files.") groups = self._get_groups() expanded_dic['groups'] = {} for group in groups: expanded_dic['groups'][group] = [] self._iterate(self.workspace, expanded_dic) # generic tool template specified or project if expanded_dic['template']: project_file = join(getcwd(), expanded_dic['template'][0]) try: coproj_dic = xmltodict.parse(open(project_file)) except IOError: logger.info("Template file %s not found. Using default template" % project_file) coproj_dic = self.definitions.coproj_file elif 'coide' in self.env_settings.templates.keys(): # template overrides what is set in the yaml files # TODO 0xc0170: extension check/expansion project_file = join(getcwd(), self.env_settings.templates['coide'][0]) try: coproj_dic = xmltodict.parse(open(project_file)) except IOError: logger.info("Template file %s not found. Using default template" % project_file) coproj_dic = self.definitions.coproj_file else: # setting values from the yaml files coproj_dic = self.definitions.coproj_file # set name and target try: coproj_dic['Project']['@name'] = expanded_dic['name'] except KeyError: raise RuntimeError("The coide template is not valid .coproj file") coproj_dic['Project']['Target']['@name'] = expanded_dic['name'] # library/exe coproj_dic['Project']['Target']['BuildOption']['Output']['Option'][0]['@value'] = 0 if expanded_dic['output_type'] == 'exe' else 1 # Fill in progen data to the coproj_dic self._coproj_set_files(coproj_dic, expanded_dic) self._coproj_set_macros(coproj_dic, expanded_dic) self._coproj_set_includepaths(coproj_dic, expanded_dic) self._coproj_set_linker(coproj_dic, expanded_dic) # set target only if defined, otherwise use from template/default one if expanded_dic['target']: pro_def = ProGenDef('coide') if not pro_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported." % expanded_dic['target'].lower()) mcu_def_dic = pro_def.get_tool_definition(expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Mcu definitions were not found for %s. Please add them to https://github.com/0xc0170/project_generator_definitions" % expanded_dic['target'].lower()) self._normalize_mcu_def(mcu_def_dic) logger.debug("Mcu definitions: %s" % mcu_def_dic) # correct attributes from definition, as yaml does not allowed multiple keys (=dict), we need to # do this magic. for k, v in mcu_def_dic['Device'].items(): del mcu_def_dic['Device'][k] mcu_def_dic['Device']['@' + k] = str(v) memory_areas = [] for k, v in mcu_def_dic['MemoryAreas'].items(): # ??? duplicate use of k for k, att in v.items(): del v[k] v['@' + k] = str(att) memory_areas.append(v) coproj_dic['Project']['Target']['Device'].update(mcu_def_dic['Device']) # TODO 0xc0170: fix debug options # coproj_dic['Project']['Target']['DebugOption'].update(mcu_def_dic['DebugOption']) coproj_dic['Project']['Target']['BuildOption']['Link']['MemoryAreas']['Memory'] = memory_areas # TODO 0xc0170: create a method and look at finding that option if we can reuse already defined method try: # find debugger definitions in the list of options index = 0 for option in coproj_dic['Project']['Target']['DebugOption']['Option']: # ??? k, v not used ??? for k, v in option.items(): if option['@name'] == 'org.coocox.codebugger.gdbjtag.core.adapter': found = index index += 1 debugger_name =pro_def.get_debugger(expanded_dic['target'])['name'] coproj_dic['Project']['Target']['DebugOption']['Option'][found]['@value'] = self.definitions.debuggers[debugger_name]['Target']['DebugOption']['org.coocox.codebugger.gdbjtag.core.adapter'] except (TypeError, KeyError) as err: pass # get debugger definitions if expanded_dic['debugger']: try: # find debugger definitions in the list of options index = 0 for option in coproj_dic['Project']['Target']['DebugOption']['Option']: # ??? k, v not used ??? for k, v in option.items(): if option['@name'] == 'org.coocox.codebugger.gdbjtag.core.adapter': found = index index += 1 coproj_dic['Project']['Target']['DebugOption']['Option'][found]['@value'] = self.definitions.debuggers[expanded_dic['debugger']]['Target']['DebugOption']['org.coocox.codebugger.gdbjtag.core.adapter'] except KeyError: raise RuntimeError("Debugger %s is not supported" % expanded_dic['debugger']) # Project file # somehow this xml is not compatible with coide, coide v2.0 changing few things, lets use jinja # for now, more testing to get xml output right. Jinja template follows the xml dictionary,which is # what we want anyway. # coproj_xml = xmltodict.unparse(coproj_dic, pretty=True) project_path, projfile = self.gen_file_jinja( 'coide.coproj.tmpl', coproj_dic, '%s.coproj' % expanded_dic['name'], expanded_dic['output_dir']['path']) return project_path, projfile
def _export_single_project(self): """ A single project export """ expanded_dic = self.workspace.copy() self._fix_paths(expanded_dic) # generic tool template specified or project if expanded_dic['template']: template_ewp = False template_ewd = False # process each template file for template in expanded_dic['template']: template = join(getcwd(), template) # we support .ewp or .ewp.tmpl templates if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template): try: ewp_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file).read()) if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template): try: ewd_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewd = True except IOError: logger.info("Template file %s not found" % template) ewd_dic = xmltodict.parse(open(self.ewd_file).read()) # handle non valid template files or not specified if not template_ewp and template_ewd: ewp_dic, _ = self._get_default_templates() elif not template_ewd and template_ewp: _, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() elif 'iar' in self.env_settings.templates.keys(): template_ewp = False template_ewd = False # template overrides what is set in the yaml files for template in self.env_settings.templates['iar']: template = join(getcwd(), template) if os.path.splitext(template)[1] == '.ewp' or re.match('.*\.ewp.tmpl$', template): try: ewp_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewp = True except IOError: logger.info("Template file %s not found" % template) ewp_dic = xmltodict.parse(open(self.ewp_file).read()) if os.path.splitext(template)[1] == '.ewd' or re.match('.*\.ewd.tmpl$', template): # get ewd template try: ewd_dic = xmltodict.parse(open(template), dict_constructor=dict) template_ewd = True except IOError: logger.info("Template file %s not found" % template) ewd_dic = xmltodict.parse(open(self.ewd_file).read()) # handle non valid template files or not specified if not template_ewp and template_ewd: ewp_dic, _ = self._get_default_templates() elif not template_ewd and template_ewp: _, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() else: ewp_dic, ewd_dic = self._get_default_templates() eww = None if self.workspace['singular']: # TODO 0xc0170: if we use here self.definitions.eww, travis fails. I cant reproduce it and dont see # eww used anywhere prior to exporting this. eww_dic = {u'workspace': {u'project': {u'path': u''}, u'batchBuild': None}} # set eww self._eww_set_path_single_project(eww_dic, expanded_dic['name']) eww_xml = xmltodict.unparse(eww_dic, pretty=True) project_path, eww = self.gen_file_raw(eww_xml, '%s.eww' % expanded_dic['name'], expanded_dic['output_dir']['path']) try: ewp_configuration = ewp_dic['project']['configuration'][0] logging.debug("Provided .ewp file has multiple configuration, we use only the first one") ewp_dic['project']['configuration'] = ewp_dic['project']['configuration'][0] except KeyError: ewp_configuration = ewp_dic['project']['configuration'] try: ewp_configuration = ewp_dic['project']['configuration'][0] logging.debug("Provided .ewp file has multiple configuration, we use only the first one") ewp_dic['project']['configuration'] = ewp_dic['project']['configuration'][0] except KeyError: ewp_configuration = ewp_dic['project']['configuration'] # replace all None with empty strings '' self._clean_xmldict_ewp(ewp_configuration) #self._clean_xmldict_ewd(ewd_dic) try: self._ewp_set_name(ewp_configuration, expanded_dic['name']) except KeyError: raise RuntimeError("The IAR template is not valid .ewp file") # set ARM toolchain and project name\ self._ewp_set_toolchain(ewp_configuration, 'ARM') # set common things we have for IAR self._ewp_general_set(ewp_configuration['settings'], expanded_dic) self._ewp_iccarm_set(ewp_configuration['settings'], expanded_dic) self._ewp_aarm_set(ewp_configuration['settings'], expanded_dic) self._ewp_ilink_set(ewp_configuration['settings'], expanded_dic) self._ewp_files_set(ewp_dic, expanded_dic) # set target only if defined, otherwise use from template/default one if expanded_dic['target']: # get target definition (target + mcu) proj_def = ProGenDef('iar') if not proj_def.is_supported(expanded_dic['target'].lower()): raise RuntimeError("Target %s is not supported." % expanded_dic['target'].lower()) mcu_def_dic = proj_def.get_tool_definition(expanded_dic['target'].lower()) if not mcu_def_dic: raise RuntimeError( "Mcu definitions were not found for %s. Please add them to https://github.com/project-generator/project_generator_definitions" % expanded_dic['target'].lower()) self._normalize_mcu_def(mcu_def_dic) logger.debug("Mcu definitions: %s" % mcu_def_dic) self._ewp_set_target(ewp_configuration['settings'], mcu_def_dic) try: debugger = proj_def.get_debugger(expanded_dic['target']) self._ewd_set_debugger(ewd_dic['project']['configuration']['settings'], debugger) except KeyError as err: # TODO: worth reporting? pass # overwrite debugger only if defined in the project file, otherwise use either default or from template if expanded_dic['debugger']: try: self._ewd_set_debugger(ewd_dic['project']['configuration']['settings'], expanded_dic['debugger']) except KeyError: raise RuntimeError("Debugger %s is not supported" % expanded_dic['debugger']) self._ewd_set_name(ewd_dic['project']['configuration'], expanded_dic['name']) # IAR uses ident 2 spaces, encoding iso-8859-1 ewp_xml = xmltodict.unparse(ewp_dic, encoding='iso-8859-1', pretty=True, indent=' ') project_path, ewp = self.gen_file_raw(ewp_xml, '%s.ewp' % expanded_dic['name'], expanded_dic['output_dir']['path']) ewd_xml = xmltodict.unparse(ewd_dic, encoding='iso-8859-1', pretty=True, indent=' ') project_path, ewd = self.gen_file_raw(ewd_xml, '%s.ewd' % expanded_dic['name'], expanded_dic['output_dir']['path']) return project_path, [ewp, eww, ewd]