def STATIC_LIBRARY(name, *args): """ create one StaticLibrary object Args: name : the name of .a file args : the variable number of SyntagTag.TagSources, SyntaxTag.TagLibs object """ # to check name of result file if not Function.CheckName(name): raise BrocArgumentIllegalError( "name(%s) in STATIC_LIBRARY is illegal" % name) tag_libs = SyntaxTag.TagLibs() tag_sources = SyntaxTag.TagSources() for arg in args: if isinstance(arg, SyntaxTag.TagSources): tag_sources.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagLibs): tag_libs.AddSVs(arg.V()) else: raise BrocArgumentIllegalError("arguments (%s) in STATIC_LIBRARY is illegal" % \ type(arg)) env = Environment.GetCurrent() lib = Target.StaticLibrary(name, env, tag_sources, tag_libs) if len(tag_sources.V()): if not env.AppendTarget(lib): raise BrocArgumentIllegalError( "STATIC_LIBRARY(%s) exists already" % name) else: # .a file has been built already, just copy it from code directory to output directory lib.DoCopy()
def PROTO_LIBRARY(name, files, *args): """ compile proto files into a static library .a when parse proto files failed, raise Exception BrocProtoError Args: name: the name of proto static library files: a string sperearated by blank character, representing the relative path of proto files args: a variable number of SyntaxTag.TagProtoFlags, SyntaxTag.TagInclude, SyntaxTag.CppFlags, SyntaxTag.CXXFlags, SyntaxTag.TagLibs """ # check validity of name if not Function.CheckName(name): raise BrocArgumentIllegalError("name(%s) PROTO_LIBRARY is illegal" % name) # check proto file whether belongs to module proto_files = files.split() env = Environment.GetCurrent() for _file in proto_files: abs_path = os.path.normpath(os.path.join(env.BrocDir(), _file)) if not env.ModulePath() in abs_path: raise NotInSelfModuleError(abs_path, env.ModulePath()) # to check args tag_protoflags = SyntaxTag.TagProtoFlags() tag_cppflags = SyntaxTag.TagCppFlags() tag_cxxflags = SyntaxTag.TagCxxFlags() tag_libs = SyntaxTag.TagLibs() tag_include = SyntaxTag.TagInclude() for arg in args: if isinstance(arg, SyntaxTag.TagProtoFlags): tag_protoflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagCppFlags): tag_cppflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagCxxFlags): tag_cxxflags.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagLibs): tag_libs.AddSVs(arg.V()) elif isinstance(arg, SyntaxTag.TagInclude): tag_include.AddSVs(arg.V()) else: raise BrocArgumentIllegalError("don't support tag(%s) in PROTO_LIBRARY in %s" \ % (str(arg), env.BrocPath())) include = set() source = set() for f in proto_files: root, _ = os.path.splitext(f) result_file = os.path.join(os.path.join('broc_out', env.ModuleCVSPath()), \ "%s.pb.cc" % root) include.add(os.path.dirname(result_file)) if os.path.dirname(f): tag_include.AddV( os.path.join(env.ModuleCVSPath(), os.path.dirname(f))) source.add(result_file) protolib = Target.ProtoLibrary(env, files, tag_include, tag_protoflags) ret, msg = protolib.PreAction() if not ret: raise BrocProtoError(msg) tag_include.AddSVs(include) broc_out = os.path.join("broc_out", env.BrocCVSDir()) if broc_out not in tag_include.V(): tag_include.AddV(os.path.join("broc_out", env.BrocCVSDir())) tag_sources = Sources(" ".join(list(source)), tag_include, tag_cppflags, tag_cxxflags) if not env.AppendTarget( Target.StaticLibrary(name, env, tag_sources, tag_libs)): raise BrocArgumentIllegalError( "PROTO_LIBRARY(%s) name exists already" % name) return protolib