OpenLayers OpenLayers

Changeset 2542

Show
Ignore:
Timestamp:
03/08/07 20:14:05 (1 year ago)
Author:
sderle
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/tools/mergejs.py

    r2098 r2542  
    133133        cfg = Config(configFile) 
    134134 
    135     print cfg.include 
    136135    allFiles = [] 
    137136 
     
    163162        files[filepath] = SourceFile(filepath, content) # TODO: Chop path? 
    164163 
    165     ## Resolve the dependencies 
    166     print "\nResolving dependencies...\n" 
     164    print 
    167165 
    168166    from toposort import toposort 
    169167 
    170     nodes = [] 
    171     routes = [] 
    172  
    173     for filepath, info in files.items(): 
    174         nodes.append(filepath) 
    175         for neededFilePath in info.requires: 
    176             routes.append((neededFilePath, filepath)) 
    177  
    178     for dependencyLevel in toposort(nodes, routes): 
    179         for filepath in dependencyLevel: 
    180             order.append(filepath) 
     168    complete = False 
     169    resolution_pass = 1 
     170 
     171    while not complete: 
     172        order = [] # List of filepaths to output, in a dependency satisfying order  
     173        nodes = [] 
     174        routes = [] 
     175        ## Resolve the dependencies 
     176        print "Resolution pass %s... " % resolution_pass 
     177        resolution_pass += 1  
     178 
     179        for filepath, info in files.items(): 
     180            nodes.append(filepath) 
     181            for neededFilePath in info.requires: 
     182                routes.append((neededFilePath, filepath)) 
     183 
     184        for dependencyLevel in toposort(nodes, routes): 
     185            for filepath in dependencyLevel: 
     186                order.append(filepath) 
     187                if not files.has_key(filepath): 
     188                    print "Importing: %s" % filepath 
     189                    fullpath = os.path.join(sourceDirectory, filepath) 
     190                    content = open(fullpath, "U").read() # TODO: Ensure end of line @ EOF? 
     191                    files[filepath] = SourceFile(filepath, content) # TODO: Chop path? 
     192         
     193 
     194 
     195        # Double check all dependencies have been met 
     196        complete = True 
     197        try: 
     198            for fp in order: 
     199                if max([order.index(rfp) for rfp in files[fp].requires] + 
     200                       [order.index(fp)]) != order.index(fp): 
     201                    complete = False 
     202        except: 
     203            complete = False 
     204         
     205        print     
    181206 
    182207 
    183208    ## Move forced first and last files to the required position 
    184209    if cfg: 
    185         print "Re-ordering files...\n
     210        print "Re-ordering files...
    186211        order = cfg.forceFirst + [item 
    187212                     for item in order 
    188213                     if ((item not in cfg.forceFirst) and 
    189214                         (item not in cfg.forceLast))] + cfg.forceLast 
    190  
    191     ## Double check all dependencies have been met 
    192     for fp in order: 
    193         if max([order.index(rfp) for rfp in files[fp].requires] + 
    194                [order.index(fp)]) != order.index(fp): 
    195             print "Inconsistent!" 
    196             raise SystemExit 
    197  
    198  
     215     
     216    print 
    199217    ## Output the files in the determined order 
    200218    result = [] 
     
    209227            result.append("\n") 
    210228 
    211     print "\nTotal files merged: %d " % len(allFiles) 
     229    print "\nTotal files merged: %d " % len(files) 
    212230 
    213231    if outputFilename: