Exemplo n.º 1
0
def UT_APPLICATION(name, sources, *args):
    """
    create one UT Application object
    Args:
        name : the name of target
        sources : the SyntaxTag.TagSource object
        args : a variable number of SyntaxTag.TagLinkLDFlags, SyntaxTag.TagLibs, SyntaxTag.TagUTArgs 
    """
    # to check name of result file
    if not Function.CheckName(name):
        raise BrocArgumentIllegalError("name(%s) in UT_APPLICATION is illegal")

    tag_links = SyntaxTag.TagLDFlags()
    tag_libs = SyntaxTag.TagLibs()
    tag_utargs = SyntaxTag.TagUTArgs()
    for arg in args:
        if isinstance(arg, SyntaxTag.TagLDFlags):
            tag_links.AddSVs(arg.V())
        elif isinstance(arg, SyntaxTag.TagLibs):
            tag_libs.AddSVs(arg.V())
        elif isinstance(arg, SyntaxTag.TagUTArgs):
            tag_utargs.AddSVs(arg.V())
        else:
            raise BrocArgumentIllegalError(
                "In UT_APPLICATION(%s) don't support %s" % (name, arg))
    env = Environment.GetCurrent()
    app = Target.UTApplication(name, env, sources, tag_links, tag_libs,
                               tag_utargs)
    if not env.AppendTarget(app):
        raise BrocArgumentIllegalError("UT_APPLICATION(%s) exists already" %
                                       name)
Exemplo n.º 2
0
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()
Exemplo n.º 3
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