-
-
Notifications
You must be signed in to change notification settings - Fork 320
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
Fully qualified Names of source files #40
Comments
Do you mean the path to the file? If so you would have to traverse the groups it exists in, and build up the path that way. |
Thanks :) |
I've written a small example. Not sure if I got everything. Is there an option to separate by target?
|
What's your use case? Maybe there's a different way to achieve what you're after |
Thanks for your input. I'd still love to see a helper method for this :) Currently I'm trying to write some kind of IDE for iOS/OSX development. To get a list of all source files I'd love to import the Xcode.proj. This way I would know, which files are actually used and not just part of the structure. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This shouldn't be closed. Reopening. |
I'm using this code to get full path of file element: extension PBXProj.Objects {
func fullPath(fileElement: PBXFileElement, reference: String, sourceRoot: Path) -> Path? {
switch fileElement.sourceTree {
case .absolute?:
return fileElement.path.flatMap({ Path($0) })
case .sourceRoot?:
return fileElement.path.flatMap({ Path($0, relativeTo: sourceRoot) })
case .group?:
guard let group = pbxproj.objects.groups.first(where: { $0.value.children.contains(reference) }) else { return sourceRoot }
guard let groupPath = fullPath(fileElement: group.value, reference: group.key, sourceRoot: sourceRoot) else { return nil }
return fileElement.path.flatMap({ Path($0, relativeTo: groupPath) })
default:
return nil
}
}
}
extension Path {
init(_ string: String, relativeTo relativePath: Path) {
var path = Path(string)
if !path.isAbsolute {
path = (relativePath + path).absolute()
}
self.init(path.string)
}
} It only encounters absolute paths and paths relative to groups or sources root, but it should be possible to extend it to other source tree types if it's possible to provide corresponding environment variables. |
@ilyapuchka I think that would be a great addition to xcproj. Would you mind adding it? We could optimize it in future iterations if it's necessary. |
These methods are great. Just one question: How to I generate the sourceRoot? Since the project file can be anywhere in subdirectories I'm wondering whether I can get the sourceRoot somewhere within xcproj. |
Basically it's just the path to the project file. In Xcode it is an environment variable so you can't get it from the project, unless it defines a custom build setting that equals to this value. |
Closed with #213 |
That makes it easy :) thx |
Hey,
sorry if this is the wrong place to ask, but I can't find anything anywhere else.
Is there an option to get the fully qualified name of the sourcefiles? In project.pbxproj.objects I can only find the direct filename.
Thanks
The text was updated successfully, but these errors were encountered: