@@ -79,27 +79,11 @@ public func generate(
79
79
// references in the project.
80
80
let extraDirs = try findDirectoryReferences ( path: srcroot)
81
81
82
- // Find non-source files in the source directories and root that should be added
83
- // as a reference to the project.
84
- var extraFiles = try findNonSourceFiles ( path: srcroot)
85
-
86
- let sourcesDirectory = srcroot. appending ( component: " Sources " )
87
- if localFileSystem. isDirectory ( sourcesDirectory) {
88
- let sourcesExtraFiles = try findNonSourceFiles ( path: sourcesDirectory, recursively: true )
89
- extraFiles. append ( contentsOf: sourcesExtraFiles)
90
- }
91
-
92
- let testsDirectory = srcroot. appending ( component: " Tests " )
93
- if localFileSystem. isDirectory ( testsDirectory) {
94
- let testsExtraFiles = try findNonSourceFiles ( path: testsDirectory, recursively: true )
95
- extraFiles. append ( contentsOf: testsExtraFiles)
96
- }
97
-
82
+ var workingCheckout : WorkingCheckout ?
98
83
if try repositoryProvider. checkoutExists ( at: srcroot) {
99
- // Get the ignored files and exclude them
100
- let repository = try repositoryProvider. openCheckout ( at: srcroot)
101
- extraFiles = try extraFiles. filter ( { try ! repository. isIgnored ( $0) } )
84
+ workingCheckout = try repositoryProvider. openCheckout ( at: srcroot)
102
85
}
86
+ let extraFiles = try getExtraFilesFor ( package : graph. rootPackages [ 0 ] , in: workingCheckout)
103
87
104
88
/// Generate the contents of project.xcodeproj (inside the .xcodeproj).
105
89
// FIXME: This could be more efficient by directly writing to a stream
@@ -243,6 +227,28 @@ func generateSchemes(
243
227
}
244
228
}
245
229
230
+ // Find and return non-source files in the source directories and root that should be added
231
+ // as a reference to the project.
232
+ func getExtraFilesFor( package : ResolvedPackage , in workingCheckout: WorkingCheckout ? = nil ) throws -> [ AbsolutePath ] {
233
+ let srcroot = package . path
234
+ var extraFiles = try findNonSourceFiles ( path: srcroot)
235
+
236
+ for target in package . targets {
237
+ let sourcesDirectory = target. sources. root
238
+ if localFileSystem. isDirectory ( sourcesDirectory) {
239
+ let sourcesExtraFiles = try findNonSourceFiles ( path: sourcesDirectory, recursively: true )
240
+ extraFiles. append ( contentsOf: sourcesExtraFiles)
241
+ }
242
+ }
243
+
244
+ if let checkout = workingCheckout {
245
+ let isIgnored = try checkout. isGitIgnored ( extraFiles)
246
+ extraFiles = extraFiles. enumerated ( ) . filter ( { !isIgnored[ $0. offset] } ) . map ( { $0. element } )
247
+ }
248
+
249
+ return extraFiles
250
+ }
251
+
246
252
/// Finds the non-source files from `path`
247
253
/// - parameters:
248
254
/// - path: The path of the directory to get the files from
0 commit comments