Projects
Wiki     New Ticket     View Tickets     Timeline     Browse Source     Search

Changeset 356 for trunk

Show
Ignore:
Timestamp:
2007-11-12 22:14:10 (12 months ago)
Author:
kvv@…
Message:

more robust dependency resolution logic

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/darwinxref/plugins/resolveDeps.c

    r299 r356  
    4444        int commit = 0; 
    4545 
    46         if(count == 1) { 
     46        if (count == 1) { 
    4747          project = strdup_cfstr(CFArrayGetValueAtIndex(argv, 0)); 
    4848        } else if (count > 1) { 
    4949          project = strdup_cfstr(CFArrayGetValueAtIndex(argv, 1)); 
    50           if(CFEqual(CFSTR("-commit"), CFArrayGetValueAtIndex(argv, 0))) 
     50          if (CFEqual(CFSTR("-commit"), CFArrayGetValueAtIndex(argv, 0))) 
    5151            commit = 1; 
    5252        } 
     
    8686        CFMutableArrayRef params[2] = { files, types }; 
    8787 
    88         CFMutableDictionaryRef finalDeps = CFDictionaryCreateMutable(NULL, 0, 
    89                                                                      &kCFCopyStringDictionaryKeyCallBacks, 
    90                                                                      &kCFTypeDictionaryValueCallBacks); 
    91  
    92  
    9388        char* table = "CREATE TABLE dependencies (build TEXT, project TEXT, type TEXT, dependency TEXT)"; 
    9489        char* index = "CREATE INDEX dependencies_index ON unresolved_dependencies (build, project, type, dependency)"; 
     
    9994        if (SQL("BEGIN")) { return -1; } 
    10095 
     96        // Convert from unresolved_dependencies (i.e. path names) to resolved dependencies (i.e. project names) 
     97        // Deletes unresolved_dependencies after they are processed. 
    10198        SQL_CALLBACK(&addToCStrArrays, params, 
    10299                "SELECT DISTINCT dependency,type FROM unresolved_dependencies WHERE build=%Q AND project=%Q", 
     
    122119                        SQL("DELETE FROM unresolved_dependencies WHERE build=%Q AND project=%Q AND type=%Q AND dependency=%Q", 
    123120                                build, project, type, file); 
    124                         if(commit) { 
    125                           // find subarray for this dep type 
    126                           CFStringRef cfdep = cfstr(type); 
    127                           CFStringRef cfval = cfstr(dep); 
    128                           CFMutableArrayRef deparray = (CFMutableArrayRef)CFDictionaryGetValue(finalDeps, cfdep); 
    129                           if(deparray == NULL) { 
    130                             deparray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); 
    131                             CFDictionarySetValue(finalDeps, cfdep, deparray); 
    132                             CFRelease(deparray); // still retained by dict 
    133                           } 
    134                           if(!CFArrayContainsValue(deparray, 
    135                                                    CFRangeMake(0, CFArrayGetCount(deparray)), 
    136                                                    cfval)) { 
    137                             CFArrayAppendValue(deparray, cfval); 
    138                           } 
    139                           CFRelease(cfdep); 
    140                           CFRelease(cfval); 
    141                         } 
    142121                } else { 
    143122                        *unresolvedCount += 1; 
     
    145124        } 
    146125 
    147         if(commit) { 
    148           DBSetProp(cfstr(build), cfstr(project), CFSTR("dependencies"), finalDeps); 
    149         } 
    150  
    151         if (SQL("COMMIT")) { return -1; } 
    152          
    153         CFRelease(finalDeps); 
    154126        CFRelease(files); 
    155127        CFRelease(types); 
     128 
     129        // If committing, merge resolved dependencies to the dependencies property dictionary. 
     130        // Deletes resolved dependencies after they are processed. 
     131        if (commit) { 
     132                CFMutableArrayRef types = CFArrayCreateMutable(NULL, 0, &cfArrayCStringCallBacks); 
     133                CFMutableArrayRef projs = CFArrayCreateMutable(NULL, 0, &cfArrayCStringCallBacks); 
     134                CFMutableArrayRef params[2] = { projs, types }; 
     135                CFMutableDictionaryRef dependencies = (CFMutableDictionaryRef)DBCopyPropDictionary(cfstr(build), cfstr(project), CFSTR("dependencies")); 
     136                if (dependencies == NULL) { 
     137                        dependencies = CFDictionaryCreateMutable(NULL, 0, 
     138                                                                     &kCFCopyStringDictionaryKeyCallBacks, 
     139                                                                     &kCFTypeDictionaryValueCallBacks); 
     140                } 
     141                 
     142                SQL_CALLBACK(&addToCStrArrays, params, 
     143                        "SELECT DISTINCT dependency,type FROM dependencies WHERE build=%Q AND project=%Q", 
     144                        build, project); 
     145                 
     146                CFIndex i, count = CFArrayGetCount(projs); 
     147                for (i = 0; i < count; ++i) { 
     148                        CFStringRef proj = cfstr(CFArrayGetValueAtIndex(projs, i)); 
     149                        CFStringRef type = cfstr(CFArrayGetValueAtIndex(types, i)); 
     150                         
     151                        CFMutableArrayRef deparray = (CFMutableArrayRef)CFDictionaryGetValue(dependencies, type); 
     152                        if (deparray == NULL) { 
     153                                deparray = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); 
     154                                CFDictionarySetValue(dependencies, type, deparray); 
     155                                CFRelease(deparray); // still retained by dict 
     156                        } 
     157                        if (!CFArrayContainsValue(deparray, 
     158                                                        CFRangeMake(0, CFArrayGetCount(deparray)), 
     159                                                        proj)) { 
     160                                CFArrayAppendValue(deparray, proj); 
     161                        } 
     162                        CFRelease(proj); 
     163                        CFRelease(type); 
     164                } 
     165                 
     166                DBSetProp(cfstr(build), cfstr(project), CFSTR("dependencies"), dependencies); 
     167                CFRelease(dependencies); 
     168                CFRelease(types); 
     169                CFRelease(projs); 
     170 
     171                SQL("DELETE FROM dependencies WHERE build=%Q AND project=%Q", build, project); 
     172        } 
     173 
     174        if (SQL("COMMIT")) { return -1; } 
    156175} 
    157176