📄 umake_lib.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: umake_lib.py,v 1.31 2004/10/12 07:04:41 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 file contains common library functions, such as error output, andbase classes used by other parts of the Umake system. Only code commonto all Umake platforms should go here."""import osimport sysimport stringimport typesimport errimport bldregimport reimport statimport sysinfoDEBUG=0def fatal(text): """Raise a fatal exception.""" e = err.Error() e.Set(text) raise err.error, edef warning(text): """Print out a warning and exit.""" print "UMAKE Warning: %s" % (text)def namespace_modified(text): """Print out a namespace modified message.""" print "UMAKE Namespace Modified: %s" % (text)def debug(text): """Print out a debug message.""" if DEBUG: print textdef listify(stuff): """Takes a string, tuple, list, or lists of sublists, and makes a new, single list out of all the strings in them.""" ## input is string if type(stuff) == types.StringType: return [stuff] try: if type(stuff) == types.UnicodeType: return [stuff] except AttributeError: pass ## has to be a list or tuple if type(stuff) != types.ListType and type(stuff) != types.TupleType: return [] list = [] for item in stuff: list.extend(listify(item)) return listdef ci_find_file(find_filename): """Searches the current directory for filename case-insesitive on case-sensitive operating systems. Returns None if it cannot find the file. There's a bug here: while we search for the filename in a case-insensitive way, we don't do the same for the directory.""" if os.path.exists(find_filename): return find_filename (path, basename) = os.path.split(find_filename) ## os.listdir cannot take a blank path as the current dir, list_path = path or os.curdir list_path = ci_find_file(list_path) if not list_path: return None ## Ugly hack for OS9 if sysinfo.host_type == "mac": import archive basename=archive.mac_name_mangler(basename) p=os.path.join(list_path, basename) if os.path.exists(p): return p find_filename = string.lower(basename) for filename in os.listdir(list_path): if find_filename == string.lower(filename): return os.path.join(list_path, filename) return Nonedef fix_path_mac(path): """Macintosh implementation of fix_path() seperated out for clarity. This is called by fix_path().""" if not path or not len(path): return "" if ':' in path and '/' not in path and '\\' not in path: ## The path is already a mac path! return path path = string.replace(path, "/", ":") mac_path = "" last_backdir = 0 last_curdir = 0 # no directory info defaults to current dir if path[0] == ":": import macpath mac_path=string.split(macpath.normpath(os.getcwd()),":")[0] elif path[0] != ".": mac_path = ":" i = 0 while i < len(path): # translate current directory if path[i:i+2] == ".:": if not last_curdir and not last_backdir: mac_path = mac_path + ":" last_curdir = 1 i = i + 2 continue # translate stepping back a directory if path[i:i+3] == "..:": if last_backdir or last_curdir: mac_path = mac_path + ":" else: mac_path = mac_path + "::" last_backdir = 1 i = i + 3 continue # append to mac_path mac_path = mac_path + path[i] i = i + 1 last_curdir = 0 last_backdir = 0 return mac_path def fix_path(path): """Takes a path which is in either POSIX or native format, and converts it to a native path on the running system.""" if not path or not len(path): return "" if sysinfo.host_type == "mac": # print "fix_path_mac(%s) = > %s\n" % (path, fix_path_mac(path)) return fix_path_mac(path) path = string.replace(path, "/", os.sep) return pathdef SetupPlatform(platform): """Twek some settings in the Platform object, and run the linker class's set_type() method. The .c and .cpp build rules are generated here.""" ## the C & C++ compiler build rules are handled outside the ## platform.build_rules hash table, so we set them here since ## they may have been replaced in the Umakefil/*.pcf file import umake try: platform.build_rules[".cpp"] = umake.BuildRule( ".cpp", ".%s" % (platform.object_suffix), platform.cxx) except AttributeError: # I hate these - hubbe pass try: platform.build_rules[".c"] = umake.BuildRule( ".c", ".%s" % (platform.object_suffix), platform.cc) except AttributeError: # I hate these - hubbe pass ## set the set_type function in the linker class; the project's target ## type MUST be set before this is done, and is only required for the ## old linker classes, which is why we don't do it for Linker2 derived ## linkers if not hasattr(platform.link, "linker2"): fun = None try: fun = platform.link.set_type except AttributeError: pass if fun: fun()class SourceFile: """Given a the platform object, a source path, and a object output directory form a number of useful intermediate paths helping to deal with the source file.""" def __init__(self, platform, path, output_dir): self.path = path (base, self.ext) = os.path.splitext(self.path) base = os.path.normpath(base) if os.path.isabs(base): base = string.replace(base,"\\","_") base = string.replace(base,":","_") base = string.replace(base,"/","_") else: ## Trim off any ../ from the beginning of the path base = string.replace(base,"\\","/") tmp = string.split(base, "/") x = 0 while len(tmp) > x + 1: if tmp[x] in [ os.curdir, os.pardir ]: x = x + 1 else: break if x: tmp = [ "par%d" % x ] + tmp[x:] base = string.join(tmp,os.sep) rules=platform.build_rules self.build_rule = rules.get(path, rules.get(os.path.basename(path), rules.get(self.ext, None))) if not self.build_rule: fatal('no build rule for extention="%s"' % (self.ext)) self.obj_path = "%s%s" % (base, self.build_rule.target_suffix) if self.build_rule.output_dir != None: self.obj_path = os.path.join(self.build_rule.output_dir, self.obj_path) elif output_dir: self.obj_path = os.path.join(output_dir, self.obj_path) ## file = a path relative to the source root## returns the module namemodule_from_file_cache = {}def module_from_file(file): if module_from_file_cache.has_key(file): return module_from_file_cache[file] module = file parts = [] root = [ ":", ".", "", "..","/","\\"] while 1: tmp = os.path.split(module) parts.append(tmp[1]) if tmp[0] in root: break root.append(tmp[0]) module = tmp[0] parts.reverse() mparts = [] while parts: module=string.join(parts, "/") id=bldreg.get("bifmodule_path_to_id",string.lower(module),None) if id: module_from_file_cache[file]=id return id parts=parts[:-1] return None## file = a path relative to the current directory## returns the module namedef module_from_file_rel(project, file): if os.path.isabs(file): return None module = file parts = [] srcroot=os.path.normpath(project.src_root_path) while not module in [ ":", ".", "", ".."]: #print "DWIM: %s (%s)" % (repr(module), repr(srcroot)) tmp = os.path.split(module) parts.append(tmp[1]) if tmp[0] == srcroot: parts.reverse() return module_from_file(string.join(parts,os.sep)) module = tmp[0] return Nonedef GetModuleDependencies(project, modname = None): try: return project.__recursive_dependency_check_done__ except: if modname == None: module_directory = project.module_directory() modname = module_from_file(module_directory) if not modname: return {} done = { modname:1 } bifdeps = [ modname ] for d in bifdeps: for n in bldreg.get("bifmodule_deplist",string.lower(d),[]): n = string.lower(n) if not done.has_key(n): bifdeps.append(n) done[n]=1 project.__recursive_dependency_check_done__ = done #print "dependencies %s => %s" % (repr(modname), repr(done)) return done# Check each path in "paths" to make sure that they come from# modules which are included in our BIF dependency list.def CheckModuleDependencies_rel(platform, project, type, paths): # I feel nice, so we check aginainst the recursive tree of # dependencies rather than against just the dependencies in this # module... /Hubbe module_directory = project.module_directory() modname = module_from_file(module_directory) if not modname: return done = GetModuleDependencies(project, modname) warnings_printed = globals().get("__umake_warnings_printed_cache__",{}) for path in paths:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -