Skip to content

Commit 5e3a6d3

Browse files
committed
Merge pull request #222 from aciidb0mb3r/patch-8
Print warning if a module not present for a product, error out if zer…
2 parents 4d9b1b7 + 34f84d6 commit 5e3a6d3

File tree

8 files changed

+52
-3
lines changed

8 files changed

+52
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Foo {
2+
var bar: Int = 0
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import PackageDescription
2+
3+
let package = Package(name: "Foo")
4+
5+
let archive = Product(name: "Bar", type: .Library(.Static), modules: "Foo", "Baz")
6+
7+
products.append(archive)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Foo {
2+
var bar: Int = 0
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import PackageDescription
2+
3+
let package = Package(name: "Foo")
4+
5+
let archive = Product(name: "Bar", type: .Library(.Dynamic), modules: "")
6+
7+
products.append(archive)

Sources/Transmute/Error.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ extension Module {
2929
case MixedSources(String)
3030
}
3131
}
32+
33+
extension Product {
34+
public enum Error: ErrorProtocol {
35+
case NoModules(String)
36+
}
37+
}

Sources/Transmute/Package+products.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@ extension Package {
3636
////// add products from the manifest
3737

3838
for p in manifest.products {
39-
//FIXME no bang
40-
let modules = p.modules.map{ moduleName in
41-
modules.pick{ $0.name == moduleName } as! SwiftModule
39+
let modules: [SwiftModule] = p.modules.flatMap{ moduleName in
40+
guard case let picked as SwiftModule = (modules.pick{ $0.name == moduleName }) else {
41+
print("warning: No module \(moduleName) found for product \(p.name)")
42+
return nil
43+
}
44+
return picked
4245
}
46+
47+
guard !modules.isEmpty else {
48+
throw Product.Error.NoModules(p.name)
49+
}
50+
4351
let product = Product(name: p.name, type: p.type, modules: modules)
4452
products.append(product)
4553
}

Tests/Functional/TestMiscellaneous.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,17 @@ class MiscellaneousTestCase: XCTestCase {
349349
XCTAssertFileExists(prefix, ".build/debug/libBar.a")
350350
}
351351
}
352+
353+
func testProductWithNoModules() {
354+
fixture(name: "Miscellaneous/ProductWithNoModules") { prefix in
355+
XCTAssertBuildFails(prefix)
356+
}
357+
}
358+
359+
func testProductWithMissingModules() {
360+
fixture(name: "Miscellaneous/ProductWithMissingModules") { prefix in
361+
XCTAssertBuilds(prefix)
362+
XCTAssertFileExists(prefix, ".build/debug/libBar.a")
363+
}
364+
}
352365
}

Tests/Functional/TestValidLayouts.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ extension MiscellaneousTestCase {
181181
("testInternalDependencyEdges", testInternalDependencyEdges),
182182
("testExternalDependencyEdges1", testExternalDependencyEdges1),
183183
("testExternalDependencyEdges2", testExternalDependencyEdges2),
184+
("testProductWithNoModules", testProductWithNoModules),
185+
("testProductWithMissingModules", testProductWithMissingModules),
184186
]
185187
}
186188
}

0 commit comments

Comments
 (0)