📄 umake_ascript.py
字号:
script.Extend(all) script.Append( 'return myerrors', 'end all', '-- run the "all()" function', 'return all()') script.Extend(mprj.project.post_target_buff) ## for DRM signing if mprj.project.target_type == "dll" and \ mprj.project.BuildOption("drmsign") and \ mprj.project.CheckDRMSign(): import shell shell.mkdir(os.path.dirname(absolute_output_path)) open(absolute_output_path+"--drmsign","w").write("signme!") def RunProject(self): mprj = self.mprj script = self.script all = self.all all.extend([ ' --build the main CodeWarrior Project', ' tell application %s' % (mprj.ide_path), ' Launch', ' with timeout of 99999 seconds', ' try', ' --open project or create a new one', ' set projectName to "%s"' % (mprj.project_file_path), ' try', ' open "%s"' % (mprj.project_file_path), ' on error number errnum', ' if errnum is -43 then -- Project not found', ' Create Project "%s"' % (mprj.project_file_path), ' end if', ' end try', ' --set prefix files', ' set preferences of panel "C/C++ Compiler" to '\ '{Prefix File:"%s"}' % (mprj.prefix_file), ' set preferences of panel "Rez Compiler" to '\ '{RezPrefix File:"%s"}' % (mprj.rprefix_file), ' --set preferences']) ## set misc preferences for (panel, pref) in mprj.preferences.items(): list = [] for (pref_key, pref_value) in pref.items(): list.append("%s:%s" % (pref_key, pref_value)) all.extend(['set preferences of panel "%s" to {%s}' % ( panel, string.join(list, ","))]) ## set access paths cwap = CWAccessPath() if mprj.always_full_search: cwap.AddSetting("Always Full Search", "true") else: cwap.AddSetting("Always Full Search", "false") cwap.AddSetting("Convert Paths", "true") for (path, recursive, origin) in mprj.system_paths: cwap.AddSystemPath(path, recursive, origin) for (path, recursive, origin) in mprj.user_paths: cwap.AddUserPath(path, recursive, origin) all.extend([ 'Set Preferences of panel "Access Paths" to {User Paths:{},System Paths:{},Always Full Search:false}', 'set preferences of panel "Access Paths" to %s' % (cwap.String())]) ## add source files all.extend([ '--add source files', 'Add Files {"%s"}' % (string.join(mprj.source_list, '","'))]) ## list of system/misc libraries which need to be "weak linked" for library in mprj.weak_link_list: all.extend(['my SetWeakLink("%s")' % (library)]) all.extend([ ' 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' ]) def VerifyPath(self): self.script.Append( '-- VerifyPath creates the path up to the specified folder if it doesnt already exist', '-- example usage: VerifyPath("Hard Disk:A:B") where B is the target folder that should exist', 'on VerifyPath(thePath)', ' -- first save the old text item delimiter and use ":" as the text item delimiter', ' set savedTextItemDelimiters to AppleScript\'s text item delimiters', ' set AppleScript\'s text item delimiters to ":"', ' ', ' set numPathItems to (count of text items of thePath)', ' if numPathItems > 1 then', ' set previousPartialPath to text item 1 of thePath -- previous path starts as the disk name', ' repeat with n from 2 to numPathItems', ' -- make a partial path through the nth item', ' set partialPath to (text items 1 through n of thePath) as string', ' tell application "Finder"', ' if not (exists (folder partialPath)) then', ' if n is 2 then', ' make new folder at disk previousPartialPath with properties {name:(text item n of thePath)}', ' else', ' make new folder at folder previousPartialPath with properties {name:(text item n of thePath)}', ' end if', ' end if', ' end tell', ' set previousPartialPath to partialPath', ' end repeat', 'end if', ' -- restore the text item delimiter', ' set AppleScript\'s text item delimiters to savedTextItemDelimiters', 'end VerifyPath' ) def SetWeakLink(self): """Emits a AppleScript function which can be called to set the Weak Link attribute for a dynamic library linked to the target.""" self.script.Append( '-- subroutine for setting weak linking on a ProjectFile', 'on SetWeakLink(projectFileName)', ' tell application %s' % (self.mprj.ide_path), ' set segs to Get Segments', ' set segNum to 0', ' repeat with thisSeg in segs', ' set segNum to segNum + 1', ' set numFiles to filecount of thisSeg', ' repeat with fileNum from 1 to numFiles', ' set the currentFile to (Get Project File fileNum Segment segNum)', ' set currentFileName to the name of currentFile', ' if (name of currentFile) = projectFileName then', ' -- set weak link on currentFile', ' set %sclass Weak%s of currentFile to true' % (chr(199), chr(200)), # XXX: CW2 BUG!!! ' Set Project File currentFileName to currentFile', ' end if', ' end repeat', ' end repeat', ' end tell', 'end SetWeakLink') def Clean(self): """Emits a AppleScript function to clean the target, project file, and project file data for a target.""" self.script.Append( '-- Allow the items to be made clean', 'on Clean()', ) for sumake in self.mprj.project.submakes: m_path = macpath.normpath(macpath.join(os.getcwd(), sumake.makefile())) self.script.Append( ' set scriptobj to (load script file "%s")' % (m_path), ' tell scriptobj', ' Clean()', ' end tell' ) if self.mprj.project.target_type != "": self.script.Append( ' tell application "Finder"', ' with timeout of 99999 seconds', ' if file "%s" exists then' % (self.mprj.project_file_path), ' delete file "%s"' % (self.mprj.project_file_path), ' end if', ' if folder "%s" exists then' % (self.mprj.project_data_path), ' delete folder "%s"' % (self.mprj.project_data_path), ' end if') if self.mprj.rtarget: self.script.Append( ' if file "%s" exists then' % (self.mprj.rproject_file_path), ' delete file "%s"' % (self.mprj.rproject_file_path), ' end if', ' if folder "%s" exists then' % (self.mprj.rproject_data_path), ' delete folder "%s"' % (self.mprj.rproject_data_path), ' end if') self.script.Append( ' end timeout', ' end tell') self.script.Append( 'end Clean', '') def PostBuildScript(self): self.script.Append('on DoPostBuild()') ## we must split the buffer up and get the newlines out self.script.Extend(string.split(mprj.post_build_script, '\n')) self.script.Append('end DoPostBuild') def DefineResourceProject(self): ## assemble path lists mprj = self.mprj cwap = CWAccessPath() if mprj.always_full_search: cwap.AddSetting("Always Full Search", "true") else: cwap.AddSetting("Always Full Search", "false") cwap.AddSetting("Convert Paths", "true") for (name, recursive, origin) in mprj.rsystem_paths: cwap.AddSystemPath(name, recursive, origin) for (name, recursive, origin) in mprj.ruser_paths: cwap.AddUserPath(name, recursive, origin) self.script.Append( 'on ResourceProject()', 'tell application %s' % (mprj.ide_path), 'Launch', 'try', 'open "%s"' % (mprj.rproject_file_path), 'on error number errnum', 'if errnum is -43 then -- Project not found', 'Create Project "%s"' % (mprj.rproject_file_path), 'end if', 'end try', '--set preferences', 'set preferences of panel "Target Settings" to '\ '{Linker:"Win32 x86 Linker",'\ 'Target Name:"%s",'\ 'Output Directory Path:"%s",'\ 'Output Directory Origin:project relative}' % ( mprj.rtarget, mprj.output_dir), 'set preferences of panel "C/C++ Compiler" to '\ '{Prefix File:"ansi_prefix.win32.h"}', 'set preferences of panel "x86 Project" to '\ '{Project Type:shared library, File Name:"%s"}' % (mprj.rtarget), 'set preferences of panel "x86 Linker" to {Entry Point Usage:none}', 'Set Preferences of panel "Access Paths" to {User Paths:{},System Paths:{},Always Full Search:false}', 'set preferences of panel "Access Paths" to %s' % (cwap.String()), 'set preferences of panel "WinRC Compiler" to '\ '{Prefix File:"ResourcePrefix.h"}', 'try', 'Add Files {"%s"}' % (mprj.rfile), 'on error', 'end try', 'set cwErrorList to Make Project with ExternalEditor', 'set myerrors to my ExtractCWErrors(cwErrorList)', 'Close Project', 'end tell', 'return myerrors', 'end ResourceProject') def ExtractCWErrors(self): """Emits a AppleScript function useful in extracting errors from CodeWarrior, so they may be returned as a string.""" self.script.Append( '(*', ' * This subroutine extracts the contents of CodeWarrior\'s', ' * Error and Warnings', ' * window, and returns them as a text string', ' *)', 'on ExtractCWErrors(errorList)', ' set logText to ""', ' -- Parse each error and convert to string', ' set numWarnings to 0', ' repeat with errInfo in errorList', ' tell application %s' % (self.mprj.ide_path), ' set errType to messagekind of errInfo', ' set errText to message of errInfo as string', ' set errTypeString to ">>unknown error type<< "', ' if errType is compiler error then', ' set errTypeString to "Compiler Error "', ' set errFile to file of errInfo as string', ' set errLine to lineNumber of errInfo as string', ' set logText to logText & errTypeString & "in " & errFile & " (line " & errLine & "): " & errText & return', ' else if errType is compiler warning then', ' numWarnings = numWarnings + 1', ' else if errType is linker error then', ' set errTypeString to "Linker Error "', ' set logText to logText & errTypeString & ": " & errText & return', ' else if errType is linker warning then', ' set errTypeString to "Linker Warning "', ' set logText to logText & errTypeString & ": " & errText & return', ' else', ' set logText to logText & errTypeString & ": " & errText & return', ' end if', ' end tell', ' end repeat', ' if (numWarnings > 0)', ' if logText is not ""', ' set logText to logText & "(" & numWarnings & ") Compiler Warnings"', ' end if', ' end if', ' return logText', 'end ExtractCWErrors')## This is ugly, output generators should not be allowed## to change stuff in the project settings!def fix_pncrt(project): """This is a fix for many of the Umakefil/*.pcf files which add this library in the wrong place, or incorrectly. We take care to remove it here, then re-add it if necessary.""" project.RemoveLibraries("pncrt.lib") project.RemoveLibraries("pncrtd.lib") if not project.IsDefined('HELIX_CONFIG_RN_CRT'): return project.RemoveSystemLibraries("pncrt.lib") project.RemoveSystemLibraries("pncrtd.lib") ## we remove pncrt entirely with "noruntime" option if project.BuildOption("noruntime"): return if project.BuildOption("debug"): project.AddLibraries("pncrtd.lib") else: project.AddLibraries("pncrt.lib")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) ## Pretend like everything went well return None
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -