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

Fixes around finding paths to files in the project. #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions Source/XCGroup.m
Original file line number Diff line number Diff line change
Expand Up @@ -489,15 +489,18 @@ - (NSString *)pathRelativeToProjectRoot
XCGroup *group = nil;
NSString *key = [_key copy];

while ((group = [_project groupForGroupMemberWithKey:key]) != nil && [group pathRelativeToParent] != nil) {
[pathComponents addObject:[group pathRelativeToParent]];
while ((group = [_project groupForGroupMemberWithKey:key]) != nil) {
if ([group pathRelativeToParent] != nil) {
[pathComponents addObject:[group pathRelativeToParent]];
}
key = [[group key] copy];
}

NSMutableString *fullPath = [[NSMutableString alloc] init];
for (NSInteger i = (NSInteger) [pathComponents count] - 1; i >= 0; i--) {
[fullPath appendFormat:@"%@/", pathComponents[i]];
}

_pathRelativeToProjectRoot = [[fullPath stringByAppendingPathComponent:_pathRelativeToParent] copy];
}
return _pathRelativeToProjectRoot;
Expand Down
25 changes: 23 additions & 2 deletions Source/XCSourceFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,29 @@ - (NSString *)displayName

- (NSString *)pathRelativeToProjectRoot
{
NSString *parentPath = [[_project groupForGroupMemberWithKey:_key] pathRelativeToProjectRoot];
NSString *result = [parentPath stringByAppendingPathComponent:_name];
NSString *result = nil;
if ([_sourceTree isEqualToString:@"<group>"]) {
NSString *component = nil;
if (_path) {
component = _path;
} else if (_name) {
component = _name;
}
NSString *parentPath = [[_project groupForGroupMemberWithKey:_key] pathRelativeToProjectRoot];
result = [parentPath stringByAppendingPathComponent:component];
} else if ([_sourceTree isEqualToString:@"SOURCE_ROOT"]) {
if (_path) {
result = _path;
} else if (_name) {
result = _name;
}
} else if ([_sourceTree isEqualToString:@"SDKROOT"]) {
//pass
} else if ([_sourceTree isEqualToString:@"BUILT_PRODUCTS_DIR"]) {
// pass
} else {
result = _sourceTree;
}
return result;
}

Expand Down
7 changes: 6 additions & 1 deletion XcodeEditor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
49EE86B01C95EF8200CBF750 /* PathRelativeToProjectRoot.zip in Resources */ = {isa = PBXBuildFile; fileRef = 49EE86AF1C95EF8200CBF750 /* PathRelativeToProjectRoot.zip */; };
5D5AC8761C6A423C00E5B3DA /* XCBuildShellScript.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D5AC8721C6A423C00E5B3DA /* XCBuildShellScript.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D5AC8771C6A423C00E5B3DA /* XCBuildShellScript.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D5AC8731C6A423C00E5B3DA /* XCBuildShellScript.m */; };
5D5AC8781C6A423C00E5B3DA /* XCBuildShellScriptDefinition.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D5AC8741C6A423C00E5B3DA /* XCBuildShellScriptDefinition.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -71,6 +72,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
49EE86AF1C95EF8200CBF750 /* PathRelativeToProjectRoot.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = PathRelativeToProjectRoot.zip; sourceTree = "<group>"; };
5D5AC8721C6A423C00E5B3DA /* XCBuildShellScript.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCBuildShellScript.h; sourceTree = "<group>"; };
5D5AC8731C6A423C00E5B3DA /* XCBuildShellScript.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XCBuildShellScript.m; sourceTree = "<group>"; };
5D5AC8741C6A423C00E5B3DA /* XCBuildShellScriptDefinition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCBuildShellScriptDefinition.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -284,6 +286,7 @@
BA7985135EB5AF8E8386EB89 /* ArchiveProj.zip */,
BA798180A5D76D64336BFF65 /* ProjectToEdit.zip */,
BA79818F51A7B4CA0077D3AE /* expanz-iOS-SDK.zip */,
49EE86AF1C95EF8200CBF750 /* PathRelativeToProjectRoot.zip */,
);
path = TestProjects;
sourceTree = "<group>";
Expand Down Expand Up @@ -644,6 +647,7 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 6BE8FDA31C01C190001EF5B3;
productRefGroup = 6BE8FDAE1C01C190001EF5B3 /* Products */;
Expand Down Expand Up @@ -671,6 +675,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
49EE86B01C95EF8200CBF750 /* PathRelativeToProjectRoot.zip in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -689,7 +694,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "#!/bin/bash\necho \"-------------- EXTRACTING TEST RESOURCES --------------\"\n\nrm -fr ~/xcode-editor-test-results\nmkdir -p ~/xcode-editor-test-results\n\nunzip XcodeEditorTests/Resources/TestProjects/expanz-iOS-SDK.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/ArchiveProj.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/HelloBoxy.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/ProjectToEdit.zip -d ~/xcode-editor-test-results\n\nfor f in XcodeEditorTests/Resources/Files/*; do cp $f ~/xcode-editor-test-results; done\n";
shellScript = "#!/bin/bash\necho \"-------------- EXTRACTING TEST RESOURCES --------------\"\n\nrm -fr ~/xcode-editor-test-results\nmkdir -p ~/xcode-editor-test-results\n\nunzip XcodeEditorTests/Resources/TestProjects/expanz-iOS-SDK.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/ArchiveProj.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/HelloBoxy.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/ProjectToEdit.zip -d ~/xcode-editor-test-results\nunzip XcodeEditorTests/Resources/TestProjects/PathRelativeToProjectRoot.zip -d ~/xcode-editor-test-results\n\nfor f in XcodeEditorTests/Resources/Files/*; do cp $f ~/xcode-editor-test-results; done\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
Binary file not shown.
4 changes: 4 additions & 0 deletions XcodeEditorTests/Utils/XCTestResourceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ NSString *XCMasterDetailContainerFolderPath(void);

NSString *XCMasterDetailProjectPath(void);

NSString *XCPathRelativeToProjectRootFolderPath(void);

NSString *XCPathRelativeToProjectRootProjectPath(void);


NSString *NSStringWithXCTestResource(NSString *resourceName);

Expand Down
10 changes: 10 additions & 0 deletions XcodeEditorTests/Utils/XCTestResourceUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
return [XCMasterDetailContainerFolderPath() stringByAppendingString:@"/ProjectToEdit.xcodeproj"];
}

NSString *XCPathRelativeToProjectRootFolderPath(void)
{
return [XCTestResourcePath() stringByAppendingString:@"/PathRelativeToProjectRoot"];
}

NSString *XCPathRelativeToProjectRootProjectPath(void)
{
return [XCPathRelativeToProjectRootFolderPath() stringByAppendingString:@"/PathRelativeToProjectRoot.xcodeproj"];
}

NSString *NSStringWithXCTestResource(NSString *resourceName)
{
NSString *filePath = [XCTestResourcePath() stringByAppendingPathComponent:resourceName];
Expand Down
22 changes: 21 additions & 1 deletion XcodeEditorTests/XCGroupTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,25 @@ - (void)test_allows_deleting_a_group_after_adding_contents
[project save];
}


- (void)test_finding_path_relative_to_project_root
{
XCProject *project = [[XCProject alloc] initWithFilePath:XCPathRelativeToProjectRootProjectPath()];
XCTarget *target = [project targetWithName:@"PathRelativeToProjectRoot"];
XCTAssertNotNil(target);

NSArray<XCSourceFile *> *files = [target members];
for (XCSourceFile *file in files) {
NSString *relativePath = [file pathRelativeToProjectRoot];
XCTAssertNotNil(relativePath);
if ([[relativePath lastPathComponent] isEqualToString:@"FileRelativeToProject.m"]) {
XCTAssertEqualObjects(@"foo/FileRelativeToProject.m", relativePath);
}
if ([[relativePath lastPathComponent] isEqualToString:@"FileRelativeToOwnProject.m"]) {
XCTAssertEqualObjects(@"PathRelativeToProjectRoot/Classes/FileRelativeToOwnProject.m", relativePath);
}
if ([[relativePath lastPathComponent] isEqualToString:@"FileRelativeToGroup.m"]) {
XCTAssertEqualObjects(@"PathRelativeToProjectRoot/Classes/FileRelativeToGroup.m", relativePath);
}
}
}
@end