コード例 #1
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_GLOB(self):
        """
        test Syntax.GLOB
        """
        #test case of one file
        files = Syntax.GLOB("./*.cpp")
        self.assertEqual(files, "hello.cpp")

        #test case of more files and those files must in the lexicographical order
        module = self._module
        Function.RunCommand("touch %s/hello1.h" % module.root_path, ignore_stderr_when_ok = True)
        Function.RunCommand("touch %s/hello2.h" % module.root_path, ignore_stderr_when_ok = True)
        Function.RunCommand("touch %s/hello3.h" % module.root_path, ignore_stderr_when_ok = True)
        Function.RunCommand("touch %s/hello10.h" % module.root_path, ignore_stderr_when_ok = True)
        files = Syntax.GLOB("./*.h")
        self.assertEqual(files, "hello.h hello1.h hello10.h hello2.h hello3.h")

        #test case of files not in self module
        Function.RunCommand("touch %s/../README" % module.root_path, ignore_stderr_when_ok = True)
        flag = False
        try:
            Syntax.GLOB("../README")
        except Syntax.NotInSelfModuleError as e:
            flag = True
        self.assertTrue(flag)

        #test case of no such files
        flag = False
        try:
            Syntax.GLOB("./just_test.cpp")
        except Syntax.BrocArgumentIllegalError as e:
            flag = True
        self.assertTrue(flag)
コード例 #2
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_ParseNameAndArgs(self):
        """
        test Syntax._ParseNameAndArgs
        """
        #only has name
        files, args = Syntax._ParseNameAndArgs("broc")
        self.assertEqual(files, ["broc"])
        self.assertEqual(args, [])

        #more args
        inctag = Syntax.Include("./ ./include")
        cpptag = Syntax.CppFlags("-DDEBUG", "-DBROC")
        ctag = Syntax.CFlags("-O2", "-O0")
        cxxtag = Syntax.CxxFlags("-Werror", "-Wall")
        files, args = Syntax._ParseNameAndArgs("./*.cpp", inctag)
        self.assertEqual(files, ["./*.cpp"])
        self.assertEqual(args, [inctag])
        files, args = Syntax._ParseNameAndArgs("./*.cpp", inctag, cpptag)
        self.assertEqual(files, ["./*.cpp"])
        self.assertEqual(args, [inctag, cpptag])
        files, args = Syntax._ParseNameAndArgs("./*.cpp", cpptag, ctag)
        self.assertEqual(files, ["./*.cpp"])
        self.assertEqual(args, [cpptag, ctag])
        files, args = Syntax._ParseNameAndArgs("./*.cpp", "./*.c", cxxtag, ctag)
        self.assertEqual(files, ["./*.cpp", "./*.c"])
        self.assertEqual(args, [cxxtag, ctag])
        files, args = Syntax._ParseNameAndArgs("./*.cpp", "./*.c", inctag, cpptag, cxxtag, ctag)
        self.assertEqual(files, ["./*.cpp", "./*.c"])
        self.assertEqual(args, [inctag, cpptag, cxxtag, ctag])
コード例 #3
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_Libs(self):
        """
        test Syntax.Libs
        """
        #one lib in arg
        tag = Syntax.Libs("$OUT_ROOT/baidu/broc/lib/libbroc.a")
        self.assertTrue("broc_out/baidu/broc/lib/libbroc.a" in tag.V())

        #more than one libs in args
        flag = True
        tag = Syntax.Libs("$OUT_ROOT/baidu/broc/lib/libbroc.a", \
                "$OUT_ROOT/protobuf/lib/libprotobuf.a", \
                "$OUT_ROOT/ccode/lib/libccode.a" \
                "$OUT_ROOT/dict/lib/libdict.a")
        lib_list = ["broc_out/baidu/broc/lib/libbroc.a", \
                "broc_out/protobuf/lib/libprotobuf.a", \
                "broc_out/ccode/lib/libccode.a" \
                "broc_out/dict/lib/libdict.a"]
        for lib in lib_list:
            if lib not in tag.V():
                flag = False

        self.assertTrue(flag)

        #arg not start with $OUT_ROOT
        flag = False
        try:
            tag = Syntax.Libs("baidu/broc/lib/libbroc.a")
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)
コード例 #4
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_INCLUDE(self):
        """
        test Syntax.INCLUDE
        """
        Environment.SetCurrent(self._env)
        # arg starts with $WORKSPACE
        Syntax.INCLUDE("$WORKSPACE/baidu/broc")
        self.assertTrue("baidu/broc" in self._env.IncludePaths().V())
        self.assertTrue("baidu/agile" not in self._env.IncludePaths().V())
        
        # arg starts with broc_out
        Syntax.INCLUDE("broc_out/baidu/broc")
        self.assertTrue("broc_out/baidu/broc" in self._env.IncludePaths().V())
        self.assertTrue("broc_out/baidu/agile" not in self._env.IncludePaths().V())

        # arg is abs path
        Syntax.INCLUDE("/opt/include")
        self.assertTrue("/opt/include" in self._env.IncludePaths().V())
        self.assertTrue("/home/include" not in self._env.IncludePaths().V())

        # arg in self module
        Syntax.INCLUDE("./include")
        incpath = os.path.normpath(os.path.join(self._module.workspace, \
                self._module.module_cvspath, "include"))
        self.assertTrue(incpath in self._env.IncludePaths().V())
コード例 #5
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_Include(self):
        """
        test Syntax.Include
        """
        Environment.SetCurrent(self._env)
        # arg starts with $WORKSPACE
        tag = Syntax.Include("$WORKSPACE/baidu/broc")
        self.assertTrue("baidu/broc" in tag.V())
        self.assertTrue("baidu/agile" not in tag.V())
        
        # arg starts with broc_out
        tag = Syntax.Include("broc_out/baidu/broc")
        self.assertTrue("broc_out/baidu/broc" in tag.V())
        self.assertTrue("broc_out/baidu/agile" not in tag.V())
        
        # arg is abs path
        tag = Syntax.Include("/opt/include")
        self.assertTrue("/opt/include" in tag.V())
        self.assertTrue("/home/include" not in tag.V())

        # arg in self module
        tag = Syntax.Include("./include")
#incpath = os.path.normpath(os.path.join(self._module.workspace, \
#                self._module.module_cvspath, "include"))
        incpath=os.path.join(self._module.module_cvspath, 'include')
        self.assertTrue(incpath in tag.V())
コード例 #6
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_PUBLISH(self):
        """
        test Syntax.PUBLISH
        """
        #src has one file
        Syntax.PUBLISH("conf/a.conf", "$OUT/conf")
        dst = os.path.join(self._env.OutputPath(), "conf")
        src = os.path.join(self._module.module_cvspath, "conf/a.conf")
        self.assertTrue("mkdir -p %s && cp -rf %s %s" % (dst, src, dst))
        
        #src has more files
        Syntax.PUBLISH("conf/a1.conf conf/a2.conf", "$OUT/conf")
        dst = os.path.join(self._env.OutputPath(), "conf")
        for s in "conf/a1.conf conf/a2.conf".split(' '):
            src = os.path.join(self._module.module_cvspath, s)
            self.assertTrue("mkdir -p %s && cp -rf %s %s" % (dst, src, dst))

        #out_dir doesn't start with $OUT
        flag = False
        try:
            Syntax.PUBLISH("conf/a3.conf", "conf")
        except Syntax.BrocArgumentIllegalError as e:
            flag = True
        self.assertTrue(flag)

        #src doesn't in self module
        flag = False
        try:
            Syntax.PUBLISH("../../conf/a3.conf", "$OUT/conf")
        except Syntax.NotInSelfModuleError as e:
            flag = True
        self.assertTrue(flag)
