Skip to content

Commit ee38fd2

Browse files
authored
Merge pull request #628 from aciidb0mb3r/SR-2533
[PackageBuilder] Error on invalid manifest config
2 parents d57de8f + bc241ca commit ee38fd2

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public enum ModuleError: Swift.Error {
3131

3232
/// A module was marked as being dependent on an executable.
3333
case executableAsDependency(module: String, dependency: String)
34+
35+
/// The manifest has invalid configuration wrt type of the module.
36+
case invalidManifestConfig(String, String)
3437
}
3538

3639
extension ModuleError: FixableError {
@@ -42,6 +45,8 @@ extension ModuleError: FixableError {
4245
return "the package has an unsupported layout, \(type.error)"
4346
case .executableAsDependency(let module, let dependency):
4447
return "the target \(module) cannot have the executable \(dependency) as a dependency"
48+
case .invalidManifestConfig(let package, let message):
49+
return "invalid configuration in '\(package)': \(message)"
4550
}
4651
}
4752

@@ -53,6 +58,8 @@ extension ModuleError: FixableError {
5358
return type.fix
5459
case .executableAsDependency(_):
5560
return "move the shared logic inside a library, which can be referenced from both the target and the executable"
61+
case .invalidManifestConfig(_):
62+
return nil
5663
}
5764
}
5865
}
@@ -338,6 +345,15 @@ public struct PackageBuilder {
338345
return [try CModule(name: manifest.name, sources: sources, path: packagePath, pkgConfig: pkgConfigPath, providers: manifest.package.providers)]
339346
}
340347

348+
// At this point the module can't be a system module, make sure manifest doesn't contain
349+
// system module specific configuration.
350+
guard manifest.package.pkgConfig == nil else {
351+
throw ModuleError.invalidManifestConfig(manifest.name, "pkgConfig should only be used with a System Module Package")
352+
}
353+
guard manifest.package.providers == nil else {
354+
throw ModuleError.invalidManifestConfig(manifest.name, "providers should only be used with a System Module Package")
355+
}
356+
341357
// If everything is excluded, just return an empty array.
342358
if manifest.package.exclude.contains(".") {
343359
return []

Tests/PackageLoadingTests/ConventionTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,26 @@ class ConventionTests: XCTestCase {
840840
}
841841
}
842842

843+
func testInvalidManifestConfigForNonSystemModules() {
844+
var fs = InMemoryFileSystem(emptyFiles:
845+
"/Sources/main.swift"
846+
)
847+
var package = PackageDescription.Package(name: "pkg", pkgConfig: "foo")
848+
849+
PackageBuilderTester(package, in: fs) { result in
850+
result.checkDiagnostic("invalid configuration in 'pkg': pkgConfig should only be used with a System Module Package")
851+
}
852+
853+
fs = InMemoryFileSystem(emptyFiles:
854+
"/Sources/Foo/main.c"
855+
)
856+
package = PackageDescription.Package(name: "pkg", providers: [.Brew("foo")])
857+
858+
PackageBuilderTester(package, in: fs) { result in
859+
result.checkDiagnostic("invalid configuration in 'pkg': providers should only be used with a System Module Package")
860+
}
861+
}
862+
843863
static var allTests = [
844864
("testCInTests", testCInTests),
845865
("testDotFilesAreIgnored", testDotFilesAreIgnored),
@@ -873,6 +893,7 @@ class ConventionTests: XCTestCase {
873893
("testBadProducts", testBadProducts),
874894
("testVersionSpecificManifests", testVersionSpecificManifests),
875895
("testTestsProduct", testTestsProduct),
896+
("testInvalidManifestConfigForNonSystemModules", testInvalidManifestConfigForNonSystemModules),
876897
]
877898
}
878899

0 commit comments

Comments
 (0)