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 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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
command: swift build
- run:
name: Test
command: swift test 2>&1 | xcpretty
command: swift test
- run:
name: Check Project Diff
command: ./diff-fixtures.sh
Expand All @@ -30,7 +30,7 @@ jobs:
command: swift build
- run:
name: Test
command: swift test 2>&1 | xcpretty
command: swift test
# disabled till UUID's are stable
# - run:
# name: Check Project Diff
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log

## master

#### ⚠️Breaking Changes⚠️

XcodeGen now retrieves UTI of a directory to know if it's a special directory such as `Assets.xcassets/`. That means other normal directories **with dots** will not appear in `Copy Bundle Resources` Build Phase any more.

- Ignore normal directory with dots [397](https://github.com/yonaskolb/XcodeGen/pull/397) @toshi0383

## 1.11.2

If XcodeGen is compiled with Swift 4.2, then UUID's in the generated project will not be deterministic. This will be fixed in an upcoming release with an update to xcodeproj 6.0
Expand Down
28 changes: 28 additions & 0 deletions Sources/XcodeGenKit/PathKitExtension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import PathKit

extension Path {

/// Treat this as a file (resource or source) instead of a normal directory.
var isFileDirectory: Bool {

if isFile || self.extension == nil {
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 {

// If uti is `public.folder` or `dyn*`, it's a normal directory in most cases.
// But for example *.lproj appears to be a `public.folder`.
// So make sure to filter to treat it as a special directory.
print("Path.string: \(self.string), uti: \(uti)")
return uti != "public.folder" && !uti.starts(with: "dyn")

}

return false
}

}
47 changes: 31 additions & 16 deletions Sources/XcodeGenKit/SourceGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,38 @@ class SourceGenerator {
if path.lastComponent == "Info.plist" {
return nil
}
if let fileExtension = path.extension {

guard let fileExtension = path.extension else {
return nil
}

if path.isDirectory {
switch fileExtension {
case "swift", "m", "mm", "cpp", "c", "cc", "S", "xcdatamodeld", "metal": return .sources
case "h", "hh", "hpp", "ipp", "tpp", "hxx", "def": return .headers
case "modulemap":
guard targetType == .staticLibrary else { return nil }
return .copyFiles(TargetSource.BuildPhase.CopyFilesSettings(
destination: .productsDirectory,
subpath: "include/$(PRODUCT_NAME)"
))
case "framework": return .frameworks
case "xpc": return .copyFiles(.xpcServices)
case "xcconfig", "entitlements", "gpx", "lproj", "apns": return nil
default: return .resources
case "xcdatamodeld":
return .sources
case "framework":
return .frameworks
case "xpc":
return .copyFiles(.xpcServices)
case "lproj":
return nil
default:
return .resources
}
}
return nil

switch fileExtension {
case "swift", "m", "mm", "cpp", "c", "cc", "S", "metal": return .sources
case "h", "hh", "hpp", "ipp", "tpp", "hxx", "def": return .headers
case "modulemap":
guard targetType == .staticLibrary else { return nil }
return .copyFiles(TargetSource.BuildPhase.CopyFilesSettings(
destination: .productsDirectory,
subpath: "include/$(PRODUCT_NAME)"
))
case "xcconfig", "entitlements", "gpx", "apns": return nil
default: return .resources
}
}

/// Create a group or return an existing one at the path.
Expand Down Expand Up @@ -310,11 +325,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.isFileDirectory && $0.extension != "lproj" }
.sorted { $0.lastComponent < $1.lastComponent }

let filePaths = children
.filter { $0.isFile || $0.extension != nil && $0.extension != "lproj" }
.filter { $0.isFile || $0.isFileDirectory }
.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 @@ -120,6 +120,7 @@
BF_874851989284 /* Result.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_131384036341 /* Result.framework */; };
BF_892119987440 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_854336462818 /* AppDelegate.swift */; settings = {COMPILER_FLAGS = "-Werror"; }; };
BF_895856588273 /* StaticLibrary_ObjC.m in Sources */ = {isa = PBXBuildFile; fileRef = "FR_698230898030-1" /* StaticLibrary_ObjC.m */; };
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_901508574566 = {isa = PBXBuildFile; fileRef = FR_704531614016 /* StaticLibrary_ObjC.a */; };
BF_903574875171 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_777446672298 /* ViewController.swift */; };
Expand Down Expand Up @@ -418,6 +419,7 @@
FR_257073931060 /* ResourceFolder */ = {isa = PBXFileReference; lastKnownFileType = folder; name = ResourceFolder; path = Resources/ResourceFolder; sourceTree = SOURCE_ROOT; };
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_281269793733 /* StaticLibrary_ObjC.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = StaticLibrary_ObjC.a; sourceTree = BUILT_PRODUCTS_DIR; };
FR_285483315484 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
FR_293137352077 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -752,6 +754,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 @@ -771,6 +781,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 @@ -1662,6 +1673,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
Loading