コード例 #7
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_CPPFLAGS(self):
        """
        test Syntax.CPPFLAGS
        """
        #test case of debug mode
        self._env._build_mode = 'debug'
        Syntax.CPPFLAGS("-g -Wall", "-g -O2")
        self.assertTrue("-g -Wall" in self._env._g_cppflags.V() \
                and "-g -O2" not in self._env._g_cppflags.V())

        #test case of muti CPPFLAGS
        Syntax.CPPFLAGS("-W -Wshadow", "-g -O2")
        Syntax.CPPFLAGS("-finline-functions", "-g -O2")
        self.assertTrue("-g -Wall" in self._env._g_cppflags.V() \
                and "-g -O2" not in self._env._g_cppflags.V())
        self.assertTrue("-W -Wshadow" in self._env._g_cppflags.V() \
                and "-g -O2" not in self._env._g_cppflags.V())
        self.assertTrue("-finline-functions" in self._env._g_cppflags.V() \
                and "-g -O2" not in self._env._g_cppflags.V())

        #reset g_cppflags
        self._env._g_cppflags = SyntaxTag.TagCPPFLAGS()

        #test case of release mode
        self._env._build_mode = 'release'
        Syntax.CPPFLAGS("-g -Wall", "-g -O2")
        self.assertTrue("-g -O2" in self._env._g_cppflags.V() \
                and "-g -Wall" not in self._env._g_cppflags.V())
コード例 #8
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_PROTO_LIBRARY(self):
        """
        test Syntax.PROTO_LIBRARY
        """
        #make a new proto file
        Function.RunCommand("touch %s/hello.proto" % self._module.root_path, \
                ignore_stderr_when_ok = True)
        #set local flags
        cpptags = Syntax.CppFlags("-DDEBUG_LOCAL", "-DRELEASE_LOCAL")
        cxxtags = Syntax.CxxFlags("-Wwrite-strings", "-Wswitch")
        incflag = Syntax.Include("")
        libflag = Syntax.Libs("$OUT_ROOT/baidu/broc/output/lib/libhello.a")

        now_dir = os.getcwd()
        os.chdir(self._module.workspace)
        protos = Syntax.PROTO_LIBRARY("hello", "*.proto", cpptags, cxxtags, incflag, libflag)
        proto_library = self._env.Targets()[0]
        src = proto_library.tag_sources.V()[0]
        proto_library.Action()
        os.chdir(now_dir)
        
        #check result
        proto_cmd = """mkdir -p broc_out/baidu/broc && protoc \
--cpp_out=broc_out/baidu/broc  -I=baidu/broc \
-I=. baidu/broc/*.proto\n"""
        self.assertEqual(' '.join(protos.__str__().split()), ' '.join(proto_cmd.split()))
        self.assertEqual(src.cppflags, ["-DDEBUG_LOCAL"])
        self.assertEqual(src.cxxflags, ["-Wwrite-strings"])
        self.assertEqual(src.includes, [".", "broc_out", 'baidu/broc', 
                u'broc_out/baidu/broc'])
        self.assertEqual(src.infile, "broc_out/baidu/broc/hello.pb.cc")
        self.assertEqual(proto_library.tag_libs.V(), \
                ["broc_out/baidu/broc/output/lib/libhello.a"])
