def _load_main_broc(self): """ load main module's BROC file Returns: return False if fail to load BROC file return True if load BROC file successfully """ # BROC file f = os.path.join(self._main_module.root_path, 'BROC') self._main_env = Environment.Environment(self._main_module) if self._build_mode == "release": self._main_env.DisableDebug() Environment.SetCurrent(self._main_env) try: execfile(f) except BaseException as ex: self._logger.LevPrint("ERROR", 'parsing %s failed(%s)' \ % (self._main_module.broc_cvspath, ex)) return False self._main_env.Action() self._add_env(self._main_module.module_cvspath, self._main_env) return True
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())
def setUp(self): """ init """ sys.argv = ['NOT PLANISH'] module = BrocModule_pb2.Module() module.name = 'broc' module.module_cvspath = 'baidu/broc' module.broc_cvspath = 'baidu/broc/BROC' module.is_main = True module.repo_kind = BrocModule_pb2.Module.GIT module.revision = "1234" module.last_changed_rev = "1236" module.dep_level = 0 #get home dir home = os.environ['HOME'] module.workspace = '%s/unittest_broc/workspace' % home module.root_path = '%s/unittest_broc/workspace/baidu/broc' % home module.url = 'https://github.com/baidu/broc' module.br_kind = BrocModule_pb2.Module.BRANCH module.br_name = 'trunk' #module.commit_id = '5d9819900c2781873aa0ffce285d5d3e75b072a8' self._module = module Function.RunCommand("mkdir -p %s" % module.root_path, ignore_stderr_when_ok = True) Function.RunCommand("touch %s/hello.cpp" % module.root_path, ignore_stderr_when_ok = True) Function.RunCommand("touch %s/hello.h" % module.root_path, ignore_stderr_when_ok = True) self._env = Environment.Environment(module) Environment.SetCurrent(self._env)
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())
def test_CXXFLAGS(self): """ test Syntax.CXXFLAGS """ #test case of debug mode Environment.SetCurrent(self._env) self._env._build_mode = 'debug' Syntax.CXXFLAGS("-g -Wall", "-g -O2") self.assertTrue("-g -Wall" in self._env._g_cxxflags.V() \ and "-g -O2" not in self._env._g_cxxflags.V()) #test case of muti CPPFLAGS Syntax.CXXFLAGS("-W -Wshadow", "-g -O2") Syntax.CXXFLAGS("-finline-functions", "-g -O2") self.assertTrue("-g -Wall" in self._env._g_cxxflags.V() \ and "-g -O2" not in self._env._g_cxxflags.V()) self.assertTrue("-W -Wshadow" in self._env._g_cxxflags.V() \ and "-g -O2" not in self._env._g_cxxflags.V()) self.assertTrue("-finline-functions" in self._env._g_cxxflags.V() \ and "-g -O2" not in self._env._g_cxxflags.V()) #reset g_cxxflags self._env._g_cxxflags = SyntaxTag.TagCXXFLAGS() #test case of release mode self._env._build_mode = 'release' Syntax.CXXFLAGS("-g -Wall", "-g -O2") self.assertTrue("-g -O2" in self._env._g_cxxflags.V() \ and "-g -Wall" not in self._env._g_cxxflags.V())
def _load_main_broc(self): """ load main module's BROC file Returns: return False if fail to load BROC file return True if load BROC file successfully """ # BROC file f = os.path.join(self._main_module.root_path, 'BROC') self._main_env = Environment.Environment(self._main_module) if self._build_mode == "release": self._main_env.DisableDebug() Environment.SetCurrent(self._main_env) sys.argv = ['NOT PLANISH', None] try: execfile(f) except BaseException as ex: traceback.print_exc() self._logger.LevPrint("ERROR", 'parsing %s failed(%s)' \ % (self._main_module.broc_cvspath, ex)) self._load_ok = False return False self._main_env.Action() self._add_env(self._main_module.broc_cvspath, self._main_env) if not self.InitSubEnvironment(self._main_env): return False return True
def InitSubEnvironment(self, parent): """ to init child env object whose comes from DIRECTORY tag Args: parent : the parent environment object """ subdirs = parent.SubDirs() if not subdirs: return True for subdir in subdirs: child_broc_cvspath = os.path.join(parent.Module().module_cvspath, subdir, 'BROC') child_module = copy.deepcopy(parent.Module()) child_module.broc_cvspath = child_broc_cvspath child_env = Environment.Environment(child_module) if self._build_mode == "release": child_env.DisableDebug() f = os.path.join(parent.Module().workspace, child_broc_cvspath) Environment.SetCurrent(child_env) sys.argv = ['NOT PLANISH', None] try: execfile(f) except BaseException as ex: traceback.print_exc() self._logger.LevPrint("ERROR", 'parsing %s failed(%s)' \ % (self._main_module.broc_cvspath, ex)) self._load_ok = False return False child_env.Action() self._add_env(child_broc_cvspath, child_env) parent.AddSubEnv(child_env) return True
def test_CxxFlags(self): """ test Syntax.CxxFlags """ #test case of debug mode Environment.SetCurrent(self._env) self._env._build_mode = 'debug' tag = Syntax.CxxFlags("-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.CxxFlags("-g -Wall", "-g -O2") self.assertTrue("-g -O2" in tag2.V() and "-g -Wall" not in tag2.V())
def _load_all_broc(self): """ thread function loading all BROC files, each thread object fetches one module(BrocModule_pb2.Module object) from queue, runs the BROC file of the module and creates one Environment object if execfile(BROC) throw exception, stop all thread objects """ while not self._load_done: module = None try: module = self._queue.get(True, 1) except Queue.Empty: continue # BROC file f = os.path.join(module.root_path, 'BROC') env = Environment.Environment(module) if self._build_mode == "release": env.DisableDebug() Environment.SetCurrent(env) try: execfile(f) except BaseException as ex: traceback.print_exc() self._logger.LevPrint( "ERROR", 'parsing %s failed(%s)' % (module.broc_cvspath, ex)) # discard all module in queue while not self._queue.empty(): self._queue.get() self._queue.task_done() self._load_done = True self._load_ok = False self._queue.task_done() break env.SetCompilerDir(self._main_env.CompilerDir()) env.Action() self._add_env(module.broc_cvspath, env) if not self.InitSubEnvironment(env): while not self._queue.empty(): self._queue.get() self._queue.task_done() self._load_done = True self._load_ok = False break self._queue.task_done()
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())