Skip to content

Print warning if a module not present for a product, error out if zer… #222

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 2 commits into from
Apr 5, 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
3 changes: 3 additions & 0 deletions Fixtures/Miscellaneous/ProductWithMissingModules/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Foo {
var bar: Int = 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import PackageDescription

let package = Package(name: "Foo")

let archive = Product(name: "Bar", type: .Library(.Static), modules: "Foo", "Baz")

products.append(archive)
3 changes: 3 additions & 0 deletions Fixtures/Miscellaneous/ProductWithNoModules/Foo.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class Foo {
var bar: Int = 0
}
7 changes: 7 additions & 0 deletions Fixtures/Miscellaneous/ProductWithNoModules/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import PackageDescription

let package = Package(name: "Foo")

let archive = Product(name: "Bar", type: .Library(.Dynamic), modules: "")

products.append(archive)
6 changes: 6 additions & 0 deletions Sources/Transmute/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ extension Module {
case MixedSources(String)
}
}

extension Product {
public enum Error: ErrorProtocol {
case NoModules(String)
}
}
14 changes: 11 additions & 3 deletions Sources/Transmute/Package+products.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ extension Package {
////// add products from the manifest

for p in manifest.products {
//FIXME no bang
let modules = p.modules.map{ moduleName in
modules.pick{ $0.name == moduleName } as! SwiftModule
let modules: [SwiftModule] = p.modules.flatMap{ moduleName in
guard case let picked as SwiftModule = (modules.pick{ $0.name == moduleName }) else {
print("warning: No module \(moduleName) found for product \(p.name)")
return nil
}
return picked
}

guard !modules.isEmpty else {
throw Product.Error.NoModules(p.name)
}

let product = Product(name: p.name, type: p.type, modules: modules)
products.append(product)
}
Expand Down
13 changes: 13 additions & 0 deletions Tests/Functional/TestMiscellaneous.swift
Original file line number Diff line number Diff line change
Expand Up @@ -349,4 +349,17 @@ class MiscellaneousTestCase: XCTestCase {
XCTAssertFileExists(prefix, ".build/debug/libBar.a")
}
}

func testProductWithNoModules() {
fixture(name: "Miscellaneous/ProductWithNoModules") { prefix in
XCTAssertBuildFails(prefix)
}
}

func testProductWithMissingModules() {
fixture(name: "Miscellaneous/ProductWithMissingModules") { prefix in
XCTAssertBuilds(prefix)
XCTAssertFileExists(prefix, ".build/debug/libBar.a")
}
}
}
2 changes: 2 additions & 0 deletions Tests/Functional/TestValidLayouts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ extension MiscellaneousTestCase {
("testInternalDependencyEdges", testInternalDependencyEdges),
("testExternalDependencyEdges1", testExternalDependencyEdges1),
("testExternalDependencyEdges2", testExternalDependencyEdges2),
("testProductWithNoModules", testProductWithNoModules),
("testProductWithMissingModules", testProductWithMissingModules),
]
}
}
Expand Down