fastdep

Christopher Waters <[email protected]>
Newsgroups gmane.comp.graphics.chromium.devel
Message-ID <[email protected]>
Is a python port of the fastdeps.pl still needed (as said in the TO-DO 
file)?  I've written one up, and attached it to this.

While writing it, I discovered a bug in the perl version:  the 
expression "/^-I(.+)\/$/" on line 92 should be "/^-I(.+\/)$/" in order 
to properly recognize include paths with a trailing slash.

If it is still needed, could someone check to see that the python 
version works correctly?  I also didn't know exactly what to put at the 
top, as well (copyright?)

  -Chris Waters
fastdep.py (application/octet-stream, 2 KB)
import sys
import re
import os

def directory( dfile ):
	if "/" in dfile:
		d = re.match("^(.*)\/([^\/])+$", dfile ).group(1)
	else:
		d = "."

	return ( d + "/" )

dInc = dict()

def includes( incfile ):
	global dInc

	if incfile in dInc:
		return dInc[ incfile ]

	try: hFile = file( incfile )
	except (IOError, TypeError):
		return None

	angles = []
	quotes = []

	for line in hFile.readlines():
		if re.match("\s*\#", line) == None:
			continue
		m = re.match("^\s*#\s*include\s*([<\"])(.*)[>\"]", line)
		if m:
			if m.group(1) == "<":
				angles.append( m.group(2) )
			else:
				quotes.append( m.group(2) )

	hFile.close()

	incdir = directory(incfile)
	files = []

	while len(quotes):
		name = quotes.pop()
		f = incdir + name
		if os.path.exists(f):
			files.append( f )
		else:
			angles.append( name )

	for name in angles:
		for incdir in incpath:
			f = incdir + name
			if os.path.exists(f):
				files.append(f)
				break

	dInc[incfile] = files

	return files

def depends( depfile ):
	depfiles = [depfile]
	dFiles = dict()

	while len(depfiles):
		f = depfiles.pop()
		if f in dFiles:
			continue

		dFiles[f] = 1
		f = includes(f)
		if f: depfiles[:0] = f

	return dFiles.keys()


obj_prefix = ""

if os.name == 'nt': obj_suffix = ".obj"
else:               obj_suffix = ".o"

extra_targets = []
incpath = []
files = []

for arg in sys.argv[1:]:
	val = re.match(r"^-I(.+/)$", arg)
	if val:
		incpath.append( val.group(1) )
		continue

	val = re.match("^-I(.+)$", arg)
	if val:
		incpath.append( val.group(1) + "/" )
		continue

	val = re.match("^--obj-prefix=(.*)$", arg )
	if val:
		obj_prefix = val.group(1)
		continue

	val = re.match("^--obj-suffix=(.*)$", arg )
	if val:
		obj_suffix = val.group(1)
		continue

	val = re.match("^--extra-target=(.*)$", arg )
	if val:
		extra_targets.append(val.group(1))
		continue

	if arg[0] != '/':
		files += [arg]

for incfile in files:
	val = re.match("^(.*)\.\w+$", incfile )
	obj = obj_prefix + val.group(1) + obj_suffix

	for t in extra_targets:
		obj += " " + t

	for incfile in depends(incfile):
		print "%s: %s" % (obj, incfile)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.