コード例 #9
0
    def DoPlanish(self, download_flag=True):
        """
        choose one version from multiple version of module
        Args:
            download_flag : whether download the code of module, if it is set True download code, and vice versa
        Returns:
            return True if planish successfully, otherwise return False
        """
        self.logger.LevPrint('MSG', 'Analyzing dependency ...')
        # create dependent tree
        broc_loader = Syntax.BrocLoader()
        try:
            broc_loader.LoadBROC()
        except BaseException as err:
            self.logger.LevPrint('ERROR', '%s' % err)
            return False
        if len(broc_loader.LackBrocModules()) != 0:
            self.logger.LevPrint('ERROR',
                                 "Can't find BROC in following module(s):")
            for cvspath in broc_loader.LackBrocModules():
                self.logger.LevPrint('ERROR', "\t%s" % cvspath)
            return False
        # check graph has circles
        (ret, msg) = BrocTree.BrocTree().HasCircle()
        if ret:
            self.logger.LevPrint(
                "ERROR",
                "There is a circle in dependency graph\nCircle is [%s]" % msg,
                False)
            return False

        nodes = Syntax.BrocLoader().AllNodes()
        for k, nodes in nodes.iteritems():
            for node in nodes:
                # jump main module itself
                if node.module.is_main:
                    continue
                if node.module.module_cvspath not in self.planished_nodes:
                    self.planished_nodes[node.module.module_cvspath] = node
                else:
                    reserved_node = self.planished_nodes[
                        node.module.module_cvspath]
                    ret = self._filter_dep_nodes(reserved_node, node)
                    if ret == 1:
                        self.planished_nodes[node.module.module_cvspath] = node
                    if ret == -1:
                        self.logger.LevPrint("ERROR", "dependent conficts(%s PK %s)" % \
                                             (reserved_node.module.origin_config, \
                                             node.module.origin_config), False)
                        return False

        self.logger.LevPrint('MSG', 'Analyzing dependency success')
        # dump planished dependency tree
        self.Dump()
        if download_flag:
            return self._download_modules()
        else:
            return True
コード例 #10
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_CONVERT_OUT(self):
     """
     test Syntax.CONVERT_OUT
     """
     self.assertEqual("broc_out/baidu/broc/hello.h", Syntax.CONVERT_OUT("./hello.h"))
     #test CONVERT_OUT can raise Syntax.NotInSelfModuleError or not
     flag = False
     try:
         Syntax.CONVERT_OUT("../hello.h")
     except Syntax.NotInSelfModuleError as er:
         flag = True
     self.assertTrue(flag)
コード例 #11
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_CppFlags(self):
     """
     test Syntax.CppFlags
     """
     #test case of debug mode
     self._env._build_mode = 'debug'
     tag = Syntax.CppFlags("-g -Wall", "-g -O2")
     self.assertTrue("-g -Wall" in tag._v and "-g -O2" not in tag.V())
     
     #test case of release mode
     self._env._build_mode = 'release'
     tag2 = Syntax.CppFlags("-g -Wall", "-g -O2")
     self.assertTrue("-g -O2" in tag2.V() and "-g -Wall" not in tag2.V())
コード例 #12
0
ファイル: test_BrocLoader.py プロジェクト: wotsen-star/broc
 def test_singleton(self):
     """
     Test singleton interface 
     """
     logger = Log.Log()
     repo_domain = 'https://github.com'
     postfix = ['trunk', 'BRANCH', 'PD_BL']
     root = PlanishUtil.CreateBrocModuleFromDir("..", repo_domain,
                                                postfix[1], postfix[2],
                                                logger)
     loader1 = Syntax.BrocLoader()
     loader2 = Syntax.BrocLoader()
     self.assertEqual(loader1.Id(), loader2.Id())
コード例 #13
0
ファイル: test_BrocLoader.py プロジェクト: wotsen-star/broc
 def test_load_broc(self):
     """
     """
     logger = Log.Log()
     repo_domain = 'https://github.com'
     postfix = ['trunk', 'BRANCH', 'PD_BL']
     root = PlanishUtil.CreateBrocModuleFromDir("..", repo_domain,
                                                postfix[1], postfix[2],
                                                logger)
     node = BrocTree.BrocNode(root, None, True)
     Syntax.BrocLoader().SetRoot(node)
     Syntax.BrocLoader().LoadBROC()
     if Syntax.BrocLoader().LackBrocModules():
         print(Syntax.BrocLoader().LackBrocModules())
コード例 #14
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_UTArgs(self):
     """
     test Syntax.UTArgs
     """
     tag = Syntax.UTArgs("--conf=a.conf --log=a.log")
     self.assertTrue("--conf=a.conf" in tag.V())
     self.assertTrue("--log=a.log" in tag.V())
     self.assertTrue("--help" not in tag.V())
