@@ -222,16 +222,33 @@ public struct PackageBuilder {
222
222
// MARK: Utility Predicates
223
223
224
224
private func isValidSource( _ path: AbsolutePath ) -> Bool {
225
- return isValidSource ( path, validExtensions: SupportedLanguageExtension . validExtensions)
226
- }
227
-
228
- private func isValidSource( _ path: AbsolutePath , validExtensions: Set < String > ) -> Bool {
229
- if path. basename. hasPrefix ( " . " ) { return false }
230
- if path == manifest. path { return false }
231
- if excludedPaths. contains ( path) { return false }
225
+ // Ignore files which don't match the expected extensions.
226
+ guard let ext = path. extension, SupportedLanguageExtension . validExtensions. contains ( ext) else {
227
+ return false
228
+ }
229
+
230
+ // Ignore dotfiles.
231
+ let basename = path. basename
232
+ if basename. hasPrefix ( " . " ) { return false }
233
+
234
+ // Ignore symlinks to non-files.
232
235
if !fileSystem. isFile ( path) { return false }
233
- guard let ext = path. extension else { return false }
234
- return validExtensions. contains ( ext)
236
+
237
+ // Ignore excluded files.
238
+ if excludedPaths. contains ( path) { return false }
239
+
240
+ // Ignore manifest files.
241
+ if path. parentDirectory == packagePath {
242
+ if basename == Manifest . filename { return false }
243
+
244
+ // Ignore version-specific manifest files.
245
+ if basename. hasPrefix ( Manifest . basename + " @ " ) && basename. hasSuffix ( " .swift " ) {
246
+ return false
247
+ }
248
+ }
249
+
250
+ // Otherwise, we have a valid source file.
251
+ return true
235
252
}
236
253
237
254
private func shouldConsiderDirectory( _ path: AbsolutePath ) -> Bool {
@@ -414,7 +431,7 @@ public struct PackageBuilder {
414
431
}
415
432
}
416
433
417
- /// Private function that constructs a single Module object for the moduel at `path`, having the name `name`. If `isTest` is true, the module is constructed as a test module; if false, it is a regular module.
434
+ /// Private function that constructs a single Module object for the module at `path`, having the name `name`. If `isTest` is true, the module is constructed as a test module; if false, it is a regular module.
418
435
private func createModule( _ path: AbsolutePath , name: String , isTest: Bool ) throws -> Module {
419
436
420
437
// Validate the module name. This function will throw an error if it detects a problem.
@@ -424,9 +441,11 @@ public struct PackageBuilder {
424
441
let walked = try walk ( path, fileSystem: fileSystem, recursing: shouldConsiderDirectory) . map { $0 }
425
442
426
443
// Select any source files for the C-based languages and for Swift.
427
- let cSources = walked. filter { isValidSource ( $0, validExtensions: SupportedLanguageExtension . cFamilyExtensions) }
428
- let swiftSources = walked. filter { isValidSource ( $0, validExtensions: SupportedLanguageExtension . swiftExtensions) }
429
-
444
+ let sources = walked. filter ( isValidSource)
445
+ let cSources = sources. filter { SupportedLanguageExtension . cFamilyExtensions. contains ( $0. extension!) }
446
+ let swiftSources = sources. filter { SupportedLanguageExtension . swiftExtensions. contains ( $0. extension!) }
447
+ assert ( sources. count == cSources. count + swiftSources. count)
448
+
430
449
// Create and return the right kind of module depending on what kind of sources we found.
431
450
if cSources. isEmpty {
432
451
// No C sources, so we expect to have Swift sources, and we create a Swift module.
0 commit comments