Skip to content

Commit bd8c29c

Browse files
committed
Fix bug, add test resources, add TODOs
- A few commits ago, the public headers were added to the header search paths (HSP) of clients. This meant Clang clients could import public headers. One bug fixed in this commit was that the generated interop header needed to be added to the HSP. This was done by adding the generated interop header to the Product all-product-headers.yaml overlay file. - A few tests were added/modified to appropriately test that Clang clients could import all public headers (including generated ones) of a mixed test target. - A few TODOs related to detecting C++ files were added to be discussed during PR review. - One TODO was added to track a remaining bug: This bug is a warning that comes from the generated bridging header being overlayed within the public headers directory. Clang will sometimes complain that the target's umbrella header (if one exists) does not include the generated bridging header.
1 parent 041adf3 commit bd8c29c

26 files changed

+248
-28
lines changed

Fixtures/MixedTargets/BasicMixedTargets/Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ let package = Package(
6666
.target(
6767
name: "MixedTargetWithCustomModuleMap"
6868
),
69+
.testTarget(
70+
name: "MixedTargetWithCustomModuleMapTests",
71+
dependencies: ["MixedTargetWithCustomModuleMap"]
72+
),
6973

7074
// MARK: - MixedTargetWithInvalidCustomModuleMap
7175
.target(

Fixtures/MixedTargets/BasicMixedTargets/Sources/MixedTargetWithCustomModuleMap/Driver.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
#import "Driver.h"
55
#import "include/Driver.h"
66

7-
@implementation Driver
7+
@implementation MyDriver
88
@end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import Foundation
22

33
// This type is Objective-C compatible and used in `OldCar`.
4-
@objc public class Engine: NSObject {}
4+
@objc public class Engine: MyMachine {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import <Foundation/Foundation.h>
2+
3+
// Both import statements should be supported.
4+
#import "Machine.h"
5+
#import "include/Machine.h"
6+
7+
@implementation MyMachine
8+
@end

Fixtures/MixedTargets/BasicMixedTargets/Sources/MixedTargetWithCustomModuleMap/NewCar.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import Foundation
33
public class NewCar {
44
// `Engine` is defined in Swift.
55
var engine: Engine? = nil
6-
// `Driver` is defined in Objective-C.
7-
var driver: Driver? = nil
6+
// `MyDriver` is defined in Objective-C.
7+
var driver: MyDriver? = nil
8+
9+
public init() {}
810
}

Fixtures/MixedTargets/BasicMixedTargets/Sources/MixedTargetWithCustomModuleMap/OldCar.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// Import the Swift part of the module.
88
#import "MixedTargetWithCustomModuleMap-Swift.h"
99

10-
@implementation OldCar
10+
@implementation MyOldCar
1111
@end
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#import <Foundation/Foundation.h>
22

33
// This type is Swift compatible and used in `NewCar`.
4-
@interface Driver : NSObject
4+
// `My` prefix is to avoid naming collision in test bundle.
5+
@interface MyDriver : NSObject
56
@property(nonnull) NSString* name;
67
@end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import <Foundation/Foundation.h>
2+
3+
// This type is subclassed by the Swift type `Engine`.
4+
// `My` prefix is to avoid naming collision in test bundle.
5+
@interface MyMachine : NSObject
6+
@end
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
#import "Machine.h"
12
#import "OldCar.h"
23
#import "Driver.h"

Fixtures/MixedTargets/BasicMixedTargets/Sources/MixedTargetWithCustomModuleMap/include/OldCar.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
// must be forward declared in headers.
77
@class Engine;
88

9-
@interface OldCar : NSObject
9+
// `My` prefix is to avoid naming collision in test bundle.
10+
@interface MyOldCar : NSObject
1011
// `Engine` is defined in Swift.
1112
@property(nullable) Engine *engine;
1213
// `Driver` is defined in Objective-C.
13-
@property(nullable) Driver *driver;
14+
@property(nullable) MyDriver *driver;
1415
@end
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module MixedTargetWithCustomModuleMapAndResources {
2-
umbrella header "MixedTarget.h"
2+
umbrella header "MixedTargetWithCustomModuleMapAndResources.h"
33
export *
44
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#import <XCTest/XCTest.h>
2+
3+
#import "BasicMixedTarget-Swift.h"
4+
#import "BasicMixedTarget/BasicMixedTarget.h"
5+
6+
@interface ObjcBasicMixedTargetTestsViaBridgingHeader : XCTestCase
7+
8+
@end
9+
10+
@implementation ObjcBasicMixedTargetTestsViaBridgingHeader
11+
12+
- (void)testPublicSwiftAPI {
13+
// Check that Objective-C compatible Swift API surface is exposed...
14+
Engine *engine = [[Engine alloc] init];
15+
}
16+
17+
- (void)testPublicObjcAPI {
18+
// Check that Objective-C API surface is exposed...
19+
OldCar *oldCar = [[OldCar alloc] init];
20+
Driver *driver = [[Driver alloc] init];
21+
CarPart *carPart = [[CarPart alloc] init];
22+
}
23+
24+
@end

Fixtures/MixedTargets/BasicMixedTargets/Tests/BasicMixedTargetTests/ObjcBasicMixedTargetTests.m renamed to Fixtures/MixedTargets/BasicMixedTargets/Tests/BasicMixedTargetTests/ObjcBasicMixedTargetTestsViaHeaderImport.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
@import BasicMixedTarget;
44

5-
@interface ObjcBasicMixedTargetTests : XCTestCase
5+
@interface ObjcBasicMixedTargetTestsViaHeaderImport : XCTestCase
66

77
@end
88

9-
@implementation ObjcBasicMixedTargetTests
9+
@implementation ObjcBasicMixedTargetTestsViaHeaderImport
1010

1111
- (void)testPublicSwiftAPI {
1212
// Check that Objective-C compatible Swift API surface is exposed...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import <XCTest/XCTest.h>
2+
3+
#import "CarPart.h"
4+
#import "Driver.h"
5+
#import "OldCar.h"
6+
#import "BasicMixedTarget-Swift.h"
7+
8+
@interface ObjcBasicMixedTargetTestsViaModuleImport : XCTestCase
9+
10+
@end
11+
12+
@implementation ObjcBasicMixedTargetTestsViaModuleImport
13+
14+
- (void)testPublicSwiftAPI {
15+
// Check that Objective-C compatible Swift API surface is exposed...
16+
Engine *engine = [[Engine alloc] init];
17+
}
18+
19+
- (void)testPublicObjcAPI {
20+
// Check that Objective-C API surface is exposed...
21+
OldCar *oldCar = [[OldCar alloc] init];
22+
Driver *driver = [[Driver alloc] init];
23+
CarPart *carPart = [[CarPart alloc] init];
24+
}
25+
26+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#import <XCTest/XCTest.h>
2+
3+
// Import the target via header imports.
4+
#import <BasicMixedTargetWithManualBridgingHeader/BasicMixedTargetWithManualBridgingHeader.h>
5+
#import <BasicMixedTargetWithManualBridgingHeader/OldPlane.h>
6+
#import <BasicMixedTargetWithManualBridgingHeader/Pilot.h>
7+
#import <BasicMixedTargetWithManualBridgingHeader/PlanePart.h>
8+
#import <BasicMixedTargetWithManualBridgingHeader-Swift.h>
9+
10+
@interface ObjcBasicMixedTargetWithManualBridgingHeaderTestsViaHeaderImport : XCTestCase
11+
12+
@end
13+
14+
@implementation ObjcBasicMixedTargetWithManualBridgingHeaderTestsViaHeaderImport
15+
16+
- (void)testPublicSwiftAPI {
17+
// Check that Objective-C compatible Swift API surface is exposed...
18+
Engine *engine = [[Engine alloc] init];
19+
}
20+
21+
- (void)testPublicObjcAPI {
22+
// Check that Objective-C API surface is exposed...
23+
OldPlane *oldPlane = [[OldPlane alloc] init];
24+
Pilot *pilot = [[Pilot alloc] init];
25+
}
26+
27+
@end
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#import <XCTest/XCTest.h>
22

3+
// Import the target via a module import.
34
@import BasicMixedTargetWithManualBridgingHeader;
45

5-
@interface ObjcBasicMixedTargetWithManualBridgingHeaderTests : XCTestCase
6+
@interface ObjcBasicMixedTargetWithManualBridgingHeaderTestsViaModuleImport : XCTestCase
67

78
@end
89

9-
@implementation ObjcBasicMixedTargetWithManualBridgingHeaderTests
10+
@implementation ObjcBasicMixedTargetWithManualBridgingHeaderTestsViaModuleImport
1011

1112
- (void)testPublicSwiftAPI {
1213
// Check that Objective-C compatible Swift API surface is exposed...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import XCTest
2+
import MixedTargetWithCustomModuleMap
3+
4+
final class MixedTargetWithCustomModuleMapTests: XCTestCase {
5+
6+
func testPublicSwiftAPI() throws {
7+
// Check that Swift API surface is exposed...
8+
let _ = NewCar()
9+
let _ = Engine()
10+
}
11+
12+
func testPublicObjcAPI() throws {
13+
// Check that Objective-C API surface is exposed...
14+
let _ = MyOldCar()
15+
let _ = MyDriver()
16+
let _ = MyMachine()
17+
}
18+
19+
func testModulePrefixingWorks() throws {
20+
let _ = MixedTargetWithCustomModuleMap.MyMachine()
21+
let _ = MixedTargetWithCustomModuleMap.NewCar()
22+
let _ = MixedTargetWithCustomModuleMap.Engine()
23+
let _ = MixedTargetWithCustomModuleMap.MyOldCar()
24+
let _ = MixedTargetWithCustomModuleMap.MyDriver()
25+
}
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#import <XCTest/XCTest.h>
2+
3+
#import "MixedTargetWithCustomModuleMap/MixedTargetWithCustomModuleMap.h"
4+
#import "MixedTargetWithCustomModuleMap-Swift.h"
5+
6+
@interface ObjcMixedTargetWithCustomModuleMapTestsViaGeneratedBridgingHeader : XCTestCase
7+
@end
8+
9+
@implementation ObjcMixedTargetWithCustomModuleMapTestsViaGeneratedBridgingHeader
10+
11+
- (void)testPublicSwiftAPI {
12+
// Check that Objective-C compatible Swift API surface is exposed...
13+
Engine *engine = [[Engine alloc] init];
14+
}
15+
16+
- (void)testPublicObjcAPI {
17+
// Check that Objective-C API surface is exposed...
18+
MyMachine *machine = [[MyMachine alloc] init];
19+
MyOldCar *oldCar = [[MyOldCar alloc] init];
20+
MyDriver *driver = [[MyDriver alloc] init];
21+
}
22+
23+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#import <XCTest/XCTest.h>
2+
3+
#import "Machine.h"
4+
#import "MixedTarget.h"
5+
#import "Driver.h"
6+
#import "OldCar.h"
7+
#import "MixedTargetWithCustomModuleMap-Swift.h"
8+
9+
@interface ObjcMixedTargetWithCustomModuleMapTestsViaHeaderImport : XCTestCase
10+
@end
11+
12+
@implementation ObjcMixedTargetWithCustomModuleMapTestsViaHeaderImport
13+
14+
- (void)testPublicSwiftAPI {
15+
// Check that Objective-C compatible Swift API surface is exposed...
16+
Engine *engine = [[Engine alloc] init];
17+
}
18+
19+
- (void)testPublicObjcAPI {
20+
// Check that Objective-C API surface is exposed...
21+
MyMachine *machine = [[MyMachine alloc] init];
22+
MyOldCar *oldCar = [[MyOldCar alloc] init];
23+
MyDriver *driver = [[MyDriver alloc] init];
24+
}
25+
26+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#import <XCTest/XCTest.h>
2+
3+
@import MixedTargetWithCustomModuleMap;
4+
5+
@interface ObjcMixedTargetWithCustomModuleMapTestsViaModuleImport : XCTestCase
6+
@end
7+
8+
@implementation ObjcMixedTargetWithCustomModuleMapTestsViaModuleImport
9+
10+
- (void)testPublicSwiftAPI {
11+
// Check that Objective-C compatible Swift API surface is exposed...
12+
Engine *engine = [[Engine alloc] init];
13+
}
14+
15+
- (void)testPublicObjcAPI {
16+
// Check that Objective-C API surface is exposed...
17+
MyMachine *machine = [[MyMachine alloc] init];
18+
MyOldCar *oldCar = [[MyOldCar alloc] init];
19+
MyDriver *driver = [[MyDriver alloc] init];
20+
}
21+
22+
@end
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
#import "ObjcCalculator.h"
55
#import "MixedTargetWithPublicCXXAPI-Swift.h"
66

7-
@interface ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests : XCTestCase
7+
@interface ObjcMixedTargetWithPublicCXXAPITestsViaHeaderImport : XCTestCase
88
@end
99

10-
@implementation ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests
10+
@implementation ObjcMixedTargetWithPublicCXXAPITestsViaHeaderImport
1111

1212
- (void)testPublicObjcAPI {
1313
XCTAssertEqual([ObjcCalculator factorialForInt:5], 120);
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
@import MixedTargetWithPublicCXXAPI;
44

5-
@interface ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests : XCTestCase
5+
@interface ObjcMixedTargetWithPublicCXXAPITestsViaModuleImport : XCTestCase
66
@end
77

8-
@implementation ObjcMixedTargetWithPublicCXXAPIViaModuleImportTests
8+
@implementation ObjcMixedTargetWithPublicCXXAPITestsViaModuleImport
99

1010
- (void)testPublicObjcAPI {
1111
XCTAssertEqual([ObjcCalculator factorialForInt:5], 120);

0 commit comments

Comments
 (0)