Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MRR support, read build configs, and other small changes #16

Merged
merged 28 commits into from
Aug 31, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f625da8
Start to de-arc-ify, and, remove logging from main project
Aug 15, 2012
5fe2e60
Add target file for ninja
Aug 15, 2012
f81f3cc
There can be multiple groups at the root level, not just one. This is…
Aug 15, 2012
1e3eccc
recursively add files, instead of hardcoding multiple paths
Aug 16, 2012
6a500d0
mutableCopy instead of addObjectsFromArray
Aug 16, 2012
c07d5b1
cache XCGroup's in groupWithKey:
Aug 16, 2012
f4995be
resource path isn't always project path + filename
Aug 17, 2012
0743b03
Don't sort member objects -- matching Xcode's list is good
Aug 18, 2012
aeae249
Adds resources getter to XCTarget
felixLam Aug 9, 2012
01ca6d6
Adds support for resources in XCTarget
felixLam Aug 17, 2012
ff551fa
remove ARC reference from the readme
Aug 18, 2012
1b0cf9e
Don't call a method that doesn't exist
Aug 18, 2012
ae91c72
Fix a leak
Aug 18, 2012
bce8c24
implement dealloc
Aug 18, 2012
fb31aa8
Less weak references
Aug 18, 2012
32f4151
Even less sorting and more sticking with what Xcode says
Aug 18, 2012
a8790b4
Rudimentary support for reading build configurations
Aug 19, 2012
89666cb
spaces instead of tabs, and even more changes to match Xcode's behavi…
Aug 19, 2012
1ccddcc
#import to silence a warning
Aug 19, 2012
12a998f
Also check project + path, in addition to the path by itself, group +…
Aug 25, 2012
c448358
Fix a bunch of potential memory errors
Aug 26, 2012
fa237fc
final leak fix
Aug 26, 2012
6a18a16
Fix an overrelease, a leak, and convert tabs to spaces
Aug 27, 2012
978df85
Changes to build in MRR and ARC, instead of one or the other
Aug 27, 2012
d407ac0
Update readme
Aug 27, 2012
eab0da8
Merge
Aug 27, 2012
40dcdaa
Don't ever reuse the var used for enumeration; clang doesn't like thi…
Aug 27, 2012
bd450f1
Use workingSetting for getting string length, to avoid oob issues whe…
Aug 28, 2012
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ If you're using the API shoot me an email and tell me what you're doing with it.

* Xcode-editor has been tested on Xcode 4+. It should also work on earlier versions of Xcode.
* The AppCode IDE from JetBrains is now supported too!
* Uses ARC and weak references so requires OSX 64 bit, and iOS 5. (Non ARC version coming soon.)

* Supports both ARC and MRR modes of memory management.

# Who's using it?

Expand Down
3 changes: 2 additions & 1 deletion Source/Main/Utils/XCKeyBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
////////////////////////////////////////////////////////////////////////////////

#import "XCKeyBuilder.h"
#import "XCMemoryUtils.h"

@implementation XCKeyBuilder

/* ================================================= Class Methods ================================================== */
+ (XCKeyBuilder*) forItemNamed:(NSString*)name {
NSData* data = [name dataUsingEncoding:NSUTF8StringEncoding];
return [[XCKeyBuilder alloc] initHashValueMD5HashWithBytes:[data bytes] length:[data length]];
return XCAutorelease([[XCKeyBuilder alloc] initHashValueMD5HashWithBytes:[data bytes] length:[data length]]);

}

Expand Down
24 changes: 24 additions & 0 deletions Source/Main/Utils/XCMemoryUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
////////////////////////////////////////////////////////////////////////////////
//
// EXPANZ
// Copyright 2008-2011 EXPANZ
// All Rights Reserved.
//
// NOTICE: Expanz permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#if !defined(__has_feature) || !__has_feature(objc_arc)
#define XCAutorelease(__var) [__var autorelease];
#define XCRetain(__var) [__var retain];
#define XCRetainAutorelease(__var) [[__var retain] autorelease];
#define XCRelease(__var) [__var release];
#define XCSuperDealloc [super dealloc];
#else
#define XCAutorelease(__var) (__var);
#define XCRetain(__var) (__var);
#define XCRetainAutorelease(__var) (__var);
#define XCRelease(__var) (void)(__var);
#define XCSuperDealloc
#endif
28 changes: 28 additions & 0 deletions Source/Main/XCBuildConfigurationList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
////////////////////////////////////////////////////////////////////////////////
//
// EXPANZ
// Copyright 2012 Zach Drayer
// All Rights Reserved.
//
// NOTICE: Zach Drayer permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

@class XCProject;

@interface XCBuildConfigurationList : NSObject {
@private
NSMutableDictionary *_buildSettings;
NSMutableDictionary *_xcconfigSettings;
}

+ (NSDictionary *) buildConfigurationsFromDictionary:(NSDictionary *) dictionary inProject:(XCProject *) project;

@property (nonatomic, readonly) NSDictionary *specifiedBuildSettings;

- (void) addXCConfigAtPath:(NSString *) path;
- (void) addBuildSettings:(NSDictionary *) buildSettings;

- (NSString *) valueForKey:(NSString *) key;
@end
146 changes: 146 additions & 0 deletions Source/Main/XCBuildConfigurationList.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
////////////////////////////////////////////////////////////////////////////////
//
// EXPANZ
// Copyright 2012 Zach Drayer
// All Rights Reserved.
//
// NOTICE: Zach Drayer permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

#import "XCBuildConfigurationList.h"
#import "XCGroup.h"
#import "XCProject.h"
#import "XCSourceFile.h"
#import "Utils/XCMemoryUtils.h"

@implementation XCBuildConfigurationList
+ (NSDictionary *) buildConfigurationsFromDictionary:(NSDictionary *) dictionary inProject:(XCProject *) project {
NSMutableDictionary *configurations = [NSMutableDictionary dictionary];

for (NSString* buildConfigurationKey in dictionary) {
NSDictionary* buildConfiguration = [[project objects] objectForKey:buildConfigurationKey];

if ([[buildConfiguration valueForKey:@"isa"] asMemberType] == XCBuildConfiguration) {
XCBuildConfigurationList *configuration = [configurations objectForKey:[buildConfiguration objectForKey:@"name"]];
if (!configuration) {
configuration = [[XCBuildConfigurationList alloc] init];

[configurations setObject:configuration forKey:[buildConfiguration objectForKey:@"name"]];
}


XCSourceFile *configurationFile = [project fileWithKey:[buildConfiguration objectForKey:@"baseConfigurationReference"]];
if (configurationFile) {
NSString *path = configurationFile.path;

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
XCGroup *group = [project groupWithSourceFile:configurationFile];
path = [[group pathRelativeToParent] stringByAppendingPathComponent:path];
}

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
path = [[[project filePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:path];
}

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
path = [[[project filePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:configurationFile.path];
}

if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
[NSException raise:@"XCConfig not found" format:@"Unable to find XCConfig file at %@", path];
}

[configuration addXCConfigAtPath:path];
}

[configuration addBuildSettings:[buildConfiguration objectForKey:@"buildSettings"]];
}
}

return configurations;
}

#pragma mark -

- (id) init {
if (!(self = [super init]))
return nil;

_buildSettings = [[NSMutableDictionary alloc] init];
_xcconfigSettings = [[NSMutableDictionary alloc] init];

return self;
}

- (void) dealloc {
XCRelease(_buildSettings)
XCRelease(_xcconfigSettings)

XCSuperDealloc
}

#pragma mark -

- (NSString *) description {
NSMutableString *description = [[super description] mutableCopy];

[description appendFormat:@"build settings: %@, inherited: %@", _buildSettings, _xcconfigSettings];

return XCAutorelease(description);
}

#pragma mark -

- (NSDictionary *) specifiedBuildSettings {
return XCAutorelease([_buildSettings copy])
}

#pragma mark -

