def GLOB(*ss): """ gather all files belonging to module, if argument specified in ss does not beneath the directory of module, raise BrocArgumentIllegalError Args: ss : a variable number of string objects, support regrex Returns: string containing the relative path of files or directories, each path separeated by blank character """ env = Environment.GetCurrent() strs = [] for s in ss: ps = string.split(s) for p in ps: if p.startswith(os.path.join("broc_out", env.ModuleCVSPath())): norm_path = os.path.normpath(os.path.join(env.Workspace(), p)) len_abandon = len(os.path.normpath(env.Workspace())) else: norm_path = os.path.normpath(os.path.join(env.BrocDir(), p)) len_abandon = len(os.path.normpath(env.BrocDir())) if env.ModuleCVSPath() not in norm_path: raise NotInSelfModuleError(norm_path, env.ModuleCVSPath()) else: gs = glob.glob(norm_path) gs.sort() file_list = list() for file_name in gs: # remove workspace path from file path file_list.append(file_name[len_abandon + 1:]) strs.extend(file_list) if not strs: raise BrocArgumentIllegalError("GLOB(%s) is empty" % str(ss)) return str(' '.join(strs))
def GIT_TAG(): """ return the tag of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def Libs(*ss): """ add .a files to target tag, such as APPLICATION, UT_APPLICATION, STATIC_LIBRARY ss may contain multiple arguments, each argument can contain muitiple lib's path, each lib's path should start with $OUT_ROOT for example Libs("$ROOT_OUT/test/output/lib/libutil.a", "$ROOT_OUT/foo/output/lib/libcommon.a") Args: ss : a variable number of string objects Returns: SyntaxTag.TagLibs() """ tag = SyntaxTag.TagLibs() if sys.argv[0] == 'PLANISH': return tag for s in ss: if not isinstance(s, str): raise BrocArgumentIllegalError("argument %s is illegal in tag Libs" % s) if os.path.isabs(s): tag.AddSV(s) continue elif s.startswith("$OUT_ROOT"): tag.AddSV(os.path.normpath(s.replace("$OUT_ROOT", "broc_out"))) continue elif s.startswith('$WORKSPACE'): tag.AddSV(os.path.normpath(s.replace("$WORKSPACE/", ""))) continue elif s.startswith("$OUT"): env = Environment.GetCurrent() out = os.path.join('broc_out', env.ModuleCVSPath(), 'output') tag.AddSV(os.path.normpath(s.replace("$OUT", out))) continue else: raise BrocArgumentIllegalError("args(%s) should be a abs path or startswith $WORKSPACE|$OUT|$OUT_ROOT in tag Libs" % s) return tag
def GIT_BRANCH(): """ return the branch name of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def GIT_COMMIT_ID(): """ return the commit id of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def GIT_URL(): """ return url of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def GIT_PATH(): """ return local path of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def SVN_LAST_CHANGED_REV(): """ return last changed rev """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def DIRECTORY(v): """ Add sub directory Args: v : the name of subdirectory, v is relative path """ # gather all dependent module env = Environment.GetCurrent() child_broc_dir = os.path.abspath(os.path.join(env.ModulePath(), v)) if env.ModulePath() not in child_broc_dir: raise BrocArgumentIllegalError("DIRECTORY(%s) is wrong: %s not in %s" % \ (child_broc_dir, env.ModulePath())) child_broc_file = os.path.join(env.Module().root_path, v, 'BROC') if sys.argv[0] == 'PLANISH': parent = sys.argv[1] if not os.path.exists(child_broc_file): raise BrocArgumentIllegalError('Not found %s in Tag Directory(%s)' % (child_broc_file, v)) try: execfile(child_broc_file) except BaseException as err: traceback.print_exc() raise BrocArgumentIllegalError(err) else: # find all targets to build if not os.path.exists(child_broc_file): raise BrocArgumentIllegalError('Not found %s in Tag Directory(%s)' % (child_broc_file, v)) # Log.Log().LevPrint("INFO", 'add sub directory (%s) for module %s' % (v, env._module.module_cvspath)) env.AddSubDir(v)
def Sources(*ss): """ create a group of Sources object all source file should beneathes the directory of module, if not will raise NotInSelfModuleError avoid containing wildcard in ss, so you can use GLOB gathering files firstly, and take the result of GLOB as ss Args: ss : a variable number of artuments, all string arguments in ss will be regarded as source file, the file can be .c, .cpp and so on, and the reset arguments are regarded as compile flags Returns: TagSources Object """ tag = SyntaxTag.TagSources() if sys.argv[0] == 'PLANISH': return tag # FIX ME: you can extend wildcard files, args = _ParseNameAndArgs(*ss) env = Environment.GetCurrent() all_files = GLOB(" ".join(files)).split(' ') for f in all_files: if not f.startswith(os.path.join("broc_out", env.ModuleCVSPath())): f = os.path.join(os.path.dirname(env.BrocCVSPath()), f) src = _CreateSources(f, args) tag.AddSV(src) return tag
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()
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
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)
def SVN_REVISION(): """ return revision of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent()
def Include(*ss): """ set the local file search path Args: ss : a variable number of string objects ss may contain multiple string objects, each object can contain multiple paths 1. if path does not beneath module, in other words, if user want to specified other modules' path, should start with $WORKSPACE, 2. if path couldn't be founed in module itself and path does not start with $WORKSPACE rasie NotInSelfModuleError 3. if path is output directory, it must start with 'broc_out/' for example: ss can be "./include ./include/foo", "$WORKSPACE/include", "broc_out/test/include" """ env = Environment.GetCurrent() broc_abs_dir = env.BrocDir() broc_cvs_dir = env.BrocCVSDir() tag = SyntaxTag.TagInclude() for s in ss: ps = string.split(s) for x in ps: if x.startswith("$WORKSPACE"): tag.AddSV(x.replace("$WORKSPACE/", "")) continue elif x.startswith('broc_out/') or os.path.isabs(x): tag.AddSV(x) continue elif x.startswith("$OUT_ROOT"): tag.AddSV(x.replace("$OUT_ROOT", 'broc_out')) continue else: _x = os.path.normpath(os.path.join(broc_abs_dir, x)) if env.ModulePath() not in _x: raise NotInSelfModuleError(_x, env.ModulePath()) else: tag.AddSV(os.path.normpath(os.path.join(broc_cvs_dir, x))) return tag
def INCLUDE(*ss): """ set the global head file search path Default head files search path includes $WORKSPACE and $OUT_ROOT Args: ss : a variable number of string objects ss may contain multiple string objects, each object can contain multiple paths 1. if path does not beneath module, in other words, if user want to specified other modules' path, should start with $WORKSPACE, 2. if path couldn't be founed in module itself and path does not start with $WORKSPACE rasie NotInSelfModuleError 3. if path is output directory, it must start with 'broc_out/' for example: ss can be "./include ./include/foo", "$WORKSPACE/include", "broc_out/test/include" """ env = Environment.GetCurrent() tag = env.IncludePaths() broc_dir = env.BrocDir() for s in ss: ps = s.split() for x in ps: if x.startswith("$WORKSPACE"): tag.AddSV(x.replace("$WORKSPACE/", '')) elif x.startswith("broc_out/") or os.path.isabs(x): tag.AddSV(x) else: _x = os.path.normpath(os.path.join(broc_dir, x)) if env.ModulePath() not in _x: raise NotInSelfModuleError(_x, env.ModulePath()) else: tag.AddSV(_x)
def DIRECOTYR(v): """ Add sub directory Args: v : the name of subdirectory, v is relative path """ env = Environment.GetCurrent() env.AppendSubDirectory(os.path.normpath(v))
def SVN_URL(): """ return url of module """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent() return env.SvnUrl()
def COMPILER_PATH(k): """ set global path of compiler's directory influence main moudle and all dependent modules Args: k : string object, compiler's directory, for example: if you set k as '/usr/bin', we should find 'gcc' and 'g++' in directory /usr/bin """ env = Environment.GetCurrent() env.SetCompilerDir(k)
def PUBLISH(srcs, out_dir): """ copy srcs to out_dir Args: srcs: the files needed to move should belongs to the module out_dir: the destination directory that must start with $OUT if argument is illeagl, raise BrocArgumentIllegalError """ if sys.argv[0] == 'PLANISH': return env = Environment.GetCurrent() if not out_dir.strip().startswith('$OUT'):
def LDFLAGS(d_flags, r_flags): """ add global link flags Args: d_flags : link flags in debug mode r_flags : link flags in release mode """ env = Environment.GetCurrent() if env.BuildMode() == "debug": env.LDFlags().AddSV(d_flags) else: env.LDFlags().AddSV(r_flags)
def CPPFLAGS(d_flags, r_flags): """ set module's global preprocess flags Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() # default build mode is debug, it can be modified by command 'broc' by user if env.BuildMode() == "debug": env.CppFlags().AddSV(d_flags) else: env.CppFlags().AddSV(r_flags)
def CXXFLAGS(d_flags, r_flags): """ set the global compile options for c++ files, this influences the all of cxx files in module Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() if env.BuildMode() == "debug": env.CxxFlags().AddSV(d_flags) else: env.CxxFlags().AddSV(r_flags)
def CFLAGS(d_flags, r_flags): """ set the global compile options for c files, this influences the all of c files in module Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() # default build mode is debug, it can be modified by command 'broc' by user if env.BuildMode() == "debug": env.CFlags().AddSV(d_flags) else: env.CFlags().AddSV(r_flags)
def LDFlags(d_flags, r_flags): """ add local link flags Args: d_flags : link flags in debug mode r_flags : link flags in release mode """ env = Environment.GetCurrent() tag = SyntaxTag.TagLDFlags() if env.BuildMode() == "debug": tag.AddSV(d_flags) else: tag.AddSV(r_flags) return tag
def CppFlags(d_flags, r_flags): """ set local prrprocess flags, override the global CPPFLAGS Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() tag = SyntaxTag.TagCppFlags() # default build mode is debug, it can be modified by command 'broc' by user if env.BuildMode() == "debug": tag.AddSV(d_flags) else: tag.AddSV(r_flags) return tag
def CONVERT_OUT(s): """ convert a directory of module into a reponsed output directory if s doesn't beneath the module, raise NotInSelfModuleError Args: s : a relative directory beneathed the module Returns: return the relative path of responsed output directory """ env = Environment.GetCurrent() _s = os.path.normpath(os.path.join(env.BrocDir(), s)) # to check whether _s beneathes directory of module if env.ModulePath() not in _s: raise NotInSelfModuleError(env.BrocDir(), _s) return os.path.normpath(os.path.join('broc_out', env.BrocCVSDir(), s))
def CxxFlags(d_flags, r_flags): """ set the local compile option for cxx files, this influences the all of cxx files in target tag Args: d_flags : debug mode preprocess flags r_flags : release mode preprocess flags """ env = Environment.GetCurrent() tag = SyntaxTag.TagCxxFlags() if env.BuildMode() == "debug": tag.AddSV(d_flags) else: tag.AddSV(r_flags) return tag
def PUBLISH(srcs, out_dir): """ copy srcs to out_dir Args: srcs: the files needed to move should belongs to the module out_dir: the destination directory that must start with $OUT if argument is illeagl, raise BrocArgumentIllegalError """ env = Environment.GetCurrent() if not out_dir.strip().startswith('$OUT'): raise BrocArgumentIllegalError("PUBLISH argument dst(%s) must start with $OUT \ in %s " % (out_dir, env.BrocPath())) src_lists = srcs.split() for s in src_lists: abs_s = os.path.normpath(os.path.join(env.BrocDir(), s)) if env.ModulePath() not in abs_s: raise NotInSelfModuleError(abs_s, env.ModulePath()) env.AddPublish(srcs, out_dir)
def _CreateSources(_file, *args): """ create a Source object Args: _file : the cvs path of source code file _args : a variable number of TagVector object Return: the Source object """ src = None env = Environment.GetCurrent() _, ext = os.path.splitext(_file) if ext in Source.CSource.EXTS: src = Source.CSource(_file, env, args) elif ext in Source.CXXSource.EXTS: src = Source.CXXSource(_file, env, args) else: raise BrocArgumentIllegalError("don't support file(%s) whose ext is(%s)" % (_file, ext)) env.AppendSource(src) return src