Skip to content

Commit

Permalink
Allow adding C++ files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasperblues committed Jun 12, 2012
1 parent 34301b9 commit d36dbae
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 55 deletions.
3 changes: 2 additions & 1 deletion Source/Main/XcodeSourceFileType.h
Expand Up @@ -15,7 +15,8 @@ typedef enum {
PropertyList, // .plist
SourceCodeHeader, // .h
SourceCodeObjC, // .m
SourceCodeObjCPlusPlus, // .mm
SourceCodeObjCPlusPlus, // .mm
SourceCodeCPlusPlus, // .cpp
XibFile, // .xib
ImageResourcePNG, // .png
Bundle, // .bundle .octet
Expand Down
1 change: 1 addition & 0 deletions Source/Main/XcodeSourceFileType.m
Expand Up @@ -22,6 +22,7 @@ + (NSDictionary*) dictionaryWithFileReferenceTypesAsStrings {
boxEnum(Framework), @"wrapper.framework",
boxEnum(PropertyList), @"text.plist.strings",
boxEnum(SourceCodeObjCPlusPlus), @"sourcecode.cpp.objcpp",
boxEnum(SourceCodeCPlusPlus), @"sourcecode.cpp.cpp",
boxEnum(XibFile), @"file.xib",
boxEnum(ImageResourcePNG), @"image.png",
boxEnum(Bundle), @"wrapper.cfbundle",
Expand Down
5 changes: 4 additions & 1 deletion Source/Main/xcode_ClassDefinition.h
Expand Up @@ -15,6 +15,7 @@
typedef enum {
ObjectiveC,
ObjectiveCPlusPlus,
CPlusPlus,
} ClassDefinitionLanguage;

@interface xcode_ClassDefinition : xcode_AbstractDefinition {
Expand Down Expand Up @@ -49,11 +50,13 @@ typedef enum {

- (BOOL) isObjectiveCPlusPlus;

- (BOOL) isCPlusPlus;

- (NSString*) headerFileName;

- (NSString*) sourceFileName;

@end

/* ================================================================================================================== */
@compatibility_alias ClassDefinition xcode_ClassDefinition;
@compatibility_alias ClassDefinition xcode_ClassDefinition;
11 changes: 9 additions & 2 deletions Source/Main/xcode_ClassDefinition.m
Expand Up @@ -37,7 +37,7 @@ - (id) initWithName:(NSString*)className language:(ClassDefinitionLanguage)langu
self = [super init];
if (self) {
_className = [className copy];
if (!(language == ObjectiveC || language == ObjectiveCPlusPlus)) {
if (!(language == ObjectiveC || language == ObjectiveCPlusPlus || language == CPlusPlus)) {
[NSException
raise:NSInvalidArgumentException format:@"Language must be one of ObjectiveC, ObjectiveCPlusPlus"];
}
Expand All @@ -56,6 +56,10 @@ - (BOOL) isObjectiveCPlusPlus {
return _language == ObjectiveCPlusPlus;
}

- (BOOL) isCPlusPlus{
return _language == CPlusPlus;
}

- (NSString*) headerFileName {
return [_className stringByAppendingString:@".h"];

Expand All @@ -69,8 +73,11 @@ - (NSString*) sourceFileName {
else if ([self isObjectiveCPlusPlus]) {
sourceFileName = [_className stringByAppendingString:@".mm"];
}
else if([self isCPlusPlus]){
sourceFileName = [_className stringByAppendingString:@".cpp"];
}
return sourceFileName;
}


@end
@end
23 changes: 14 additions & 9 deletions Source/Main/xcode_Group.m
Expand Up @@ -21,6 +21,7 @@
#import "xcode_SourceFileDefinition.h"

#import "Logging.h"

/* ================================================================================================================== */
@interface xcode_Group ()

Expand All @@ -40,6 +41,7 @@ - (XcodeMemberType) typeForKey:(NSString*)key;
- (void) addSourceFile:(SourceFile*)sourceFile toTargets:(NSArray*)targets;

@end

/* ================================================================================================================== */

@implementation xcode_Group
Expand All @@ -50,7 +52,6 @@ @implementation xcode_Group
@synthesize alias = _alias;



/* ================================================= Class Methods ================================================== */
+ (Group*) groupWithProject:(xcode_Project*)project key:(NSString*)key alias:(NSString*)alias path:(NSString*)path
children:(NSArray*)children {
Expand Down Expand Up @@ -120,9 +121,10 @@ - (BOOL) isRootGroup {

- (void) addClass:(ClassDefinition*)classDefinition {


[self makeGroupMemberWithName:[classDefinition headerFileName] contents:[classDefinition header]
type:SourceCodeHeader fileOperationStyle:[classDefinition fileOperationStyle]];
if ([classDefinition header]) {
[self makeGroupMemberWithName:[classDefinition headerFileName] contents:[classDefinition header]
type:SourceCodeHeader fileOperationStyle:[classDefinition fileOperationStyle]];
}

if ([classDefinition isObjectiveC]) {
[self makeGroupMemberWithName:[classDefinition sourceFileName] contents:[classDefinition source]
Expand All @@ -132,6 +134,10 @@ - (void) addClass:(ClassDefinition*)classDefinition {
[self makeGroupMemberWithName:[classDefinition sourceFileName] contents:[classDefinition source]
type:SourceCodeObjCPlusPlus fileOperationStyle:[classDefinition fileOperationStyle]];
}
else if ([classDefinition isCPlusPlus]) {
[self makeGroupMemberWithName:[classDefinition sourceFileName] contents:[classDefinition source]
type:SourceCodeCPlusPlus fileOperationStyle:[classDefinition fileOperationStyle]];
}

[[_project objects] setObject:[self asDictionary] forKey:_key];
}
Expand All @@ -145,7 +151,6 @@ - (void) addClass:(ClassDefinition*)classDefinition toTargets:(NSArray*)targets

- (void) addFramework:(FrameworkDefinition*)frameworkDefinition {
if (([self memberWithDisplayName:[frameworkDefinition name]]) == nil) {
LogDebug(@"Here we go!!!!");
NSDictionary* fileReference;
if ([frameworkDefinition copyToDestination]) {
LogDebug(@"Making file reference");
Expand All @@ -156,8 +161,8 @@ - (void) addFramework:(FrameworkDefinition*)frameworkDefinition {
}
else if ([frameworkDefinition fileOperationStyle] == FileOperationStyleAcceptExisting) {
NSString* frameworkName = [[frameworkDefinition filePath] lastPathComponent];
if (![_fileOperationQueue
fileWithName:frameworkName existsInProjectDirectory:[self pathRelativeToProjectRoot]]) {
if (![_fileOperationQueue fileWithName:frameworkName
existsInProjectDirectory:[self pathRelativeToProjectRoot]]) {
copyFramework = YES;
}

Expand Down Expand Up @@ -387,14 +392,14 @@ - (void) makeGroupMemberWithName:(NSString*)name contents:(id)contents type:(Xco
if (fileOperationStyle == FileOperationStyleOverwrite) {
writeFile = YES;
if ([_fileOperationQueue fileWithName:name existsInProjectDirectory:filePath]) {
LogInfo(@"*** WARNING *** Group %@ already contains member with name %@. Contents will be updated", [self
displayName], name);
LogInfo(@"*** WARNING *** Group %@ already contains member with name %@. Contents will be updated", [self displayName], name);
}
}
else if (fileOperationStyle == FileOperationStyleAcceptExisting &&
![_fileOperationQueue fileWithName:name existsInProjectDirectory:filePath]) {
writeFile = YES;
}
//TODO: Fix this hack. Should use polymorphism or something.
if (writeFile) {
if ([contents isKindOfClass:[NSString class]]) {
[_fileOperationQueue queueTextFile:name inDirectory:filePath withContents:contents];
Expand Down
2 changes: 2 additions & 0 deletions Source/Main/xcode_SourceFile.h
Expand Up @@ -54,6 +54,8 @@

- (BOOL) canBecomeBuildFile;

- (XcodeMemberType) buildPhase;

- (NSString*) buildFileKey;

/**
Expand Down
32 changes: 24 additions & 8 deletions Source/Main/xcode_SourceFile.m
Expand Up @@ -64,10 +64,29 @@ - (BOOL) isBuildFile {
}

- (BOOL) canBecomeBuildFile {
return _type == SourceCodeObjC || _type == SourceCodeObjCPlusPlus || _type == XibFile || _type == Framework || _type == ImageResourcePNG || _type == HTML || _type == Bundle || _type == Archive;
return _type == SourceCodeObjC || _type == SourceCodeObjCPlusPlus || _type == SourceCodeCPlusPlus || _type ==
XibFile || _type == Framework || _type == ImageResourcePNG || _type == HTML || _type == Bundle || _type ==
Archive;
}


- (XcodeMemberType) buildPhase {
if (_type == SourceCodeObjC || _type == SourceCodeObjCPlusPlus || _type == SourceCodeCPlusPlus || _type ==
XibFile) {
return PBXSourcesBuildPhase;
}
else if (_type == Framework) {
return PBXFrameworksBuildPhase;
}
else if (_type == ImageResourcePNG || _type == HTML || _type == Bundle) {
return PBXResourcesBuildPhase;
}
else if (_type == Archive) {
return PBXFrameworksBuildPhase;
}
return PBXNilType;
}

- (NSString*) buildFileKey {
if (_buildFileKey == nil) {
[[_project objects] enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSDictionary* obj, BOOL* stop) {
Expand All @@ -84,7 +103,6 @@ - (NSString*) buildFileKey {


- (void) becomeBuildFile {
LogDebug(@"$$$$$$$$$$$$$$$$$ Start becoming build file");
if (![self isBuildFile]) {
if ([self canBecomeBuildFile]) {
NSMutableDictionary* sourceBuildFile = [NSMutableDictionary dictionary];
Expand All @@ -97,11 +115,11 @@ - (void) becomeBuildFile {
[NSException raise:NSInvalidArgumentException format:@"Add framework to target not implemented yet."];
}
else {
[NSException raise:NSInvalidArgumentException format:@"Project file of type %@ can't become a build file.",
[NSString stringFromSourceFileType:_type]];
[NSException raise:NSInvalidArgumentException
format:@"Project file of type %@ can't become a build file.", [NSString stringFromSourceFileType:_type]];
}

}LogDebug(@"Done becoming build file");
}
}

/* ================================================= Protocol Methods =============================================== */
Expand All @@ -127,10 +145,8 @@ - (NSString*) pathRelativeToProjectRoot {

/* ================================================== Utility Methods =============================================== */
- (NSString*) description {
return [NSString stringWithFormat:@"Project file: key=%@, name=%@, fullPath=%@", _key, _name,
[self pathRelativeToProjectRoot]];
return [NSString stringWithFormat:@"Project file: key=%@, name=%@, fullPath=%@", _key, _name, [self pathRelativeToProjectRoot]];
}



@end
25 changes: 1 addition & 24 deletions Source/Main/xcode_Target.m
Expand Up @@ -20,8 +20,6 @@ - (SourceFile*) buildFileWithKey:(NSString*)key;

- (void) flagMembersAsDirty;

- (XcodeMemberType) buildPhaseFor:(SourceFile*)sourceFile;

@end


Expand Down Expand Up @@ -75,7 +73,7 @@ - (void) addMember:(xcode_SourceFile*)member {

for (NSString* buildPhaseKey in [target objectForKey:@"buildPhases"]) {
NSMutableDictionary* buildPhase = [[_project objects] objectForKey:buildPhaseKey];
if ([[buildPhase valueForKey:@"isa"] asMemberType] == [self buildPhaseFor:member]) {
if ([[buildPhase valueForKey:@"isa"] asMemberType] == [member buildPhase]) {

NSMutableArray* files = [buildPhase objectForKey:@"files"];
if (![files containsObject:[member buildFileKey]]) {
Expand Down Expand Up @@ -161,25 +159,4 @@ - (void) flagMembersAsDirty {
}


- (XcodeMemberType) buildPhaseFor:(SourceFile*)sourceFile {
if (sourceFile.type == SourceCodeObjC || sourceFile.type == SourceCodeObjCPlusPlus || sourceFile.type == XibFile) {
return PBXSourcesBuildPhase;
}
else if (sourceFile.type == Framework) {
return PBXFrameworksBuildPhase;
}
else if (sourceFile.type == ImageResourcePNG || sourceFile.type == HTML || sourceFile.type == Bundle) {
return PBXResourcesBuildPhase;
}
else if (sourceFile.type == Archive) {
return PBXFrameworksBuildPhase;
}

else {
NSString* type = [NSString stringFromSourceFileType:[sourceFile type]];
[NSException raise:NSInternalInconsistencyException format:@"Type %@ cannot be added to a target.", type];
}
return 0;
}

@end

0 comments on commit d36dbae

Please sign in to comment.