static int run(CFArrayRef argv) { if (CFArrayGetCount(argv) > 1) return -1; CFStringRef build = DBGetCurrentBuild(); CFStringRef project = NULL; CFDictionaryRef projectEnv = NULL; CFDictionaryRef globalEnv = DBCopyPropDictionary(build, NULL, CFSTR("environment")); if (CFArrayGetCount(argv) == 1) { project = CFArrayGetValueAtIndex(argv, 0); projectEnv = DBCopyPropDictionary(build, project, CFSTR("environment")); } CFMutableDictionaryRef env = NULL; if (globalEnv && projectEnv) { env = (CFMutableDictionaryRef)mergeDictionaries(projectEnv, globalEnv); } else if (globalEnv) { env = (CFMutableDictionaryRef)globalEnv; } else if (projectEnv) { env = (CFMutableDictionaryRef)projectEnv; } else { return 0; } // Auto-generate some variables based on RC_ARCHS and RC_NONARCH_CFLAGS // RC_CFLAGS=$RC_NONARCH_CFLAGS -arch ${arch} // RC_${arch}=YES CFStringRef str = CFDictionaryGetValue(env, CFSTR("RC_NONARCH_CFLAGS")); if (!str) str = CFSTR(""); CFMutableStringRef cflags = CFStringCreateMutableCopy(NULL, 0, str); str = CFDictionaryGetValue(env, CFSTR("RC_ARCHS")); if (str) { CFMutableStringRef trimmed = CFStringCreateMutableCopy(NULL, 0, str); CFStringTrimWhitespace(trimmed); CFArrayRef archs = tokenizeString(trimmed); CFIndex i, count = CFArrayGetCount(archs); for (i = 0; i < count; ++i) { CFStringRef arch = CFArrayGetValueAtIndex(archs, i); // -arch ${arch} CFStringAppendFormat(cflags, NULL, CFSTR(" -arch %@"), arch); // RC_${arch}=YES CFStringRef name = CFStringCreateWithFormat(NULL, NULL, CFSTR("RC_%@"), arch); CFDictionarySetValue(env, name, CFSTR("YES")); CFRelease(name); } CFRelease(trimmed); } CFDictionarySetValue(env, CFSTR("RC_CFLAGS"), cflags); // print variables to stdout CFArrayRef keys = dictionaryGetSortedKeys(env); CFIndex i, count = CFArrayGetCount(keys); for (i = 0; i < count; ++i) { CFStringRef name = CFArrayGetValueAtIndex(keys, i); CFStringRef value = CFDictionaryGetValue(env, name); cfprintf(stdout, "%@=%@\n", name, value); } return 0; }
void IOFireWireUserClientIniter::mergeProperties( IORegistryEntry * dest, OSDictionary * src ) { //IOLog( "IOFireWireUserClientIniter<0x%08lx>::mergeProperties - dest = 0x%08lx, src = 0x%08lx\n", this, dest, src ); if( !dest || !src ) return; OSCollectionIterator* srcIterator = OSCollectionIterator::withCollection( src ); OSSymbol* keyObject = NULL; OSObject* destObject = NULL; OSObject* srcObject = NULL; while( NULL != (keyObject = OSDynamicCast(OSSymbol, srcIterator->getNextObject())) ) { srcObject = src->getObject(keyObject); destObject = dest->getProperty(keyObject); OSDictionary * destDictionary = OSDynamicCast( OSDictionary, destObject ); OSDictionary * srcDictionary = OSDynamicCast( OSDictionary, srcObject ); if( destDictionary && srcDictionary ) { // if there's already already a property defined in the destination // and the source and destination are dictionaries, we need to do // a recursive merge // shallow copy the destination directory destDictionary = OSDictionary::withDictionary( destDictionary ); // recurse mergeDictionaries( destDictionary, srcDictionary ); // set the property dest->setProperty( keyObject, destDictionary ); destDictionary->release(); } else { // if the property is not already in destination dictionary // or both source a destination are not dictionaries // then we can set the property without merging // any dictionaries in the source should already // have been deep copied before we began merging dest->setProperty( keyObject, srcObject ); } } // have to release this, or we'll leak. srcIterator->release(); //IOLog( "IOFireWireUserClientIniter<0x%08lx>::mergeProperties - return\n", this ); }