| 1 |
/* |
| 2 |
Copyright (C) 2018, 2019, 2020, 2021 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
Written by: Gregory John Casamento <[email protected]> |
| 5 |
Date: 2022 |
| 6 |
|
| 7 |
This file is part of the GNUstep XCode Library |
| 8 |
|
| 9 |
This library is free software; you can redistribute it and/or |
| 10 |
modify it under the terms of the GNU Lesser General Public |
| 11 |
License as published by the Free Software Foundation; either |
| 12 |
version 2 of the License, or (at your option) any later version. |
| 13 |
|
| 14 |
This library is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
Lesser General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU Lesser General Public |
| 20 |
License along with this library; if not, write to the Free |
| 21 |
Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 22 |
Boston, MA 02110 USA. |
| 23 |
*/ #import "PBXCommon.h" |
| 24 |
#import "PBXVariantGroup.h" |
| 25 |
#import "PBXGroup.h" |
| 26 |
#import "PBXFileReference.h" |
| 27 |
#import "GSXCBuildContext.h" |
| 28 |
|
| 29 |
@implementation PBXVariantGroup |
| 30 |
|
| 31 |
// Methods.... |
| 32 |
- (NSString *) sourceTree // getter |
| 33 |
{ |
| 34 |
return sourceTree; |
| 35 |
} |
| 36 |
|
| 37 |
- (void) setSourceTree: (NSString *)object; // setter |
| 38 |
{ |
| 39 |
ASSIGN(sourceTree,object); |
| 40 |
} |
| 41 |
|
| 42 |
- (NSString *) path // getter |
| 43 |
{ |
| 44 |
return path; |
| 45 |
} |
| 46 |
|
| 47 |
- (void) setPath: (NSString *)object; // setter |
| 48 |
{ |
| 49 |
ASSIGN(path,object); |
| 50 |
} |
| 51 |
|
| 52 |
- (NSMutableArray *) children // getter |
| 53 |
{ |
| 54 |
return children; |
| 55 |
} |
| 56 |
|
| 57 |
- (void) setChildren: (NSMutableArray *)object; // setter |
| 58 |
{ |
| 59 |
ASSIGN(children,object); |
| 60 |
} |
| 61 |
|
| 62 |
- (NSString *) name // getter |
| 63 |
{ |
| 64 |
return name; |
| 65 |
} |
| 66 |
|
| 67 |
- (void) setName: (NSString *)object; // setter |
| 68 |
{ |
| 69 |
ASSIGN(name,object); |
| 70 |
} |
| 71 |
|
| 72 |
- (NSString *) resolvePathFor: (id)object |
| 73 |
withGroup: (PBXGroup *)group |
| 74 |
found: (BOOL *)found |
| 75 |
{ |
| 76 |
NSString *result = @""; |
| 77 |
NSArray *chldren = [group children]; |
| 78 |
NSEnumerator *en = [chldren objectEnumerator]; |
| 79 |
id file = nil; |
| 80 |
while((file = [en nextObject]) != nil && *found == NO) |
| 81 |
{ |
| 82 |
if(file == self) // have we found ourselves?? |
| 83 |
{ |
| 84 |
PBXFileReference *fileRef = [[file children] objectAtIndex: 0]; // FIXME: Assume english for now... |
| 85 |
NSString *filePath = ([fileRef path] == nil)?@"":[[fileRef path] lastPathComponent]; |
| 86 |
result = filePath; |
| 87 |
*found = YES; |
| 88 |
break; |
| 89 |
} |
| 90 |
else if([file isKindOfClass: [PBXGroup class]]) |
| 91 |
{ |
| 92 |
NSString *filePath = ([file path] == nil)?@"":[file path]; // lastPathComponent]; |
| 93 |
result = [filePath stringByAppendingPathComponent: |
| 94 |
[self resolvePathFor: object |
| 95 |
withGroup: file |
| 96 |
found: found]]; |
| 97 |
} |
| 98 |
} |
| 99 |
return result; |
| 100 |
} |
| 101 |
|
| 102 |
- (NSString *) buildPath |
| 103 |
{ |
| 104 |
PBXGroup *mainGroup = [[GSXCBuildContext sharedBuildContext] objectForKey: @"MAIN_GROUP"]; |
| 105 |
BOOL found = NO; |
| 106 |
NSString *result = nil; |
| 107 |
|
| 108 |
// Resolve path for the current file reference... |
| 109 |
result = [self resolvePathFor: self |
| 110 |
withGroup: mainGroup |
| 111 |
found: &found]; |
| 112 |
|
| 113 |
return result; |
| 114 |
} |
| 115 |
|
| 116 |
- (NSString *) description |
| 117 |
{ |
| 118 |
return [NSString stringWithFormat: @"%@ - %@, %@, %@, %@", [super description], name, path, sourceTree, children]; |
| 119 |
} |
| 120 |
@end |