Skip to content

Commit 348613b

Browse files
committed
ignore info plists in synced folders
1 parent b285345 commit 348613b

3 files changed

Lines changed: 37 additions & 10 deletions

File tree

Sources/XcodeGenKit/PBXProjGenerator.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,14 @@ public class PBXProjGenerator {
686686
let infoPlistFiles: [Config: String] = getInfoPlists(for: target)
687687
let sourceFileBuildPhaseOverrideSequence: [(Path, BuildPhaseSpec)] = Set(infoPlistFiles.values).map({ (project.basePath + $0, .none) })
688688
let sourceFileBuildPhaseOverrides = Dictionary(uniqueKeysWithValues: sourceFileBuildPhaseOverrideSequence)
689-
let sourceFiles = try sourceGenerator.getAllSourceFiles(targetType: target.type, sources: target.sources, buildPhases: sourceFileBuildPhaseOverrides)
690-
.sorted { $0.path.lastComponent < $1.path.lastComponent }
689+
let targetObject = targetObjects[target.name]!
690+
let sourceFiles = try sourceGenerator.getAllSourceFiles(
691+
target: targetObject,
692+
targetType: target.type,
693+
sources: target.sources,
694+
buildPhases: sourceFileBuildPhaseOverrides
695+
)
696+
.sorted { $0.path.lastComponent < $1.path.lastComponent }
691697

692698
var anyDependencyRequiresObjCLinking = false
693699

@@ -1439,8 +1445,6 @@ public class PBXProjGenerator {
14391445
defaultConfigurationName: defaultConfigurationName
14401446
))
14411447

1442-
let targetObject = targetObjects[target.name]!
1443-
14441448
let targetFileReference = targetFileReferences[target.name]
14451449

14461450
targetObject.name = target.name

Sources/XcodeGenKit/SourceGenerator.swift

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ class SourceGenerator {
8686
/// - targetType: The type of target that the source files should belong to.
8787
/// - sources: The array of sources defined as part of the targets spec.
8888
/// - buildPhases: A dictionary containing any build phases that should be applied to source files at specific paths in the event that the associated `TargetSource` didn't already define a `buildPhase`. Values from this dictionary are used in cases where the project generator knows more about a file than the spec/filesystem does (i.e if the file should be treated as the targets Info.plist and so on).
89-
func getAllSourceFiles(targetType: PBXProductType, sources: [TargetSource], buildPhases: [Path : BuildPhaseSpec]) throws -> [SourceFile] {
90-
try sources.flatMap { try getSourceFiles(targetType: targetType, targetSource: $0, buildPhases: buildPhases) }
89+
func getAllSourceFiles(target: PBXTarget, targetType: PBXProductType, sources: [TargetSource], buildPhases: [Path : BuildPhaseSpec]) throws -> [SourceFile] {
90+
try sources.flatMap { try getSourceFiles(target: target, targetType: targetType, targetSource: $0, buildPhases: buildPhases) }
9191
}
9292

9393
// get groups without build files. Use for Project.fileGroups
9494
func getFileGroups(path: String) throws {
95-
_ = try getSourceFiles(targetType: .none, targetSource: TargetSource(path: path), buildPhases: [:])
95+
_ = try getSourceFiles(target: nil, targetType: .none, targetSource: TargetSource(path: path), buildPhases: [:])
9696
}
9797

9898
func getFileType(path: Path) -> FileType? {
@@ -601,7 +601,7 @@ class SourceGenerator {
601601
}
602602

603603
/// creates source files
604-
private func getSourceFiles(targetType: PBXProductType, targetSource: TargetSource, buildPhases: [Path: BuildPhaseSpec]) throws -> [SourceFile] {
604+
private func getSourceFiles(target: PBXTarget?, targetType: PBXProductType, targetSource: TargetSource, buildPhases: [Path: BuildPhaseSpec]) throws -> [SourceFile] {
605605

606606
// generate excluded paths
607607
let path = project.basePath + targetSource.path
@@ -690,13 +690,23 @@ class SourceGenerator {
690690
case .syncedFolder:
691691

692692
let relativePath = (try? path.relativePath(from: project.basePath)) ?? path
693-
693+
694+
var exceptions: [PBXFileSystemSynchronizedExceptionSet] = []
695+
let ignoredFiles = Array(buildPhases.filter { $0.value == .none }.keys)
696+
if let target, !ignoredFiles.isEmpty {
697+
let memberShipExceptions = ignoredFiles
698+
.map { (try? $0.relativePath(from: project.basePath)) ?? $0 }
699+
.map(\.string)
700+
let exception = PBXFileSystemSynchronizedBuildFileExceptionSet(target: target, membershipExceptions: memberShipExceptions, publicHeaders: nil, privateHeaders: nil, additionalCompilerFlagsByRelativePath: nil, attributesByRelativePath: nil)
701+
addObject(exception)
702+
exceptions.append(exception)
703+
}
694704
let syncedRootGroup = PBXFileSystemSynchronizedRootGroup(
695705
sourceTree: .group,
696706
path: relativePath.string,
697707
name: targetSource.name,
698708
explicitFileTypes: [:],
699-
exceptions: [],
709+
exceptions: exceptions,
700710
explicitFolders: []
701711
)
702712
addObject(syncedRootGroup)

Tests/Fixtures/TestProject/Project.xcodeproj/project.pbxproj

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,22 @@
830830
FED40A89162E446494DDE7C7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
831831
/* End PBXFileReference section */
832832

833+
/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
834+
"TEMP_067E2B5F-0F9F-4B71-A34B-DB4FEB8A01AC" /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
835+
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
836+
membershipExceptions = (
837+
App_iOS/Info.plist,
838+
);
839+
target = 0867B0DACEF28C11442DE8F7 /* App_iOS */;
840+
};
841+
/* End PBXFileSystemSynchronizedBuildFileExceptionSet section */
842+
833843
/* Begin PBXFileSystemSynchronizedRootGroup section */
834844
AE2AB2772F70DFFF402AA02B /* SyncedFolder */ = {
835845
isa = PBXFileSystemSynchronizedRootGroup;
846+
exceptions = (
847+
"TEMP_067E2B5F-0F9F-4B71-A34B-DB4FEB8A01AC" /* PBXFileSystemSynchronizedBuildFileExceptionSet */,
848+
);
836849
explicitFileTypes = {
837850
};
838851
explicitFolders = (

0 commit comments

Comments
 (0)