def BuildPch( infile, incdirs=None, incfiles=None, defines=None, options=None ) : # call cpp0.exe cpp0 = atmake.utilities.FindApp('cpp0.exe') cl = r'%s %s ' % (cpp0, options if options else '') # -I path if incdirs : for incdir in atmake.ToList(incdirs) : cl += ' -I {%s}' % incdir # -include file if incfiles : for incfile in atmake.ToList(incfiles) : cl += ' -include {%s}' % incfile # -Dsym if defines : for sym in atmake.ToList(defines) : cl += ' {-D%s}' % sym # input cpp source file cl += ' {%s}' % infile # print cl res = spawn.Spawn( cl ) # ( exec_success, exit_code, stdout lines, stderr lines ) return res
def ParseCpp(infile, outfile=None, incdirs=None, incfiles=None, defines=None, options=None, startscope=None): # call gccxml_cc1plus.exe gccxml = atmake.utilities.FindApp('gccxml_cc1plus') cl = r'%s %s ' % (gccxml, options if options else '-quiet -w') # -I path if incdirs: for incdir in atmake.ToList(incdirs): cl += ' -I {%s}' % incdir # -include file if incfiles: for incfile in atmake.ToList(incfiles): cl += ' -include {%s}' % incfile # -Dsym if defines: for sym in atmake.ToList(defines): cl += ' {-D%s}' % sym # -fxml-start=su::CNet for example if atmake.IsString(startscope): cl += ' {-fxml-start=%s}' % startscope # output XML file return_lines = False if outfile is None: outfile = tempfile.NamedTemporaryFile().name return_lines = True cl += ' {-fxml=%s}' % outfile # input cpp source file cl += ' {%s}' % infile # print (cl) res = spawn.Spawn(cl) # print (res) if not res: return None if not res[0] or res[1] != 0: for l in res[3]: print(l) return None if return_lines: return open(outfile, 'r').readlines() else: return True
def AppendList(li, v): if atmake.IsEmpty(li): li = [] elif atmake.IsString(li): li = li.split() for i in atmake.ToList(v): if not i in li: li.append(i) return li
def PrependList(li, v): if atmake.IsEmpty(li): li = [] elif atmake.IsString(li): li = li.split() for i in atmake.ToList(v): if not i in li: li.insert(0, i) return li
def FindFileInDirs(filename, listdirs): if os.path.isfile(filename): return os.path.normpath(filename) for dir in atmake.ToList(listdirs): f = os.path.join(dir, filename) if os.path.isfile(f): return os.path.normpath(f) return None
def mfilters_list(infilter): fl = [] for f1 in atmake.ToList(infilter): for f2 in f1.split(): for f3 in f2.split(';'): for f4 in f3.split(':'): for f5 in f4.split(','): fl.append(f5) return fl
def __actions_sign(self, actions): if actions: so = sha() for a in atmake.ToList(actions): a = str(a) so.update(a.encode()) return so.hexdigest() else: return None
def __fmt_source_ext(self, ext): if atmake.IsString(ext): extl = ext.split() else: extl = atmake.ToList(ext) extr = [] for e in extl: if not atmake.IsString(e): atmake.Error("Source extension must be a string !") if e.startswith('.'): extr.append(e[1:]) else: extr.append(e) return extr
def SubstActions(self, ctxt): """ Context ctxt """ actions = [] for a in self.actions: if a: sa = subst_build.Subst(ctxt, a) if sa: actions.extend(atmake.ToList(sa)) if not actions: return None else: return actions
def parse_cpp(sidl=None): cpppath = sidl.env.GetVarlist('cpppath') gccxmldefines = sidl.env.GetVarlist('gccxmldefines') gccxmlfiles = sidl.env.GetVarlist('gccxmlfiles') fromfiles = collect_fromfiles(sidl) gccfiles = atmake.ToList(gccxmlfiles) + atmake.ToList(fromfiles) cpplines = [] for f in gccfiles: if fs.IsAbsPath(f) and fs.IsFilePath(f): cpplines.append('#include "%s"\n' % f) else: cpplines.append('#include <%s>\n' % f) xmlfile = tempfile.NamedTemporaryFile(prefix='.xml').name cppfile = tempfile.NamedTemporaryFile(prefix='.cpp').name open(cppfile, 'w').writelines(cpplines) ok = cpptoxml.ParseCpp(infile=cppfile, outfile=xmlfile, incdirs=cpppath, defines=gccxmldefines) cpp = cpptoxml.ParseXml(xmlfile) if ok else None atmake.RmFile(cppfile) atmake.RmFile(xmlfile) return cpp
def CFileScanner ( outScan, fw, fname ) : srcfile = fw.ToAbsFile( fname ) incdirs = [] includes = fw.env['INCLUDE'] atmake.Assert( atmake.IsString(includes) ) for d in includes.split( os.pathsep ) : if atmake.IsString(d) : incdirs.append( fw.ToAbsFile(d) ) deps = CFileDepends ( srcfile, incdirs=incdirs, recurse=False ) for dep in atmake.ToList(deps) : outScan.AddDepend( dep )
def UnindentLines(lines): def findcommon(a, b): if a is None: return b if b is None: return a la, lb, s = len(a), len(b), 0 while s < la and s < lb and a[s] == b[s]: s += 1 return a[:s] lines = '\n'.join(atmake.ToList(lines)).splitlines() if len(lines) >= 2: if len(lines[0].strip()) == 0: lines = lines[1:] if len(lines[-1].strip()) == 0: lines = lines[:-1] d = None for l in lines: if len(l.strip()): s = l.lstrip() t = len(l) - len(s) r = l[:t] d = findcommon(d, r) if d: return [l[len(d):] for l in lines] else: return lines
def extend1(toappend=None, target=None): if target is None: target = [] for l in atmake.ToList(toappend): if not l in target: target.append(l) return target
def __init__(self, target=None, sources=None): self.target = target self.sources = atmake.iif(sources, atmake.ToList(sources), [])
def __fmt_actions(self, actions): actions = [e.replace('\\', '/') for e in actions] return atmake.ToList(actions)
def RackHeaderFiles ( outputdir, inputs=None, readonly=True, prefix=None, extlist=None ) : inputs_dirs = [x for x in atmake.ToList(inputs) if fs.IsDirPath(x)] inputs_files = [x for x in atmake.ToList(inputs) if fs.IsFilePath(x)] extlist = extlist or ['.h'] fmap = {} def _map_name ( infile ) : i = 0 d = os.path.dirname(infile) b,e = os.path.splitext( os.path.basename(infile) ) f = '%s/%s%s%s' % (outputdir,prefix or '',b,e) while 1 : if not f in fmap : fmap[f] = infile return f f = '%s/%s%s_%d%s' % (d,prefix or '',b,i,e) i += 1 def _map_file( infile ) : if not os.path.isfile(infile): return df = os.path.dirname(infile) nf = os.path.normpath(infile) if nf in fmap: return fmap[nf] fext = os.path.splitext(infile)[1] if not fext in extlist: return try: lines = open(nf,'r').readlines() except: return fmap[nf] = _map_name(infile) olines = [] for l in lines : of = None # "..." ? so = _re_cfile_inc1.search(l) if so : f = '%s/%s' % (df,so.group(1)) if os.path.isfile(f) : of = _map_file(f) # <...> ? so = _re_cfile_inc2.search(l) if so : for d in inputs_dirs: f = '%s/%s' % (d,so.group(1)) if os.path.isfile(f) : of = _map_file(f) if of: olines.append( '#include "%s"\n'%fs.FileToFile(of,fmap[nf]) ) else: olines.append( l ) open(fmap[nf],'w').writelines(olines) return fmap[nf] fs.RmTree( outputdir ) fs.CreateDir( outputdir, rec=True ) if not fs.IsDirPath(outputdir) : print("Can't create output directory '%s' !" % outputdir) exit(1) for f in inputs_files: _map_file( f ) for d in inputs_dirs: [ _map_file(f) for f in glob.glob('%s/*'%d) ]
def AddBuild ( self, target, sources ) : if target and sources : bf = builder.BuildFiles( target, atmake.ToList(sources) ) self.builds.append( bf )
def GetLinesSign(lines): so = sha() for l in atmake.ToList(lines): so.update(l.encode()) return so.hexdigest()
def CFileDepends ( fnames, incdirs=None, recurse=True ) : def __find_usr_inc( srcfile, inc ) : # include "..." # The include file could not exist, for example toto.bin2h is generated and doesn't exist before ... if not inc or not srcfile : return None if fs.IsFilePath(inc) : # "c:\\..." afile = os.path.normpath( inc ) # print '[%s] #include "%s" -> [%s]' % (srcfile,inc,str(afile)) return afile else : adir = os.path.dirname( srcfile ) afile = os.path.normpath( os.path.join( adir, inc ) ) # print '[%s] #include "%s" -> [%s]' % (fname,inc,str(afile)) return afile def __find_sys_inc( srcfile, inc, incdirs ) : # include <...> # The include file must exist ! if not inc or not srcfile : return None if fs.IsFilePath(inc) : # <c:\\...> afile = os.path.normpath( inc ) #print '[%s] #include <%s> -> [%s]' % (fname,inc,str(afile)) return afile afile = fs.FindFileInDirs( inc, incdirs ) if fs.IsFilePath(afile) : #print '[%s] #include <%s> -> [%s]' % (fname,inc,str(afile)) return os.path.normpath( afile ) # not found ! #print '[%s] #include <%s> -> not found !' % (fname,inc) return os.path.normpath( inc ) def __recurse_inc ( fname, incdirs, iodeps ) : srcfile = fs.FindFileInDirs( fname, incdirs ) try : srclines = open(srcfile,'r').readlines() except : return None for l in srclines : dep = None so = _re_cfile_inc1.search(l) if so : dep = __find_usr_inc( srcfile, so.group(1) ) else : so = _re_cfile_inc2.search(l) if so : dep = __find_sys_inc( srcfile, so.group(1), incdirs ) if dep and dep not in iodeps : iodeps[ dep ] = 1 __recurse_inc( dep, incdirs, iodeps ) deps = {} for fname in atmake.ToList(fnames) : __recurse_inc( fname, incdirs, deps ) return list(deps.keys())
def AbsoluteFiles(basedir, paths): l = [] for p in atmake.ToList(paths): l.append(AbsoluteFile(basedir, p)) return l
def RelativeFiles(refdir, paths): l = [] for p in atmake.ToList(paths): l.append(RelativeFile(refdir, p)) return l