Skip to content

Ignore normal directory with dots #397

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 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
23 changes: 23 additions & 0 deletions Sources/XcodeGenKit/PathKitExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation
import PathKit

extension Path {

/// Treat this as a resource instead of a normal directory.
var isNonFolderDirectory: Bool {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNonFolderDirectory sounds a bit ambiguous. What about isGroupDirectory? That's how Xcode names directories in an Xcode project.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then you could just say !myPath.isGroupDirectory

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, but I think it's depends on how you look at the problem.

From Xcode perspective, isGroupDirectory is maybe straight forward, but this specific functionality is seen outside of Xcode too. That's why I've put this as PathKitExtension.

Also, I actually tried to rename it, and ended up with rather complicated code. (Needed additional is a directory, but condition to retrieve non "public.folder" directory.)

        let directories = children
            .filter { $0.isDirectory && $0.isGroupDirectory && $0.extension != "lproj" }
            .sorted { $0.lastComponent < $1.lastComponent }

        let filePaths = children
            .filter { $0.isFile || ($0.isDirectory && !$0.isGroupDirectory) }
            .sorted { $0.lastComponent < $1.lastComponent }

Therefore, I think it's better to define this way (isNonFolderDirectory) in whitelist manner.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about isFileDirectory? I agree that isNonFolderDirectory is a bit strange of a name. The actual logic doesn't need to change

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3aac581


if isFile {
return false
}

if let uti = try! URL(fileURLWithPath: self.string)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to get the performance tests in (coming shortly) so this can be tested for performance

.resourceValues(forKeys: [URLResourceKey.typeIdentifierKey])
.typeIdentifier {
// NOTE: lproj is public.folder
return uti != "public.folder"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone looks at this code in three months, it's hard to say what it does. Which types of paths am I ignoring with this expression. Maybe it's worth adding a larger comment where you explain the rationale behind this line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Will do. Maybe as a doc-comment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in 6933cde

}

return false
}

}
4 changes: 2 additions & 2 deletions Sources/XcodeGenKit/SourceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,11 @@ class SourceGenerator {
let children = try getSourceChildren(targetSource: targetSource, dirPath: path)

let directories = children
.filter { $0.isDirectory && $0.extension == nil && $0.extension != "lproj" }
.filter { $0.isDirectory && !$0.isNonFolderDirectory && $0.extension != "lproj" }
.sorted { $0.lastComponent < $1.lastComponent }

let filePaths = children
.filter { $0.isFile || $0.extension != nil && $0.extension != "lproj" }
.filter { $0.isFile || $0.isNonFolderDirectory }
.sorted { $0.lastComponent < $1.lastComponent }

let localisedDirectories = children
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
BF_892119987440 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_854336462818 /* AppDelegate.swift */; settings = {COMPILER_FLAGS = "-Werror"; }; };
BF_897881229855 /* Alamofire.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FR_257516580010 /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BF_898051828670 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_752394658615 /* Alamofire.framework */; };
BF_900577809062 /* Fox.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_269747717860 /* Fox.swift */; settings = {COMPILER_FLAGS = "-Werror"; }; };
BF_901390118565 /* FrameworkFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_172952167809 /* FrameworkFile.swift */; };
BF_905038616071 /* Framework.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FR_472296042419 /* Framework.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
BF_905617636654 /* Headers in Headers */ = {isa = PBXBuildFile; fileRef = FR_815403394914 /* Headers */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -367,6 +368,7 @@
FR_257516580010 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Alamofire.framework; sourceTree = "<group>"; };
FR_263408310401 /* Model 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 3.xcdatamodel"; sourceTree = "<group>"; };
FR_264279911176 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Interface.storyboard; sourceTree = "<group>"; };
FR_269747717860 /* Fox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Fox.swift; sourceTree = "<group>"; };
FR_293137352077 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
FR_304712043717 /* NotificationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationController.swift; sourceTree = "<group>"; };
FR_310979699934 /* MessagesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -683,6 +685,14 @@
path = App_iOS_Tests;
sourceTree = "<group>";
};
G_7841902032535 /* F.O.X */ = {
isa = PBXGroup;
children = (
FR_269747717860 /* Fox.swift */,
);
path = F.O.X;
sourceTree = "<group>";
};
G_8030722683864 /* UnderFileGroup */ = {
isa = PBXGroup;
children = (
Expand All @@ -702,6 +712,7 @@
G_8252321105004 /* App */ = {
isa = PBXGroup;
children = (
G_7841902032535 /* F.O.X */,
FR_854336462818 /* AppDelegate.swift */,
FR_868653349092 /* Assets.xcassets */,
FR_725187762757 /* Info.plist */,
Expand Down Expand Up @@ -1510,6 +1521,7 @@
buildActionMask = 2147483647;
files = (
BF_892119987440 /* AppDelegate.swift in Sources */,
BF_900577809062 /* Fox.swift in Sources */,
BF_670499288392 /* Model.xcdatamodeld in Sources */,
BF_503484983186 /* MoreUnder.swift in Sources */,
BF_561304997165 /* Standalone.swift in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Tests/XcodeGenKitTests/SourceGeneratorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class SourceGeneratorTests: XCTestCase {
- a.swift
- B:
- b.swift
- C.D.E:
- c.d.e.swift
"""
try createDirectories(directories)

Expand All @@ -70,6 +72,7 @@ class SourceGeneratorTests: XCTestCase {
let pbxProj = try project.generatePbxProj()
try pbxProj.expectFile(paths: ["Sources", "A", "a.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["Sources", "A", "B", "b.swift"], buildPhase: .sources)
try pbxProj.expectFile(paths: ["Sources", "A", "C.D.E", "c.d.e.swift"], buildPhase: .sources)
}

$0.it("supports frameworks in sources") {
Expand Down