コード例 #15
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_LDFlags(self):
        """
        test Syntax.LDFlags
        """
        #test case of debug mode
        Environment.SetCurrent(self._env)
        self._env._build_mode = 'debug'
        tag = Syntax.LDFlags("-lpthread -lcrypto", "-lprotobuf -lpthread")
        self.assertTrue("-lpthread -lcrypto" in tag.V() \
                and "-lprotobuf -lpthread" not in tag.V())

        #reset g_linkflags
        self._env._g_linkflags = SyntaxTag.TagLDFLAGS()

        #test case of release mode
        self._env._build_mode = 'release'
        tag = Syntax.LDFlags("-lpthread -lcrypto", "-lprotobuf -lpthread")
        self.assertTrue("-lprotobuf -lpthread" in tag.V() \
                and "-lpthread -lcrypto" not in tag.V())
コード例 #16
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_Sources(self):
     """
     test Syntax.Sources
     """
     #get local flags tag
     cpptags = Syntax.CppFlags("-DDEBUG_LOCAL", "-DRELEASE_LOCAL")
     cxxtags = Syntax.CxxFlags("-Wwrite-strings", "-Wswitch")
     ctags = Syntax.CFlags("-Wwrite-strings", "-Wswitch")
     incflags = Syntax.Include("$WORKSPACE/baidu/bcloud")
     
     tag = Syntax.Sources("hello.cpp", cpptags, cxxtags, ctags, incflags)
     
     src = tag.V()[0]
     Source.Source.Action(src)
     self.assertEqual(src.cppflags, ["-DDEBUG_LOCAL"])
     self.assertEqual(src.cxxflags, ["-Wwrite-strings"])
     self.assertEqual(src.cflags, ["-Wwrite-strings"])
     self.assertEqual(src.includes, [".", "broc_out", "baidu/bcloud"])
     self.assertEqual(src.infile, "baidu/broc/hello.cpp")
コード例 #17
0
    def test_STATIC_LIBRARY(self):
        """
        test Syntax.STATIC_LIBRARY
        """
        #set local flags tag
        libs = Syntax.Libs("$OUT_ROOT/baidu/broc/libhello.a")
        cpptags = Syntax.CppFlags("-DBROC", "-DRELEASE")
        src = Syntax.Sources("hello.cpp")

        #an error name of application
        flag = False
        try:
            Syntax.STATIC_LIBRARY("^*^&*!*$^", src)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #an error args of application
        flag = False
        try:
            Syntax.STATIC_LIBRARY("hello", src, cpptags)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #Libs
        Syntax.STATIC_LIBRARY("hello", src, libs)
        library = self._env.Targets()[0]
        library.Action()
        self.assertEqual(library.tag_libs.V(),
                         ["broc_out/baidu/broc/libhello.a"])

        #two samename target
        flag = False
        try:
            Syntax.STATIC_LIBRARY("hello", src)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #library DoCopy
        Function.RunCommand("mkdir -p %s/lib" % self._module.root_path, \
                ignore_stderr_when_ok = True)
        Function.RunCommand("touch %s/lib/libhello1.a" % self._module.root_path, \
                ignore_stderr_when_ok = True)
        now_dir = os.getcwd()
        os.chdir(self._module.workspace)
        Syntax.STATIC_LIBRARY("hello1")
        lib_paths = os.path.join(self._module.workspace, "broc_out", \
                self._module.module_cvspath, "output/lib/libhello1.a")
        self.assertTrue(os.path.exists(lib_paths))
        os.chdir(now_dir)
コード例 #18
0
 def __init__(self, main_module, repo_domain, logger, postfix):
     """
     Args:
         main_module : the BrocModule_pb2.Module object representing the main module
         repo_domain : the domain name of repository
         logger : the log facility object
         postfix : the list of postfix [postfix_branche, postfix_tag]
     """
     Syntax.BrocLoader().SetRoot(BrocTree.BrocNode(main_module, None, True))
     self.logger = logger
     self.planished_nodes = dict()  # module cvspath --> BrocNode
コード例 #19
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_GIT_URL(self):
     """
     test Syntax.
     """
     self.assertEqual(self._module.url, Syntax.GIT_URL())
