📄 bif.py
字号:
# # ***** BEGIN LICENSE BLOCK *****# Source last modified: $Id: bif.py,v 1.28 2004/10/20 21:07:21 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 *****# """Functions and classes used in *.bif file loading, compiling, errorchecking, and parsing."""import osimport sysimport stringimport statimport cPicklefrom module import CreateModuleimport outmsgimport errimport fnmatchimport sysinfoimport typesimport moduleimport datelibimport reimport timebif_shadows=[]BIFParser=Nonehave_expat=0def AddShadow(file): bif_shadows.append(file)## load a BIF file, returning the bif_data and saving the compiled## version to a compiled BIF file (BIC file)def load_bif(filename, branchlist = None, include_shadows=1): bif_data = BIFData() global BIFParser global have_expat if not BIFParser: try: install_new_bif_parser() have_expat=1 except ImportError: print "Unable to find expat module, using old BIF parser" install_old_bif_parser() try: BIFParser(filename, bif_data, branchlist) except err.error, e: if have_expat: print "WARNING: this bif file fails to parse with new BIF parser" print e install_old_bif_parser() try: BIFParser(filename, bif_data, branchlist) finally: install_new_bif_parser() else: raise orig_modules = bif_data.module_hash.keys() if include_shadows: id=bif_data.build_id for shadow in bif_shadows: for mod in bif_data.module_hash.values(): mod.inherited=1 if not branchlist: import branchlist branchlist=branchlist.BranchList() shadow_file_name=branchlist.file(shadow) if not shadow_file_name: if include_shadows > 1: continue e=err.Error() e.Set("Unable to find shadow BIF file \"%s\"." % shadow) raise err.error, e BIFParser(shadow_file_name, bif_data, branchlist) tmp={} for m in orig_modules: tmp[m]=1 for m in bif_data.module_hash.keys(): if not tmp.has_key(m): bif_data.module_hash[m].set_attribute("from_shadow_only") bif_data.build_id=id return bif_data## load a BIFData class either from the compiled BIC file or from## the BIF filedef load_bif_data(filename, branchlist = None, shadow=1): bif_data = load_bif(filename, branchlist, shadow) return bif_dataclass Default: def __init__(self, profile=None, target=None, options=None, system_id = None): self.profile=profile self.target=target self.options=options self.system_id=system_id def write(self): ret=" <default" if self.target: ret = ret +' target="%s"' % self.target if self.profile: ret = ret +' profile="%s"' % self.profile if self.options != None: ret = ret +' options="%s"' % self.options if self.system_id: ret = ret +' for="%s"' % self.system_id return ret+"/>" ## data structure for information contained in BIF filesclass BIFData: def __init__(self): self.build_id = '' self.default_cvs_tag = '' self.default_cvs_tag_type = 'branch' self.default_cvs_root = '' self.default_cvs_date = '' self.module_hash = {} self.defaults = [] self.default_target = '' self.default_profile = '' self.default_options = '' self.bif_version = 100 self.expires = '2005-01-01' def set_build_id(self, build_id): self.build_id = build_id def get_expiration_ticks(self): return datelib.date_to_ticks(self.expires+" 00:00:00") def set_default_cvs_tag(self, default_cvs_tag): self.default_cvs_tag = default_cvs_tag def set_default_cvs_tag_type(self, default_cvs_tag_type): self.default_cvs_tag_type = default_cvs_tag_type def set_default_cvs_root(self, default_cvs_root): self.default_cvs_root = default_cvs_root def add_module(self, module): if self.module_hash.has_key(module.id): mod = self.module_hash[module.id] if not mod.__dict__.has_key("inherited"): e = err.Error() e.Set("Two or more modules have id=\"%s\" in the bif file." % ( module.id)) raise err.error, e self.module_hash[module.id] = module def write(self, all=0): ret = [ "<?xml version=\"1.0\" ?>", "<!-- $Id: -->", '<build id="%s"' % self.build_id, ] ## For backwards compatibility, expires and version must ## be excluded if they have their default values. ## (In fact, no attribute other than id may exist in the ## <build> tag for old versions of the build system.) if self.bif_version != 100: ret[-1]=ret[-1] + ' version="%d.%02d"' % ( self.bif_version/100, self.bif_version % 100 ) if self.expires != '2005-01-01': ret[-1]=ret[-1] + ' expires="%s"' % self.expires ret[-1]=ret[-1]+">" ret.append(" <!-- defaults --> ") addnl=0 if self.default_cvs_root: ret.append(' <cvs root="%s"/>' % self.default_cvs_root) addnl=1 if self.default_cvs_tag: ret.append(' <cvs %s="%s"/>' % (self.default_cvs_tag_type, self.default_cvs_tag)) addnl=1 if self.default_cvs_date: ret.append(' <cvs date="%s"/>' % (self.default_cvs_date)) addnl=1 if addnl: ret.append("") for d in self.defaults: ret.append(d.write()) ret.append(" <targets>") ids = self.module_hash.keys() ids.sort() for id in ids: m=self.module_hash[id] if (all or not m.attributes.get("from_shadow_only") or m.attributes.get("sdk_depend_only")): ret.append(self.module_hash[id].write(self)) ret.append(" </targets>") ret.append("</build>") return string.join(ret,"\n") + "\n" ## the BIF file XML ParserTAG_build = "build"TAG_cvstag = "cvstag"TAG_default = "default"TAG_cvs = "cvs"TAG_targets = "targets"TAG_module = "module"TAG_description = "description"TAG_attribute = "attribute"TAG_includeplatforms = "includeplatforms"TAG_excludeplatforms = "excludeplatforms"TAG_includeprofiles = "includeprofiles"TAG_excludeprofiles = "excludeprofiles"TAG_dependlist = "dependlist"TAG_source_dependlist = "source_dependlist"TAG_checkin_dependlist = "checkin_dependlist"TAG_halt = "halt"TAG_sdk = "sdk"TAG_errmsg = "checkout_error_message"TAG_defines = "defines"TAG_ifdef = "ifdef"TAG_ifndef = "ifndef"TAG_umake_includefiles = "umake_includefiles"TAG_version = "version"class BIFParserFunctions: def __init__(self, filename, bif_data = None, branchlist = None): if not bif_data: bif_data = BIFData() self.bif_data = bif_data self.branchlist = branchlist ## intermediate self.module = None ## parsing state stack self.tag_stack = [] self.current_tag = None self.last_module="" self.linenum = 0 self.filename=filename ticks=self.bif_data.get_expiration_ticks() tmp = ( self.bif_data.bif_version, self.bif_data.build_id, self.bif_data.expires, self.bif_data.default_cvs_tag, self.bif_data.default_cvs_tag_type, self.bif_data.default_cvs_root, self.bif_data.default_cvs_date ) ## Historical compatibility if self.bif_data.bif_version >= 203: self.bif_data.default_cvs_tag = '' self.bif_data.default_cvs_tag_type = 'branch' self.bif_data.default_cvs_root = '' self.bif_data.default_cvs_date = '' self.bif_data.expires = '2005-01-01' self.bif_data.bif_version = 100 self.parse_bif(filename) if tmp[1]: t2=self.bif_data.get_expiration_ticks() if t2 < ticks: self.warning("Inherited file expires before this file!!") (self.bif_data.bif_version, self.bif_data.build_id, self.bif_data.expires ) = tmp[:3] if self.bif_data.bif_version >= 203: ( self.bif_data.default_cvs_tag, self.bif_data.default_cvs_tag_type, self.bif_data.default_cvs_root, self.bif_data.default_cvs_date ) = tmp[3:] ## Delete the 'inherited' flag for mod in self.bif_data.module_hash.values(): try: del mod.inherited except AttributeError: pass def parse_bif(self, filename): fil = open(filename, "r") while 1: line = fil.readline() if not line: break self.linenum = self.linenum + 1 self.feed(line) def location(self): return "%s:%d" % (self.filename, self.lineno) def error(self, text): e = err.Error() e.Set("bif parser(%s): %s" % (self.location(), text)) raise err.error, e def warning(self, text): outmsg.send("[WARNING] bif parser(%s): %s" % (self.location(), text)) def fix_data_cb(self): self.__data_cb=getattr(self, "handle_data_"+self.current_tag, self.handle_data_default) def push_tag(self, tag): #print "%d: <%s>" % (self.linenum, tag) self.tag_stack.append(tag) self.current_tag = tag self.fix_data_cb() def pop_tag(self, tag): #print "%d: </%s>" % (self.linenum, tag) if len(self.tag_stack) == 0: self.error("pop xml tag with empty stack") if self.tag_stack[-1] != tag: self.error("pop xml tag=\"%s\" but expected tag=\"%s\"" % ( tag, self.tag_stack[-1])) self.tag_stack = self.tag_stack[:-1] if len(self.tag_stack): self.current_tag = self.tag_stack[-1] else: self.current_tag="" self.fix_data_cb() def handle_data_description(self, data): self.module.set_description(data) def handle_data_includeplatforms(self, data): self.module.set_platform_include_list(data) def handle_data_excludeplatforms(self, data): self.module.set_platform_exclude_list(data) def handle_data_includeprofiles(self, data): self.module.set_profile_include_list(data) def handle_data_excludeprofiles(self, data): self.module.set_profile_exclude_list(data) def handle_data_ifdef(self, data): self.module.set_define_include_list(data) def handle_data_ifndef(self, data): self.module.set_define_exclude_list(data) def handle_data_dependlist(self, data):
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -