Skip to content

Commit 9c5323c

Browse files
committed
Simplify module logic
1 parent 4d9db59 commit 9c5323c

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Sources/Transmute/Package+modules.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,16 @@ extension Package {
8080

8181
let cSources = walked.filter{ isValidSource($0, validExtensions: Sources.validCExtensions) }
8282
let swiftSources = walked.filter{ isValidSource($0, validExtensions: Sources.validSwiftExtensions) }
83-
84-
guard cSources.count > 0 || swiftSources.count > 0 else { throw Module.Error.NoSources(path) }
85-
guard !(cSources.count > 0 && swiftSources.count > 0) else { throw Module.Error.MixedSources(path) }
8683

87-
let isSwiftModule = swiftSources.count > 0 //We've already made sure that it'll can be only either of the two.
88-
let sources = Sources(paths: isSwiftModule ? swiftSources : cSources, root: path)
89-
90-
if isSwiftModule {
91-
return SwiftModule(name: name, sources: sources)
84+
if !cSources.isEmpty {
85+
guard swiftSources.isEmpty else { throw Module.Error.MixedSources(path) }
86+
//FIXME: Support executables for C languages
87+
guard !cSources.contains({ $0.hasSuffix("main.c") }) else { throw Module.Error.CExecutableNotSupportedYet(path) }
88+
return ClangModule(name: name, sources: Sources(paths: cSources, root: path))
9289
}
9390

94-
//FIXME: Support executables for C languages
95-
guard !cSources.contains({ $0.hasSuffix("main.c") }) else { throw Module.Error.CExecutableNotSupportedYet(path) }
96-
97-
return ClangModule(name: name, sources: sources)
91+
guard !swiftSources.isEmpty else { throw Module.Error.NoSources(path) }
92+
return SwiftModule(name: name, sources: Sources(paths: swiftSources, root: path))
9893
}
9994

10095
func isValidSource(path: String) -> Bool {

0 commit comments

Comments
 (0)