@@ -1460,6 +1460,233 @@ class PIFBuilderTests: XCTestCase {
1460
1460
}
1461
1461
}
1462
1462
1463
+ func testPIFGenWithModuleAliases( ) throws {
1464
+ #if !os(macOS)
1465
+ try XCTSkipIf ( true , " test is only supported on macOS " )
1466
+ #endif
1467
+ let fs = InMemoryFileSystem ( emptyFiles:
1468
+ " /App/Sources/App/main.swift " ,
1469
+ " /App/Sources/Logging/lib.swift " ,
1470
+ " /App/Sources/Utils/lib.swift " ,
1471
+ " /Bar/Sources/Lib/lib.swift " ,
1472
+ " /Bar/Sources/Logging/lib.swift "
1473
+ )
1474
+
1475
+ let observability = ObservabilitySystem . makeForTesting ( )
1476
+ let graph = try loadPackageGraph (
1477
+ fs: fs,
1478
+ manifests: [
1479
+ Manifest . createRootManifest (
1480
+ name: " App " ,
1481
+ path: . init( " /App " ) ,
1482
+ dependencies: [
1483
+ . localSourceControl( path: . init( " /Bar " ) , requirement: . branch( " main " ) ) ,
1484
+ ] ,
1485
+ targets: [
1486
+ . init( name: " App " , dependencies: [ " Logging " , " Utils " ] , type: . executable) ,
1487
+ . init( name: " Logging " , dependencies: [ ] ) ,
1488
+ . init( name: " Utils " , dependencies: [
1489
+ . product( name: " BarLib " , package : " Bar " , moduleAliases: [ " Logging " : " BarLogging " ] ) ,
1490
+ ] ) ,
1491
+ ] ) ,
1492
+ Manifest . createLocalSourceControlManifest (
1493
+ name: " Bar " ,
1494
+ path: . init( " /Bar " ) ,
1495
+ products: [
1496
+ . init( name: " BarLib " , type: . library( . dynamic) , targets: [ " Lib " ] ) ,
1497
+ ] ,
1498
+ targets: [
1499
+ . init( name: " Lib " , dependencies: [ " Logging " ] ) ,
1500
+ . init( name: " Logging " , dependencies: [ ] ) ,
1501
+ ] ) ,
1502
+ ] ,
1503
+ observabilityScope: observability. topScope
1504
+ )
1505
+
1506
+ var pif : PIF . TopLevelObject !
1507
+ try ! withCustomEnv ( [ " PKG_CONFIG_PATH " : inputsDir. pathString] ) {
1508
+ let builder = PIFBuilder (
1509
+ graph: graph,
1510
+ parameters: . mock( ) ,
1511
+ fileSystem: localFileSystem,
1512
+ observabilityScope: observability. topScope
1513
+ )
1514
+ pif = try builder. construct ( )
1515
+ }
1516
+
1517
+ XCTAssertNoDiagnostics ( observability. diagnostics)
1518
+
1519
+ PIFTester ( pif) { workspace in
1520
+ workspace. checkProject ( " PACKAGE:/App " ) { project in
1521
+ project. checkTarget ( " PACKAGE-PRODUCT:App " ) { target in
1522
+ XCTAssertEqual ( target. name, " App_1DA2DD44_PackageProduct " )
1523
+ XCTAssertEqual ( target. productType, . executable)
1524
+ XCTAssertEqual ( target. productName, " App " )
1525
+ XCTAssertEqual ( target. dependencies, [
1526
+ " PACKAGE-TARGET:Utils " ,
1527
+ " PACKAGE-TARGET:Logging " ,
1528
+ " PACKAGE-PRODUCT:BarLib " ,
1529
+ ] )
1530
+ XCTAssertEqual ( target. frameworks, [
1531
+ " PACKAGE-TARGET:Utils " ,
1532
+ " PACKAGE-TARGET:Logging " ,
1533
+ " PACKAGE-PRODUCT:BarLib " ,
1534
+ ] )
1535
+
1536
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1537
+ XCTAssertEqual ( configuration. guid, " PACKAGE-PRODUCT:App::BUILDCONFIG_Debug " )
1538
+ XCTAssertEqual ( configuration. name, " Debug " )
1539
+ configuration. checkBuildSettings { settings in
1540
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1541
+ }
1542
+ }
1543
+
1544
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1545
+ XCTAssertEqual ( configuration. guid, " PACKAGE-PRODUCT:App::BUILDCONFIG_Release " )
1546
+ XCTAssertEqual ( configuration. name, " Release " )
1547
+ configuration. checkBuildSettings { settings in
1548
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1549
+ }
1550
+ }
1551
+ }
1552
+
1553
+ project. checkTarget ( " PACKAGE-TARGET:Utils " ) { target in
1554
+ XCTAssertEqual ( target. name, " Utils " )
1555
+ XCTAssertEqual ( target. productType, . objectFile)
1556
+ XCTAssertEqual ( target. productName, " Utils.o " )
1557
+ XCTAssertEqual ( target. dependencies, [
1558
+ " PACKAGE-PRODUCT:BarLib " ,
1559
+ ] )
1560
+
1561
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1562
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Utils::BUILDCONFIG_Debug " )
1563
+ XCTAssertEqual ( configuration. name, " Debug " )
1564
+ configuration. checkBuildSettings { settings in
1565
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1566
+ }
1567
+ }
1568
+
1569
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1570
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Utils::BUILDCONFIG_Release " )
1571
+ XCTAssertEqual ( configuration. name, " Release " )
1572
+ configuration. checkBuildSettings { settings in
1573
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1574
+ }
1575
+ }
1576
+
1577
+ }
1578
+ project. checkTarget ( " PACKAGE-TARGET:Logging " ) { target in
1579
+ XCTAssertEqual ( target. name, " Logging " )
1580
+ XCTAssertEqual ( target. productType, . objectFile)
1581
+ XCTAssertEqual ( target. productName, " Logging.o " )
1582
+ XCTAssertEqual ( target. dependencies, [ ] )
1583
+
1584
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1585
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Logging::BUILDCONFIG_Debug " )
1586
+ XCTAssertEqual ( configuration. name, " Debug " )
1587
+ configuration. checkBuildSettings { settings in
1588
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1589
+ }
1590
+ }
1591
+
1592
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1593
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Logging::BUILDCONFIG_Release " )
1594
+ XCTAssertEqual ( configuration. name, " Release " )
1595
+ configuration. checkBuildSettings { settings in
1596
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1597
+ }
1598
+ }
1599
+ }
1600
+ }
1601
+
1602
+ workspace. checkProject ( " PACKAGE:/Bar " ) { project in
1603
+ project. checkTarget ( " PACKAGE-PRODUCT:BarLib " ) { target in
1604
+ XCTAssertEqual ( target. name, " BarLib_175D063FAE17B2_PackageProduct " )
1605
+ XCTAssertEqual ( target. productType, . framework)
1606
+ XCTAssertEqual ( target. productName, " BarLib.framework " )
1607
+ XCTAssertEqual ( target. dependencies, [ " PACKAGE-TARGET:BarLogging " , " PACKAGE-TARGET:Lib " ] )
1608
+ XCTAssertEqual ( target. frameworks, [ " PACKAGE-TARGET:BarLogging " , " PACKAGE-TARGET:Lib " ] )
1609
+
1610
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1611
+ XCTAssertEqual ( configuration. guid, " PACKAGE-PRODUCT:BarLib::BUILDCONFIG_Debug " )
1612
+ XCTAssertEqual ( configuration. name, " Debug " )
1613
+ configuration. checkBuildSettings { settings in
1614
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1615
+ XCTAssertEqual ( settings [ . PRODUCT_MODULE_NAME] , " BarLib " )
1616
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " BarLib " )
1617
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " BarLib " )
1618
+ }
1619
+ }
1620
+
1621
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1622
+ XCTAssertEqual ( configuration. guid, " PACKAGE-PRODUCT:BarLib::BUILDCONFIG_Release " )
1623
+ XCTAssertEqual ( configuration. name, " Release " )
1624
+ configuration. checkBuildSettings { settings in
1625
+ XCTAssertNil ( settings [ . SWIFT_MODULE_ALIASES] )
1626
+ XCTAssertEqual ( settings [ . PRODUCT_MODULE_NAME] , " BarLib " )
1627
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " BarLib " )
1628
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " BarLib " )
1629
+ }
1630
+ }
1631
+ }
1632
+ project. checkTarget ( " PACKAGE-TARGET:BarLogging " ) { target in
1633
+ XCTAssertEqual ( target. name, " BarLogging " )
1634
+ XCTAssertEqual ( target. productType, . objectFile)
1635
+ XCTAssertEqual ( target. productName, " BarLogging.o " )
1636
+ XCTAssertEqual ( target. dependencies, [ ] )
1637
+ XCTAssertEqual ( target. frameworks, [ ] )
1638
+
1639
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1640
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:BarLogging::BUILDCONFIG_Debug " )
1641
+ XCTAssertEqual ( configuration. name, " Debug " )
1642
+ configuration. checkBuildSettings { settings in
1643
+ XCTAssertEqual ( settings [ . SWIFT_MODULE_ALIASES] , [ " Logging=BarLogging " ] )
1644
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " BarLogging.o " )
1645
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " BarLogging " )
1646
+ }
1647
+ }
1648
+
1649
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1650
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:BarLogging::BUILDCONFIG_Release " )
1651
+ XCTAssertEqual ( configuration. name, " Release " )
1652
+ configuration. checkBuildSettings { settings in
1653
+ XCTAssertEqual ( settings [ . SWIFT_MODULE_ALIASES] , [ " Logging=BarLogging " ] )
1654
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " BarLogging.o " )
1655
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " BarLogging " )
1656
+ }
1657
+ }
1658
+ }
1659
+ project. checkTarget ( " PACKAGE-TARGET:Lib " ) { target in
1660
+ XCTAssertEqual ( target. name, " Lib " )
1661
+ XCTAssertEqual ( target. productType, . objectFile)
1662
+ XCTAssertEqual ( target. productName, " Lib.o " )
1663
+ XCTAssertEqual ( target. dependencies, [ " PACKAGE-TARGET:BarLogging " ] )
1664
+ XCTAssertEqual ( target. frameworks, [ ] )
1665
+
1666
+ target. checkBuildConfiguration ( " Debug " ) { configuration in
1667
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Lib::BUILDCONFIG_Debug " )
1668
+ XCTAssertEqual ( configuration. name, " Debug " )
1669
+ configuration. checkBuildSettings { settings in
1670
+ XCTAssertEqual ( settings [ . SWIFT_MODULE_ALIASES] , [ " Logging=BarLogging " ] )
1671
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " Lib.o " )
1672
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " Lib " )
1673
+ }
1674
+ }
1675
+
1676
+ target. checkBuildConfiguration ( " Release " ) { configuration in
1677
+ XCTAssertEqual ( configuration. guid, " PACKAGE-TARGET:Lib::BUILDCONFIG_Release " )
1678
+ XCTAssertEqual ( configuration. name, " Release " )
1679
+ configuration. checkBuildSettings { settings in
1680
+ XCTAssertEqual ( settings [ . SWIFT_MODULE_ALIASES] , [ " Logging=BarLogging " ] )
1681
+ XCTAssertEqual ( settings [ . PRODUCT_NAME] , " Lib.o " )
1682
+ XCTAssertEqual ( settings [ . TARGET_NAME] , " Lib " )
1683
+ }
1684
+ }
1685
+ }
1686
+ }
1687
+ }
1688
+ }
1689
+
1463
1690
func testLibraryTargetsAsDylib( ) throws {
1464
1691
#if !os(macOS)
1465
1692
try XCTSkipIf ( true , " test is only supported on macOS " )
0 commit comments