Esempio n. 1
0
 def test_CFlags(self):
     """
     test Syntax.CFlags
     """
     #test case of debug mode
     Environment.SetCurrent(self._env)
     self._env._build_mode = 'debug'
     tag = Syntax.CFlags("-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'
     self._env._build_mode = 'release'
     tag2 = Syntax.CFlags("-g -Wall", "-g -O2")
     self.assertTrue("-g -O2" in tag2.V() and "-g -Wall" not in tag2.V())
Esempio n. 2
0
    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])
Esempio n. 3
0
 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")
Esempio n. 4
0
    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")