build.py now automatically incorporates dependencies not listed in the build profile. fixes #490.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2542 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Schuyler Erle
2007-03-08 20:14:05 +00:00
parent c66f1ce360
commit 846c98df4a

View File

@@ -132,7 +132,6 @@ def run (sourceDirectory, outputFilename = None, configFile = None):
if configFile: if configFile:
cfg = Config(configFile) cfg = Config(configFile)
print cfg.include
allFiles = [] allFiles = []
## Find all the Javascript source files ## Find all the Javascript source files
@@ -162,13 +161,20 @@ def run (sourceDirectory, outputFilename = None, configFile = None):
content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF? content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
files[filepath] = SourceFile(filepath, content) # TODO: Chop path? files[filepath] = SourceFile(filepath, content) # TODO: Chop path?
## Resolve the dependencies print
print "\nResolving dependencies...\n"
from toposort import toposort from toposort import toposort
complete = False
resolution_pass = 1
while not complete:
order = [] # List of filepaths to output, in a dependency satisfying order
nodes = [] nodes = []
routes = [] routes = []
## Resolve the dependencies
print "Resolution pass %s... " % resolution_pass
resolution_pass += 1
for filepath, info in files.items(): for filepath, info in files.items():
nodes.append(filepath) nodes.append(filepath)
@@ -178,24 +184,36 @@ def run (sourceDirectory, outputFilename = None, configFile = None):
for dependencyLevel in toposort(nodes, routes): for dependencyLevel in toposort(nodes, routes):
for filepath in dependencyLevel: for filepath in dependencyLevel:
order.append(filepath) order.append(filepath)
if not files.has_key(filepath):
print "Importing: %s" % filepath
fullpath = os.path.join(sourceDirectory, filepath)
content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF?
files[filepath] = SourceFile(filepath, content) # TODO: Chop path?
# Double check all dependencies have been met
complete = True
try:
for fp in order:
if max([order.index(rfp) for rfp in files[fp].requires] +
[order.index(fp)]) != order.index(fp):
complete = False
except:
complete = False
print
## Move forced first and last files to the required position ## Move forced first and last files to the required position
if cfg: if cfg:
print "Re-ordering files...\n" print "Re-ordering files..."
order = cfg.forceFirst + [item order = cfg.forceFirst + [item
for item in order for item in order
if ((item not in cfg.forceFirst) and if ((item not in cfg.forceFirst) and
(item not in cfg.forceLast))] + cfg.forceLast (item not in cfg.forceLast))] + cfg.forceLast
## Double check all dependencies have been met print
for fp in order:
if max([order.index(rfp) for rfp in files[fp].requires] +
[order.index(fp)]) != order.index(fp):
print "Inconsistent!"
raise SystemExit
## Output the files in the determined order ## Output the files in the determined order
result = [] result = []
@@ -208,7 +226,7 @@ def run (sourceDirectory, outputFilename = None, configFile = None):
if not source.endswith("\n"): if not source.endswith("\n"):
result.append("\n") result.append("\n")
print "\nTotal files merged: %d " % len(allFiles) print "\nTotal files merged: %d " % len(files)
if outputFilename: if outputFilename:
print "\nGenerating: %s" % (outputFilename) print "\nGenerating: %s" % (outputFilename)