def Include(*ss): """ set the local file search path Args: ss : a variable number of string objects ss may contain multiple string objects, each object can contain multiple paths 1. if path does not beneath module, in other words, if user want to specified other modules' path, should start with $WORKSPACE, 2. if path couldn't be founed in module itself and path does not start with $WORKSPACE rasie NotInSelfModuleError 3. if path is output directory, it must start with 'broc_out/' for example: ss can be "./include ./include/foo", "$WORKSPACE/include", "broc_out/test/include" """ env = Environment.GetCurrent() broc_abs_dir = env.BrocDir() broc_cvs_dir = env.BrocCVSDir() tag = SyntaxTag.TagInclude() for s in ss: ps = string.split(s) for x in ps: if x.startswith("$WORKSPACE"): tag.AddSV(x.replace("$WORKSPACE/", "")) continue elif x.startswith('broc_out/') or os.path.isabs(x): tag.AddSV(x) continue elif x.startswith("$OUT_ROOT"): tag.AddSV(x.replace("$OUT_ROOT", 'broc_out')) continue else: _x = os.path.normpath(os.path.join(broc_abs_dir, x)) if env.ModulePath() not in _x: raise NotInSelfModuleError(_x, env.ModulePath()) else: tag.AddSV(os.path.normpath(os.path.join(broc_cvs_dir, x))) return tag
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