コード例 #20
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_GIT_PATH(self):
     """
     test Syntax.GIT_PATH
     """
     self.assertEqual(self._module.root_path, Syntax.GIT_PATH())
コード例 #21
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_SVN_LAST_CHANGED_REV(self):
     """
     test Syntax.LAST_CHANGED_REV
     """
     self.assertEqual(self._module.last_changed_rev, Syntax.SVN_LAST_CHANGED_REV())
コード例 #22
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_SVN_REVISION(self):
     """
     test Syntax.SVN_REVISION
     """
     self.assertEqual(self._module.revision, Syntax.SVN_REVISION())
コード例 #23
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_SVN_URL(self):
     """
     test Syntax.SVN_URL
     """
     self.assertEqual(self._module.url, Syntax.SVN_URL())
コード例 #24
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_GIT_BRANCH(self):
     """
     test Syntax.GIT_BRANCH
     """
     self.assertEqual(self._module.br_name, Syntax.GIT_BRANCH())
コード例 #25
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_COMPILER_PATH(self):
     """
     test Syntax.COMPILER_PATH
     """
     Syntax.COMPILER_PATH('/usr/bin/')
     self.assertEqual('/usr/bin/', self._env.CompilerDir())
コード例 #26
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_UT_APPLICATION(self):
        """
        test Syntax.UT_APPLICATION
        """
        #set local flags tag
        ldflag = Syntax.LDFlags("-lpthread", "-lcrypto")
        libs = Syntax.Libs("$OUT_ROOT/baidu/broc/libhello.a")
        cpptags = Syntax.CppFlags("-DBROC", "-DRELEASE")
        utargs = Syntax.UTArgs("--log=a.log --conf=a.conf")

        #set global flags
        Syntax.LDFLAGS("-lmcpack", "-lrt")
        src = Syntax.Sources("hello.cpp")
        
        #an error name of utapplication
        flag = False
        try:
            Syntax.UT_APPLICATION("^*^&*!*$^", src)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #an error args of utapplication
        flag = False
        try:
            Syntax.UT_APPLICATION("hello", src, cpptags)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #global ldflags
        Syntax.UT_APPLICATION("hello", src)
        utapp = self._env.Targets()[0]
        utapp.Action()
        self.assertEqual(utapp.link_options, ["-lmcpack"])
        self.assertEqual(utapp.tag_libs.V(), [])
        self.assertEqual(utapp._ut_args, [])

        #two samename target
        flag = False
        try:
            Syntax.UT_APPLICATION("hello", src)
        except Syntax.BrocArgumentIllegalError as ex:
            flag = True
        self.assertTrue(flag)

        #local ldflags
        Syntax.UT_APPLICATION("hello2", src, ldflag)
        utapp = self._env.Targets()[1]
        utapp.Action()
        self.assertEqual(utapp.link_options, ["-lpthread"])
        self.assertEqual(utapp.tag_libs.V(), [])
        self.assertEqual(utapp._ut_args, [])

        #Libs
        Syntax.UT_APPLICATION("hello3", src, ldflag, libs)
        utapp = self._env.Targets()[2]
        utapp.Action()
        self.assertEqual(utapp.link_options, ["-lpthread"])
        self.assertEqual(utapp.tag_libs.V(), ["broc_out/baidu/broc/libhello.a"])
        self.assertEqual(utapp._ut_args, [])
        
        #UTArgs
        Syntax.UT_APPLICATION("hello4", src, ldflag, libs, utargs)
        utapp = self._env.Targets()[3]
        utapp.Action()
        self.assertEqual(utapp.link_options, ["-lpthread"])
        self.assertEqual(utapp.tag_libs.V(), ["broc_out/baidu/broc/libhello.a"])
        self.assertEqual(utapp._ut_args, ["--log=a.log", "--conf=a.conf"])
コード例 #27
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
 def test_GIT_TAG(self):
     """
     test Syntax.GIT_TAG
     """
     self.assertEqual(self._module.tag_name, Syntax.GIT_TAG())
