⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 umake_cwxml_ascript.py

📁 linux下的一款播放器
💻 PY
📖 第 1 页 / 共 3 页
字号:
                                        framework_string_list,                                        "#FRAMEWORK_LIST#")    else:        template_text=string.replace(template_text, "#FRAMEWORK_LIST#", "")    ## group order    template_text=SetGroupBlock(template_text,                                file_list,                                "#GROUP_LIST_ITEMS#",                                mprj.cwtarget_name)    template_text = string.replace(template_text,                                   "#GROUP_NAME#",                                   mprj.cwtarget_name)    ## CW project preferences    template_text=SetPreferenceValue(template_text, "MWFrontEnd_C_prefixname", mprj.prefix_file)    template_text=SetPreferenceValue(template_text, "MWRez_Language_prefixname", mprj.rprefix_file)                    ## set remaining preferences - theses are defined in macos-carbon-powerpc-cw6.cf    for (panel, pref) in mprj.preferences.items():        for (pref_key, pref_value) in pref.items():            template_text = SetPreferenceValue(template_text,                                               pref_key,                                               pref_value)    # set target dir to debug/release    if templateName == "project_uber.xml":          module_path = mprj.project_file_path[:-1]        module_path, module_name = os.path.split(module_path)        module_path, module_name = os.path.split(module_path)        template_text = string.replace(template_text,                                       "#TARGET_DIR#",                                       "#SRC_ROOT_PATH#%s:%s:" % (module_name,output_dir))                                               template_text = string.replace(template_text,                                       "#OUTPUT_FILE_NAME#",                                       "%s:%s" % (output_dir,mprj.output_name))    else:        template_text = string.replace(template_text,                                       "#TARGET_DIR#",                                       ":%s:" % (output_dir))    template_text = string.replace(template_text,                                   "#TARGET_NAME#",                                   mprj.cwtarget_name)    return template_text    def WriteProjectXML(mprj):    """ Writes out the CodeWarrior project definition XML         Also writes out in project_uber.xml the sections of the XML        required by the uber-project creator"""            xml=WriteProjectSettingsXML(mprj, "project.xml")    filename=mprj.project.makefile_name+".xml"    open(filename,"w").write(xml)    xml=WriteProjectSettingsXML(mprj, "project_uber.xml")    filename=mprj.project.makefile_name+"_uber.xmldata"    open(filename,"w").write(xml)class ASMakefile(umake_ascript.ASMakefile):    def RunProject(self):        mprj = self.mprj        script = self.script        all = self.all        ## create the project XML files to be imported into CW        WriteProjectXML(mprj)        xml_filename=macpath.join(os.getcwd(), mprj.project.makefile_name+".xml")        all.extend( [            '  tell application %s' % (mprj.ide_path),            '       with timeout of 99999 seconds',            '       try',            '           make new (project document) as "%s" with data ("%s")' \            % (mprj.project_file_path, xml_filename),            '        set cwErrorList to Make Project with ExternalEditor',            '        set myerrors to my ExtractCWErrors(cwErrorList)',            '        Close Project',            '        on error errText number errnum',            '        try',            '          Close Project',            '        end try',            '        --rethrow the error',            '        return errText & return',            '      end try',            '    end timeout',            '  end tell' ])# the outermost XML template for the uber project XMLUberTemplate = """<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><?codewarrior exportversion="1.0.1" ideversion="4.2" ?><PROJECT>    <TARGETLIST>#TARGET#    <TARGET><NAME>Make All</NAME>#MAKE_ALL_SUBTARGETS#</TARGET>    </TARGETLIST>    <TARGETORDER>#TARGETORDER#      <ORDEREDTARGET><NAME>Make All</NAME></ORDEREDTARGET>    </TARGETORDER>    <GROUPLIST>#GROUP#    </GROUPLIST></PROJECT>"""def declaw_name(name):    name = macpath.normpath(name)    while len(name) and name[0] == ':':        name = name[1:]    name = string.lower(name)    name = string.replace(name,":","_")    name = string.replace(name,"_makefile","")    name = string.replace(name,".mak","")    return name#### Generate an Uber-project for this umakefile and all it's dependencies## def generate_uberxml(platform, project, mprj):    global UberTemplate    target_tag = '#TARGET#'    targetorder_tag = '#TARGETORDER#'    group_tag = '#GROUP#'    make_all_subtargets_tag = '#MAKE_ALL_SUBTARGETS#'    dependencies_section_empty = '<SUBTARGETLIST></SUBTARGETLIST>'    uber_template = UberTemplate    # scoop up the uber text from each directory, add the depend    all_module_targetnames_list = []    for mod in project.get_uber_makes():        uber_file_name = mod.makefile() + "_uber.xmldata"        umake_lib.debug("Reading uber-data %r" % repr(uber_file_name))        # Read the generated UBER-file        try:            uber_text = open(uber_file_name, 'r').read()        except:            print "==> Cannot read from %s " % (uber_file_name )            continue        uber_text = string.replace(uber_text,"#SRC_ROOT_PATH#", project.src_root_path)        try:            (uber_target_name,             uber_text_1,             uber_text_2,             uber_text_3,             uber_output_path) = string.split(uber_text, "<<>>")        except:            print "==> Cannot parse %s from module %s for <<>> sections" % (uber_file_name, module.name)            continue        uber_target_name = string.strip(uber_target_name)        # also add this as a subtarget for the Make All target        all_module_targetnames_list.append(uber_target_name)        # now we look for the <SUBTARGETLIST></SUBTARGETLIST> in the target section of the        # module's XML, and replace it with a list of all actual dependencies        # make a subtarget list containing our dependencies list, and replace the empty one        # in the template with ours        deps = mod.dependencies()[:]        deps.reverse()        dependencies_section_xml = MakeDependenciesSubtargetListXML(deps)        uber_text_1 = string.replace(uber_text_1,                                     dependencies_section_empty,                                     dependencies_section_xml,                                     1)                # if an empty subtarget list is left in the template, remove it        uber_text_1 = string.replace(uber_text_1,                                     dependencies_section_empty,                                     "",                                     1)        # finally, follow the target, targetorder, and group placeholders in the top level        # template with the data for this module        template1 = string.replace(uber_template, target_tag, target_tag + '\n' + uber_text_1, 1)        template2 = string.replace(template1, targetorder_tag, targetorder_tag + '\n' + uber_text_2, 1)        uber_template = string.replace(template2, group_tag, group_tag + '\n' + uber_text_3, 1)    # if we found any uber.xml files, generate the master uber.xml file    # print "Extracted uber-project XML from %s" % (string.join(success_list, ", "))    # insert the Make All subtarget list    make_all_dependencies_section_xml = MakeDependenciesSubtargetListXML(all_module_targetnames_list)    uber_template = string.replace(uber_template,                                   make_all_subtargets_tag,                                   make_all_dependencies_section_xml, 1)    # remove the placeholder tags from the template    uber_template = string.replace(uber_template, target_tag, "", 1)    uber_template = string.replace(uber_template, targetorder_tag, "", 1)    uber_template = string.replace(uber_template, group_tag, "", 1)    # write out the file into an uber directory in the source directory    uberxml_output_name = project.makefile_name + "_uber.xml"    print "Writing %s" % (uberxml_output_name)    try:        # delete any old xml file with the same name as our uber        if os.path.isfile(uberxml_output_name):            os.remove(uberxml_output_name)        open(uberxml_output_name, 'w').write(uber_template)    except IOError:        print "*** Failed to write file %s" % (uberxml_output_name) def MakeDependenciesSubtargetListXML(subtarget_list):    # given a list of modules, make a <SUBTARGETLIST> XML section    ret = [ '<SUBTARGETLIST>']    for x in subtarget_list:        x = declaw_name(x)        ret.append('<SUBTARGET><TARGETNAME>%s</TARGETNAME></SUBTARGET>' % x)    ret.append('</SUBTARGETLIST>')    return string.join(ret,"\n")def make_makefile(platform, project):    ## FIX pncrt madness    if project.target_type == "exe" or \           project.target_type == "dll" :        fix_pncrt(project)    ## Create Applescript    mprj = ProjectToMacCWProjectData(platform, project)    applescript_path = macfs.FSSpec(project.makefile_name).as_pathname()    ASMakefile(mprj).script.CompileAndSave(applescript_path)    ## Create Uber XML file    generate_uberxml(platform, project, mprj)    ## Create an applescript stub file for reading the Uber XML file    # this needs better handling/reporting of build errors    script = ascript.CreateAppleScript()    script.Append(        'tell application %s' % (os.environ["BUILD_SW"]),        '  with timeout of 99999 seconds',        '    try',        '      make new (project document) as "%s" with data ("%s")' % (        macpath.join(os.getcwd(),project.makefile_name+"_uber.prj"),        macpath.join(os.getcwd(),project.makefile_name+"_uber.xml")),        '      set cwErrorList to Make Project with ExternalEditor',        '      Close Project',        '    on error errText number errnum',        '      return errText & return',        '    end try',        '  end timeout',        'end tell')    uber_ascript = macfs.FSSpec(project.makefile_name+"_uber").as_pathname()    script.CompileAndSave(uber_ascript)    ## Pretend like everything went well    return Nonedef compile():    """This will eventually be the primary function for invoking make"""    pass

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -