Beispiel #1
0
def ProtoFlags(*ss):
    """
    add the command options for protoc
    Args:
       ss : a variable number of string objects 
            ss may contain multiple string objects, each object can contain multiple options
            one option may be:
            1. option may contains $WORKSPACE, $OUT Macros value
    Returns:
        return a 
    """
    env = Environment.GetCurrent()
    tag = SyntaxTag.TagProtoFlags()
    for s in ss:
        ps = s.split()
        for x in ps:
            if "$WORKSPACE" in x:
                tag.AddSV(x.replace("$WORKSPACE/", ''))
            elif "$OUT" in x:
                tag.AddSV(x.replace("$OUT", env.OutputPath()))
            elif "$OUT_ROOT" in x:
                tag.AddSV(x.replace("$OUT_ROOT", env.OutputRoot()))
            else:
                tag.AddSV(x)
    return tag
Beispiel #2
0
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