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