📄 umake_ascript.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: umake_ascript.py,v 1.8 2004/07/07 22:00:04 hubbe Exp $# # Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.# # The contents of this file, and the files included with this file,# are subject to the current version of the RealNetworks Public# Source License (the "RPSL") available at# http://www.helixcommunity.org/content/rpsl unless you have licensed# the file under the current version of the RealNetworks Community# Source License (the "RCSL") available at# http://www.helixcommunity.org/content/rcsl, in which case the RCSL# will apply. You may also obtain the license terms directly from# RealNetworks. You may not use this file except in compliance with# the RPSL or, if you have a valid RCSL with RealNetworks applicable# to this file, the RCSL. Please see the applicable RPSL or RCSL for# the rights, obligations and limitations governing use of the# contents of the file.# # Alternatively, the contents of this file may be used under the# terms of the GNU General Public License Version 2 or later (the# "GPL") in which case the provisions of the GPL are applicable# instead of those above. If you wish to allow use of your version of# this file only under the terms of the GPL, and not to allow others# to use your version of this file under the terms of either the RPSL# or RCSL, indicate your decision by deleting the provisions above# and replace them with the notice and other provisions required by# the GPL. If you do not delete the provisions above, a recipient may# use your version of this file under the terms of any one of the# RPSL, the RCSL or the GPL.# # This file is part of the Helix DNA Technology. RealNetworks is the# developer of the Original Code and owns the copyrights in the# portions it created.# # This file, and the files included with this file, is distributed# and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY# KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS# ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET# ENJOYMENT OR NON-INFRINGEMENT.# # Technology Compatibility Kit Test Suite(s) Location:# http://www.helixcommunity.org/content/tck# # Contributor(s):# # ***** END LICENSE BLOCK *****# """This is the Mactinosh/AppleScript/CodeWarrior back end for Umake. Itgenerates a AppleScript file which, when run, tries its best to emulatea standard Makefile. It uses AppleScript to generate a CodeWarrior project,and also emits copy commands (using the AppleScript extentions in AkauSweets)to copy the targets once built."""import osimport sysimport stringimport reimport timeimport typesimport posixpathimport macfsimport ascriptimport umake_libimport macpathdef condense_mac_path(_path): """Remove skipped directories from a macintosh path, because two path seperators in a row means to backstep in Macintosh path speak.""" plist = string.split(_path, ":") path_list = [] for pc in plist: if pc == "": path_list = path_list[:-1] else: path_list.append(pc) return string.join(path_list, ":")def extract_ascw_path(_as_path, project): """extract_ascw_path takes a path string in AppleScript Codewarrior form and extracts the data from it, returning a 3-tuple of strings: Input String: '{name:":Win32-x86 Support:", recursive:true, origin:shell relative}' Returns Tuple: (":Win32-x86 Support:", "true", "shell relative")""" _as_path = string.strip(_as_path) if len(_as_path) == 0: umake_lib.fatal("extract_ascw_path() called with empty path") if _as_path[0] != "{" or _as_path[-1] != "}": umake_lib.fatal( "extract_ascw_path() called with invalid path=\"%s\"" % (_as_path)) _as_path = _as_path[1:-1] list = string.split(_as_path, ",") name = "" recursive = "" origin = "" for item in list: i = string.find(item, ":") key = string.lower(string.strip(item[:i])) value = string.strip(item[i+1:]) if key == "name": name = value[1:-1] if name[:7] == "SRCROOT": name = os.path.join(project.src_root_path, name[7:]) elif key == "recursive": recursive = value elif key == "origin": origin = value else: umake_lib.fatal( "extract_ascw_path: unhandled field=\"%s\"" % (key)) return (name, recursive, origin)def ProjectToMacCWProjectData(platform, project): """Takes a Platform and Project class, defined in umake.py, and creates a MacCWProjectData class from them. The MacCWProjectData class is then fed to the CodeWarrior AppleScript generator. Data from the Project and Platform classes are munged in various ways in this function. There are many "make it work" hacks here.""" mprj = MacCWProjectData() mprj.platform = platform mprj.project = project mprj.target_name = project.target_name mprj.target_type = project.target_type mprj.define_list = project.defines[:] mprj.prefix_file_include_list = project.prefix_file_include_list[:] ## setup paths/file names mprj.project_file = "%s.prj" % (mprj.target_name) mprj.project_file_path = os.path.join(os.getcwd(), mprj.project_file) ## project data foldername/folder path mprj.project_data = "%s Data" % (mprj.target_name) ## prefix file filename/path mprj.prefix_file = "%s_prefix.h" % (mprj.target_name) mprj.prefix_file_path = mprj.prefix_file mprj.rprefix_file = "r%s_prefix.r" % (mprj.target_name) mprj.rprefix_file_path = mprj.rprefix_file ## resource targets if project.with_resource_flag: mprj.rtarget = "%s.%s" % ( project.resource_target, platform.resource_dll_suffix) mprj.rfile = project.resourcefile ## resource project filename/path mprj.rproject_file = "r%s.prj" % (mprj.target_name) mprj.rproject_file_path = os.path.join(os.getcwd(), mprj.rproject_file) ## resource project data foldername/folder path mprj.rproject_data = "r%s Data" % (mprj.target_name) ## output foldername/folder path mprj.output_dir = project.output_dir mprj.output_dir_path = condense_mac_path( os.path.join(os.getcwd(), mprj.output_dir)) ## target dir foldername/folder path mprj.target_dir = project.target_dir mprj.target_dir_path = condense_mac_path( os.path.join(os.getcwd(), mprj.target_dir)) ## copy over the "preferences" nested hash from the project for (panel, pref) in project.preferences.items(): ## skip copying some of the panels which are handled ## seperately if panel == "Access Paths": for (key, value) in pref.items(): key = string.lower(key) if key == "always full search": mprj.always_full_search = (value == "true") try: temp = mprj.preferences[panel] except KeyError: temp = mprj.preferences[panel] = {} for (pref_key, pref_value) in pref.items(): temp[pref_key] = pref_value ## includes are processed at the end of this, but they are ## accumeulated here first include_path_list = [] ## create soruce_list from project.sources, adding the source ## path (if any) to the user access path list mprj.source_list = [] for source in project.sources: source_path, source_name = os.path.split(source) mprj.source_list.append(source_name) if source_path and source_path not in include_path_list: include_path_list.append(source_path) ## add libraries to sources ## we have to add the libraries to mprj.source_list by splitting ## any path away (if there is a path) and adding it to the includes ## list, which ends up in the "Access Paths->User Paths" panel library_list = project.libraries + project.libraries2 + \ project.local_libs + project.dynamic_libraries + \ project.sys_libraries ## XXX: don't include the module libraries for static libraries ## this is a hack; normally, we don't link any libraries into ## static libs; on the Macintosh, dynamic library links to the ## static library are inherited by whatever program or shared ## library links in the static lib, and programmers have used ## this feature in our code base to avoid listing all the ## libraries programs/dll's link to in their Makefiles... -JMP if mprj.target_type != "lib": library_list = project.module_libs + library_list for library in library_list: lib_path, lib_name = os.path.split(library) ## only add to the weak link list if the library was added if lib_name in project.weak_link_list: mprj.weak_link_list.append(lib_name) if lib_name not in mprj.source_list: mprj.source_list.append(lib_name) if lib_path and lib_path not in include_path_list: include_path_list.append(lib_path) ## Access Paths (System Paths/User Paths) for path in platform.system_paths + project.system_paths: mprj.system_paths.append(extract_ascw_path(path,project)) for path in platform.user_paths: mprj.user_paths.append(extract_ascw_path(path,project)) ## include this for the path to the XRS(resource) dll ## XXX: this should be moved -JMP mprj.user_paths.append( (mprj.output_dir, "false", "project relative") ) ## mix in source/lib/project.includes here ## drop non-unique paths temp_list = project.includes + include_path_list include_path_list = [] for include in temp_list: if include not in include_path_list: include_path_list.append(include) for include in include_path_list: if include[-1] != ":": include = "%s:" % (include) mprj.user_paths.append( (include, "false", "project relative") ) ## Resource Access Paths for path in platform.rsystem_paths: mprj.rsystem_paths.append(extract_ascw_path(path,project)) for path in platform.ruser_paths: mprj.ruser_paths.append(extract_ascw_path(path,project)) for include in project.resourceincludes: if include[-1] != ":": include = "%s:" % (include) if os.path.isdir(include): mprj.ruser_paths.append( (include, "false", "project relative") ) else: umake_lib.warning( "dropping non-existant include path=\"%s\"" % (include)) ## export file mprj.export_file = "" if len(project.exported_func): mprj.export_file = "%s.exp" % (mprj.target_name) mprj.export_list = project.exported_func if mprj.export_file not in mprj.source_list: mprj.source_list.append(mprj.export_file) ## customize the "PPC Project", "PPC PEF" panel, setting ## target output and type ppc_project = mprj.preferences["PPC Project"] ppc_pef = mprj.preferences["PPC PEF"] ## warnings if ppc_project["Project Type"] != "xxxProjType": umake_lib.warning('panel="Project Type" modified to="%s"' % ( ppc_project["Project Type"])) if ppc_project["File Name"] != "xxxFileName": umake_lib.warning('panel="File Name" modified to="%s"' % ( ppc_project["File Name"])) mprj.output_name = ppc_project["File Name"][1:-1] else: mprj.output_name = project.OutputName() if ppc_project["File Type"] != "xxxFileType": umake_lib.warning('panel="File Type" modified to="%s"' % ( ppc_project["File Type"])) if ppc_pef["Fragment Name"] != "xxxFragmentName": umake_lib.warning('panel="Fragment Name" modified to="%s"' % ( ppc_pef["Fragment Name"])) ## set target name ppc_project["File Name"] = '"%s"' % (mprj.output_name) ppc_pef["Fragment Name"] = ppc_project["File Name"] ## targe type/output file type if mprj.target_type == "lib": ppc_project["Project Type"] = "library" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"????"' elif mprj.target_type == "exe": ppc_project["Project Type"] = "standard application" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"APPL"' elif mprj.target_type == "dll": ppc_project["Project Type"] = "shared library" ## only set the filetype to 'shlb' if it has not been specified if ppc_project["File Type"] == "xxxFileType": ppc_project["File Type"] = '"shlb"' ## tweak the PPC Linker settings ppc_linker = mprj.preferences["PPC Linker"] if mprj.target_type == "lib" or mprj.target_type == "dll": if not ppc_linker.has_key("Initialization Name"): ppc_linker["Initialization Name"] = '"__initialize"' if not ppc_linker.has_key("Termination Name"): ppc_linker["Termination Name"] = '"__terminate"' if not ppc_linker.has_key("Main Name"): ppc_linker["Main Name"] = '""' elif mprj.target_type == "exe": if not ppc_linker.has_key("Initialization Name"): ppc_linker["Initialization Name"] = '""' if not ppc_linker.has_key("Termination Name"):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -