Skip to content

[PackageBuilder] Error on invalid manifest config #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public enum ModuleError: Swift.Error {

/// A module was marked as being dependent on an executable.
case executableAsDependency(module: String, dependency: String)

/// The manifest has invalid configuration wrt type of the module.
case invalidManifestConfig(String, String)
}

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

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

// At this point the module can't be a system module, make sure manifest doesn't contain
// system module specific configuration.
guard manifest.package.pkgConfig == nil else {
throw ModuleError.invalidManifestConfig(manifest.name, "pkgConfig should only be used with a System Module Package")
}
guard manifest.package.providers == nil else {
throw ModuleError.invalidManifestConfig(manifest.name, "providers should only be used with a System Module Package")
}

// If everything is excluded, just return an empty array.
if manifest.package.exclude.contains(".") {
return []
Expand Down
21 changes: 21 additions & 0 deletions Tests/PackageLoadingTests/ConventionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,26 @@ class ConventionTests: XCTestCase {
}
}

func testInvalidManifestConfigForNonSystemModules() {
var fs = InMemoryFileSystem(emptyFiles:
"/Sources/main.swift"
)
var package = PackageDescription.Package(name: "pkg", pkgConfig: "foo")

PackageBuilderTester(package, in: fs) { result in
result.checkDiagnostic("invalid configuration in 'pkg': pkgConfig should only be used with a System Module Package")
}

fs = InMemoryFileSystem(emptyFiles:
"/Sources/Foo/main.c"
)
package = PackageDescription.Package(name: "pkg", providers: [.Brew("foo")])

PackageBuilderTester(package, in: fs) { result in
result.checkDiagnostic("invalid configuration in 'pkg': providers should only be used with a System Module Package")
}
}

static var allTests = [
("testCInTests", testCInTests),
("testDotFilesAreIgnored", testDotFilesAreIgnored),
Expand Down Expand Up @@ -873,6 +893,7 @@ class ConventionTests: XCTestCase {
("testBadProducts", testBadProducts),
("testVersionSpecificManifests", testVersionSpecificManifests),
("testTestsProduct", testTestsProduct),
("testInvalidManifestConfigForNonSystemModules", testInvalidManifestConfigForNonSystemModules),
]
}

Expand Down