- (void) addXCConfigAtPath:(NSString *) path {
path = [[path stringByResolvingSymlinksInPath] stringByExpandingTildeInPath];

if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

for (NSString *setting in [contents componentsSeparatedByString:@"\n"]) {
// rudimentary #include support
NSString *workingSetting = [setting stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

NSRange range = [workingSetting rangeOfString:@"#include" options:NSAnchoredSearch range:NSMakeRange(0, workingSetting.length)];

if (range.location != NSNotFound) {
workingSetting = [workingSetting substringFromIndex:@"#include \"".length];

[self addXCConfigAtPath:[setting substringToIndex:(setting.length - 1)]];
} else {
NSArray *parts = [setting componentsSeparatedByString:@"="];
if (parts.count == 2) {
// XCConfig files can be used to unset properties, a la `FOO=`
// so, we have to be able to insert blank (but non-nil) values into the dictionary
NSString *key = [[parts objectAtIndex:0] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *value = [[parts objectAtIndex:1] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

[_xcconfigSettings setObject:value forKey:key];
}
}
}
}
}

#pragma mark -

- (void) addBuildSettings:(NSDictionary *) buildSettings {
[_xcconfigSettings removeObjectsForKeys:[buildSettings allKeys]];
[_buildSettings addEntriesFromDictionary:buildSettings];
}

- (NSString *) valueForKey:(NSString *) key {
NSString *value = [_buildSettings objectForKey:key];
if (!value)
value = [_xcconfigSettings objectForKey:key];
return value;
}
@end
13 changes: 11 additions & 2 deletions Source/Main/XCClassDefinition.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
////////////////////////////////////////////////////////////////////////////////

#import "XCClassDefinition.h"
#import "Utils/XCMemoryUtils.h"

@implementation XCClassDefinition

Expand All @@ -20,11 +21,11 @@ @implementation XCClassDefinition

/* ================================================= Class Methods ================================================== */
+ (XCClassDefinition*) classDefinitionWithName:(NSString*)fileName {
return [[XCClassDefinition alloc] initWithName:fileName];
return XCAutorelease([[XCClassDefinition alloc] initWithName:fileName])
}

+ (XCClassDefinition*) classDefinitionWithName:(NSString*)className language:(ClassDefinitionLanguage)language {
return [[XCClassDefinition alloc] initWithName:className language:language];
return XCAutorelease([[XCClassDefinition alloc] initWithName:className language:language])
}


Expand All @@ -46,6 +47,14 @@ - (id) initWithName:(NSString*)className language:(ClassDefinitionLanguage)langu
return self;
}

/* ================================================== Deallocation ================================================== */
- (void) dealloc {
XCRelease(_className)
XCRelease(_header)
XCRelease(_source)

XCSuperDealloc
}

/* ================================================ Interface Methods =============================================== */
- (BOOL) isObjectiveC {
Expand Down
16 changes: 11 additions & 5 deletions Source/Main/XCFileOperationQueue.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
////////////////////////////////////////////////////////////////////////////////

#import "XCFileOperationQueue.h"
#import "OCLogTemplate.h"
#import "Utils/XCMemoryUtils.h"

@interface XCFileOperationQueue ()

Expand Down Expand Up @@ -42,6 +42,16 @@ - (id) initWithBaseDirectory:(NSString*)baseDirectory {
return self;
}

/* ================================================== Deallocation ================================================== */
- (void) dealloc {
XCRelease(_baseDirectory)
XCRelease(_filesToWrite)
XCRelease(_frameworksToCopy)
XCRelease(_filesToDelete)
XCRelease(_directoriesToCreate)

XCSuperDealloc
}
/* ================================================ Interface Methods =============================================== */
- (BOOL) fileWithName:(NSString*)name existsInProjectDirectory:(NSString*)directory {
NSString* filePath = [self destinationPathFor:name inProjectDirectory:directory];
Expand Down Expand Up @@ -69,7 +79,6 @@ - (void) queueFrameworkWithFilePath:(NSString*)filePath inDirectory:(NSString*)d
}

- (void) queueDeletion:(NSString*)filePath {
LogDebug(@"Queing deletion for path: %@", filePath);
[_filesToDelete addObject:filePath];
}

Expand Down Expand Up @@ -111,7 +120,6 @@ - (void) performCopyFrameworks {
}
NSError* error = nil;
if (![fileManager copyItemAtURL:frameworkPath toURL:destinationUrl error:&error]) {
LogDebug(@"User info: %@", [error userInfo]);
[NSException raise:NSInternalInconsistencyException format:@"Error writing file at filePath: %@",
[frameworkPath absoluteString]];
}
Expand All @@ -120,8 +128,6 @@ - (void) performCopyFrameworks {
}

- (void) performFileDeletions {
LogDebug(@"Files to delete: %@", _filesToDelete);

for (NSString* filePath in [_filesToDelete reverseObjectEnumerator]) {
NSString* fullPath = [_baseDirectory stringByAppendingPathComponent:filePath];
NSError* error = nil;
Expand Down
9 changes: 7 additions & 2 deletions Source/Main/XCFrameworkDefinition.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
//
////////////////////////////////////////////////////////////////////////////////
#import "XCFrameworkDefinition.h"

#import "Utils/XCMemoryUtils.h"

@implementation XCFrameworkDefinition

Expand All @@ -20,7 +20,7 @@ @implementation XCFrameworkDefinition
+ (XCFrameworkDefinition*) frameworkDefinitionWithFilePath:(NSString*)filePath
copyToDestination:(BOOL)copyToDestination {

return [[XCFrameworkDefinition alloc] initWithFilePath:filePath copyToDestination:copyToDestination];
return XCAutorelease([[XCFrameworkDefinition alloc] initWithFilePath:filePath copyToDestination:copyToDestination])
}


Expand All @@ -40,5 +40,10 @@ - (NSString*) name {
}


/* ================================================== Deallocation ================================================== */
- (void) dealloc {
XCRelease(_filePath)

XCSuperDealloc
}
@end
4 changes: 2 additions & 2 deletions Source/Main/XCGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
NSMutableArray* _children;
NSMutableArray* _members;

__weak XCFileOperationQueue* _fileOperationQueue;
__weak XCProject* _project;
XCFileOperationQueue* _fileOperationQueue; // weak
XCProject* _project;

}

Expand Down
Loading