コード例 #28
0
ファイル: test_Syntax.py プロジェクト: wotsen-star/broc
    def test_CreateSources(self):
        """
        test Syntax._CreateSource
        """
        #init env global flags
        self._env._g_cppflags = SyntaxTag.TagCPPFLAGS()
        self._env._g_cflags = SyntaxTag.TagCFLAGS()
        self._env._g_cxxflags = SyntaxTag.TagCXXFLAGS()
        self._env._g_incflags = SyntaxTag.TagINCLUDE()
        self._env._g_incflags.AddV('. broc_out')
        self._env._build_mode = 'debug'

        #set local flags tag
        cpptags = Syntax.CppFlags("-DDEBUG_LOCAL", "-DRELEASE_LOCAL")
        cxxtags = Syntax.CxxFlags("-Wwrite-strings", "-Wswitch")
        ctags = Syntax.CFlags("-Wwrite-strings", "-Wswitch")
        incflag = Syntax.Include("$WORKSPACE/baidu/bcloud")

        #no flags
        src = Syntax._CreateSources("baidu/broc/hello.cpp", [])
        Source.Source.Action(src)
        self.assertEqual(src.cppflags, [])
        self.assertEqual(src.cxxflags, [])
        self.assertEqual(src.cflags, [])
        self.assertEqual(src.includes, [".", "broc_out"])
        self.assertEqual(src.infile, "baidu/broc/hello.cpp")

        #only local flags
        src = Syntax._CreateSources("baidu/broc/hello.cpp", \
                [cpptags, cxxtags, ctags, incflag])
        Source.Source.Action(src)
        self.assertEqual(src.cppflags, ["-DDEBUG_LOCAL"])
        self.assertEqual(src.cxxflags, ["-Wwrite-strings"])
        self.assertEqual(src.cflags, ["-Wwrite-strings"])
        self.assertEqual(src.includes, [".", "broc_out", "baidu/bcloud"])
        
        #only global flags
        Syntax.CFLAGS("-Werror -O2", "-W")
        Syntax.CXXFLAGS("-Werror -O2", "-W")
        Syntax.CPPFLAGS("-DDEBUG", "-DRELEASE")
        Syntax.INCLUDE("$WORKSPACE/baidu/broc")
        src = Syntax._CreateSources("baidu/broc/hello.cpp", [])
        Source.Source.Action(src)
        self.assertEqual(src.cppflags, ["-DDEBUG"])
        self.assertEqual(src.cxxflags, ["-Werror -O2"])
        self.assertEqual(src.cflags, ["-Werror -O2"])
        self.assertEqual(src.includes, [".", "broc_out", "baidu/broc"])
        self.assertEqual(src.infile, "baidu/broc/hello.cpp")

        #more value of global flags
        Syntax.CFLAGS("-Wall", "-Wall")
        Syntax.CXXFLAGS("-Wall", "-Wall")
        Syntax.CPPFLAGS("-DBROC", "-DBROC")
        src = Syntax._CreateSources("baidu/broc/hello.cpp", [])
        Source.Source.Action(src)
        self.assertEqual(src.cppflags, ["-DDEBUG", "-DBROC"])
        self.assertEqual(src.cxxflags, ["-Werror -O2", "-Wall"])
        self.assertEqual(src.cflags, ["-Werror -O2", "-Wall"])
        self.assertEqual(src.includes, [".", "broc_out", "baidu/broc"])
        self.assertEqual(src.infile, "baidu/broc/hello.cpp")

        #local flags cover golbal flags
        src = Syntax._CreateSources("baidu/broc/hello.cpp", [cpptags, cxxtags])
        Source.Source.Action(src)
        self.assertEqual(src.cppflags, ["-DDEBUG_LOCAL"])
        self.assertEqual(src.cxxflags, ["-Wwrite-strings"])
        self.assertEqual(src.cflags, ["-Werror -O2", "-Wall"])
        self.assertEqual(src.includes, [".", "broc_out", "baidu/broc"])
        self.assertEqual(src.infile, "baidu/broc/hello.cpp")