Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
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 )
Exemplo n.º 12
0
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
Exemplo n.º 13
0
 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
Exemplo n.º 14
0
 def __init__(self, target=None, sources=None):
     self.target = target
     self.sources = atmake.iif(sources, atmake.ToList(sources), [])
Exemplo n.º 15
0
 def __fmt_actions(self, actions):
     actions = [e.replace('\\', '/') for e in actions]
     return atmake.ToList(actions)
Exemplo n.º 16
0
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) ]
Exemplo n.º 17
0
	def AddBuild ( self, target, sources ) :
		if target and sources :
			bf = builder.BuildFiles( target, atmake.ToList(sources) )
			self.builds.append( bf )
Exemplo n.º 18
0
def GetLinesSign(lines):
    so = sha()
    for l in atmake.ToList(lines):
        so.update(l.encode())
    return so.hexdigest()
Exemplo n.º 19
0
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())
Exemplo n.º 20
0
def AbsoluteFiles(basedir, paths):
    l = []
    for p in atmake.ToList(paths):
        l.append(AbsoluteFile(basedir, p))
    return l
Exemplo n.º 21
0
def RelativeFiles(refdir, paths):
    l = []
    for p in atmake.ToList(paths):
        l.append(RelativeFile(refdir, p))
    return l