@@ -1481,6 +1481,190 @@ final class BuildPlanTests: XCTestCase {
1481
1481
""" ) , contents)
1482
1482
}
1483
1483
}
1484
+
1485
+ func testObjCHeader1( ) throws {
1486
+ // This has a Swift and ObjC target in the same package.
1487
+ let fs = InMemoryFileSystem ( emptyFiles:
1488
+ " /PkgA/Sources/Bar/main.m " ,
1489
+ " /PkgA/Sources/Foo/Foo.swift "
1490
+ )
1491
+
1492
+ let diagnostics = DiagnosticsEngine ( )
1493
+ let graph = loadPackageGraph ( root: " /PkgA " , fs: fs, diagnostics: diagnostics,
1494
+ manifests: [
1495
+ Manifest . createV4Manifest (
1496
+ name: " PkgA " ,
1497
+ path: " /PkgA " ,
1498
+ url: " /PkgA " ,
1499
+ targets: [
1500
+ TargetDescription ( name: " Foo " , dependencies: [ ] ) ,
1501
+ TargetDescription ( name: " Bar " , dependencies: [ " Foo " ] ) ,
1502
+ ] ) ,
1503
+ ]
1504
+ )
1505
+ XCTAssertNoDiagnostics ( diagnostics)
1506
+
1507
+ let plan = try BuildPlan ( buildParameters: mockBuildParameters ( ) , graph: graph, diagnostics: diagnostics, fileSystem: fs)
1508
+ let result = BuildPlanResult ( plan: plan)
1509
+
1510
+ let fooTarget = try result. target ( for: " Foo " ) . swiftTarget ( ) . compileArguments ( )
1511
+ #if os(macOS)
1512
+ XCTAssertMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1513
+ #else
1514
+ XCTAssertNoMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1515
+ #endif
1516
+
1517
+ let barTarget = try result. target ( for: " Bar " ) . clangTarget ( ) . basicArguments ( )
1518
+ #if os(macOS)
1519
+ XCTAssertMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1520
+ #else
1521
+ XCTAssertNoMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1522
+ #endif
1523
+
1524
+ mktmpdir { path in
1525
+ let yaml = path. appending ( component: " debug.yaml " )
1526
+ let llbuild = LLBuildManifestGenerator ( plan, client: " swift-build " )
1527
+ try llbuild. generateManifest ( at: yaml)
1528
+ let contents = try localFileSystem. readFileContents ( yaml) . description
1529
+ XCTAssertMatch ( contents, . contains( """
1530
+ " /path/to/build/debug/Bar.build/main.m.o " :
1531
+ tool: clang
1532
+ description: " Compiling Bar main.m "
1533
+ inputs: [ " /path/to/build/debug/Foo.swiftmodule " , " /PkgA/Sources/Bar/main.m " ]
1534
+ """ ) )
1535
+ }
1536
+ }
1537
+
1538
+ func testObjCHeader2( ) throws {
1539
+ // This has a Swift and ObjC target in different packages with automatic product type.
1540
+ let fs = InMemoryFileSystem ( emptyFiles:
1541
+ " /PkgA/Sources/Bar/main.m " ,
1542
+ " /PkgB/Sources/Foo/Foo.swift "
1543
+ )
1544
+
1545
+ let diagnostics = DiagnosticsEngine ( )
1546
+ let graph = loadPackageGraph ( root: " /PkgA " , fs: fs, diagnostics: diagnostics,
1547
+ manifests: [
1548
+ Manifest . createV4Manifest (
1549
+ name: " PkgA " ,
1550
+ path: " /PkgA " ,
1551
+ url: " /PkgA " ,
1552
+ dependencies: [
1553
+ PackageDependencyDescription ( url: " /PkgB " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
1554
+ ] ,
1555
+ targets: [
1556
+ TargetDescription ( name: " Bar " , dependencies: [ " Foo " ] ) ,
1557
+ ] ) ,
1558
+ Manifest . createV4Manifest (
1559
+ name: " PkgB " ,
1560
+ path: " /PkgB " ,
1561
+ url: " /PkgB " ,
1562
+ products: [
1563
+ ProductDescription ( name: " Foo " , targets: [ " Foo " ] ) ,
1564
+ ] ,
1565
+ targets: [
1566
+ TargetDescription ( name: " Foo " , dependencies: [ ] ) ,
1567
+ ] ) ,
1568
+ ]
1569
+ )
1570
+ XCTAssertNoDiagnostics ( diagnostics)
1571
+
1572
+ let plan = try BuildPlan ( buildParameters: mockBuildParameters ( ) , graph: graph, diagnostics: diagnostics, fileSystem: fs)
1573
+ let result = BuildPlanResult ( plan: plan)
1574
+
1575
+ let fooTarget = try result. target ( for: " Foo " ) . swiftTarget ( ) . compileArguments ( )
1576
+ #if os(macOS)
1577
+ XCTAssertMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1578
+ #else
1579
+ XCTAssertNoMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1580
+ #endif
1581
+
1582
+ let barTarget = try result. target ( for: " Bar " ) . clangTarget ( ) . basicArguments ( )
1583
+ #if os(macOS)
1584
+ XCTAssertMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1585
+ #else
1586
+ XCTAssertNoMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1587
+ #endif
1588
+
1589
+ mktmpdir { path in
1590
+ let yaml = path. appending ( component: " debug.yaml " )
1591
+ let llbuild = LLBuildManifestGenerator ( plan, client: " swift-build " )
1592
+ try llbuild. generateManifest ( at: yaml)
1593
+ let contents = try localFileSystem. readFileContents ( yaml) . description
1594
+ XCTAssertMatch ( contents, . contains( """
1595
+ " /path/to/build/debug/Bar.build/main.m.o " :
1596
+ tool: clang
1597
+ description: " Compiling Bar main.m "
1598
+ inputs: [ " /path/to/build/debug/Foo.swiftmodule " , " /PkgA/Sources/Bar/main.m " ]
1599
+ """ ) )
1600
+ }
1601
+ }
1602
+
1603
+ func testObjCHeader3( ) throws {
1604
+ // This has a Swift and ObjC target in different packages with dynamic product type.
1605
+ let fs = InMemoryFileSystem ( emptyFiles:
1606
+ " /PkgA/Sources/Bar/main.m " ,
1607
+ " /PkgB/Sources/Foo/Foo.swift "
1608
+ )
1609
+
1610
+ let diagnostics = DiagnosticsEngine ( )
1611
+ let graph = loadPackageGraph ( root: " /PkgA " , fs: fs, diagnostics: diagnostics,
1612
+ manifests: [
1613
+ Manifest . createV4Manifest (
1614
+ name: " PkgA " ,
1615
+ path: " /PkgA " ,
1616
+ url: " /PkgA " ,
1617
+ dependencies: [
1618
+ PackageDependencyDescription ( url: " /PkgB " , requirement: . upToNextMajor( from: " 1.0.0 " ) ) ,
1619
+ ] ,
1620
+ targets: [
1621
+ TargetDescription ( name: " Bar " , dependencies: [ " Foo " ] ) ,
1622
+ ] ) ,
1623
+ Manifest . createV4Manifest (
1624
+ name: " PkgB " ,
1625
+ path: " /PkgB " ,
1626
+ url: " /PkgB " ,
1627
+ products: [
1628
+ ProductDescription ( name: " Foo " , type: . library( . dynamic) , targets: [ " Foo " ] ) ,
1629
+ ] ,
1630
+ targets: [
1631
+ TargetDescription ( name: " Foo " , dependencies: [ ] ) ,
1632
+ ] ) ,
1633
+ ]
1634
+ )
1635
+ XCTAssertNoDiagnostics ( diagnostics)
1636
+
1637
+ let plan = try BuildPlan ( buildParameters: mockBuildParameters ( ) , graph: graph, diagnostics: diagnostics, fileSystem: fs)
1638
+ let dynamicLibraryExtension = plan. buildParameters. triple. dynamicLibraryExtension
1639
+ let result = BuildPlanResult ( plan: plan)
1640
+
1641
+ let fooTarget = try result. target ( for: " Foo " ) . swiftTarget ( ) . compileArguments ( )
1642
+ #if os(macOS)
1643
+ XCTAssertMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1644
+ #else
1645
+ XCTAssertNoMatch ( fooTarget, [ . anySequence, " -emit-objc-header " , " -emit-objc-header-path " , " /path/to/build/debug/Foo.build/Foo-Swift.h " , . anySequence] )
1646
+ #endif
1647
+
1648
+ let barTarget = try result. target ( for: " Bar " ) . clangTarget ( ) . basicArguments ( )
1649
+ #if os(macOS)
1650
+ XCTAssertMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1651
+ #else
1652
+ XCTAssertNoMatch ( barTarget, [ . anySequence, " -fmodule-map-file=/path/to/build/debug/Foo.build/module.modulemap " , . anySequence] )
1653
+ #endif
1654
+
1655
+ mktmpdir { path in
1656
+ let yaml = path. appending ( component: " debug.yaml " )
1657
+ let llbuild = LLBuildManifestGenerator ( plan, client: " swift-build " )
1658
+ try llbuild. generateManifest ( at: yaml)
1659
+ let contents = try localFileSystem. readFileContents ( yaml) . description
1660
+ XCTAssertMatch ( contents, . contains( """
1661
+ " /path/to/build/debug/Bar.build/main.m.o " :
1662
+ tool: clang
1663
+ description: " Compiling Bar main.m "
1664
+ inputs: [ " /path/to/build/debug/libFoo \( dynamicLibraryExtension) " , " /PkgA/Sources/Bar/main.m " ]
1665
+ """ ) )
1666
+ }
1667
+ }
1484
1668
}
1485
1669
1486
1670
// MARK:- Test Helpers
0 commit comments