@@ -6936,4 +6936,86 @@ final class BuildPlanTests: XCTestCase {
69366936 XCTAssertMatch ( contents, . regex( #"args: \[.*"-I","/testpackagedep/SomeArtifact.xcframework/macos/Headers".*,"/testpackage/Sources/CLib/lib.c".*]"# ) )
69376937 XCTAssertMatch ( contents, . regex( #"args: \[.*"-module-name","SwiftLib",.*"-I","/testpackagedep/SomeArtifact.xcframework/macos/Headers".*]"# ) )
69386938 }
6939+
6940+ func testMacroPluginDependencyLeakage( ) async throws {
6941+ // Make sure the include paths from macro and plugin executables don't leak into dependents
6942+ let observability = ObservabilitySystem . makeForTesting ( )
6943+ let fs = InMemoryFileSystem ( emptyFiles: [
6944+ " /LeakTest/Sources/CLib/include/Clib.h " ,
6945+ " /LeakTest/Sources/CLib/Clib.c " ,
6946+ " /LeakTest/Sources/MyMacro/MyMacro.swift " ,
6947+ " /LeakTest/Sources/MyPluginTool/MyPluginTool.swift " ,
6948+ " /LeakTest/Sources/MyLib/MyLib.swift " ,
6949+ " /LeakTest/Plugins/MyPlugin/MyPlugin.swift " ,
6950+ " /LeakTest/Tests/MyMacroTests/MyMacroTests.swift " ,
6951+ " /LeakTest/Tests/MyMacro2Tests/MyMacro2Tests.swift " ,
6952+ " /LeakLib/Sources/CLib2/include/Clib.h " ,
6953+ " /LeakLib/Sources/CLib2/Clib.c " ,
6954+ " /LeakLib/Sources/MyMacro2/MyMacro.swift " ,
6955+ " /LeakLib/Sources/MyPluginTool2/MyPluginTool.swift " ,
6956+ " /LeakLib/Sources/MyLib2/MyLib.swift " ,
6957+ " /LeakLib/Plugins/MyPlugin2/MyPlugin.swift " ,
6958+ ] )
6959+
6960+ let graph = try loadModulesGraph ( fileSystem: fs, manifests: [
6961+ Manifest . createFileSystemManifest (
6962+ displayName: " LeakLib " ,
6963+ path: " /LeakLib " ,
6964+ products: [
6965+ ProductDescription ( name: " MyLib2 " , type: . library( . automatic) , targets: [ " MyLib2 " ] ) ,
6966+ ProductDescription ( name: " MyMacros2 " , type: . macro, targets: [ " MyMacro2 " ] ) ,
6967+ ] ,
6968+ targets: [
6969+ TargetDescription ( name: " CLib2 " ) ,
6970+ TargetDescription ( name: " MyMacro2 " , dependencies: [ " CLib2 " ] , type: . macro) ,
6971+ TargetDescription ( name: " MyPluginTool2 " , dependencies: [ " CLib2 " ] , type: . executable) ,
6972+ TargetDescription ( name: " MyPlugin2 " , dependencies: [ " MyPluginTool2 " ] , type: . plugin, pluginCapability: . buildTool) ,
6973+ TargetDescription ( name: " MyLib2 " , dependencies: [ " CLib2 " , " MyMacro2 " ] , pluginUsages: [ . plugin( name: " MyPlugin2 " , package : nil ) ] ) ,
6974+ ]
6975+ ) ,
6976+ Manifest . createRootManifest (
6977+ displayName: " LeakTest " ,
6978+ path: " /LeakTest " ,
6979+ dependencies: [
6980+ . fileSystem( path: " /LeakLib " )
6981+ ] ,
6982+ targets: [
6983+ TargetDescription ( name: " CLib " ) ,
6984+ TargetDescription ( name: " MyMacro " , dependencies: [ " CLib " ] , type: . macro) ,
6985+ TargetDescription ( name: " MyPluginTool " , dependencies: [ " CLib " ] , type: . executable) ,
6986+ TargetDescription ( name: " MyPlugin " , dependencies: [ " MyPluginTool " ] , type: . plugin, pluginCapability: . buildTool) ,
6987+ TargetDescription (
6988+ name: " MyLib " ,
6989+ dependencies: [ " CLib " , " MyMacro " , . product( name: " MyLib2 " , package : " LeakLib " ) ] ,
6990+ pluginUsages: [ . plugin( name: " MyPlugin " , package : nil ) ]
6991+ ) ,
6992+ TargetDescription ( name: " MyMacroTests " , dependencies: [ " MyMacro " ] , type: . test) ,
6993+ TargetDescription (
6994+ name: " MyMacro2Tests " ,
6995+ dependencies: [ . product( name: " MyMacros2 " , package : " LeakLib " ) ] ,
6996+ type: . test
6997+ )
6998+ ]
6999+ )
7000+ ] , observabilityScope: observability. topScope)
7001+ XCTAssertNoDiagnostics ( observability. diagnostics)
7002+
7003+ let plan = try await mockBuildPlan (
7004+ graph: graph,
7005+ fileSystem: fs,
7006+ observabilityScope: observability. topScope
7007+ )
7008+ XCTAssertNoDiagnostics ( observability. diagnostics)
7009+
7010+ let myLib = try XCTUnwrap ( plan. targets. first ( where: { $0. module. name == " MyLib " } ) ) . swift ( )
7011+ XCTAssertFalse ( myLib. additionalFlags. contains ( where: { $0. contains ( " -tool " ) } ) , " flags shouldn't contain tools items " )
7012+
7013+ // Make sure the tests do have the include path and the module map from the lib
7014+ let myMacroTests = try XCTUnwrap ( plan. targets. first ( where: { $0. module. name == " MyMacroTests " } ) ) . swift ( )
7015+ XCTAssertTrue ( myMacroTests. additionalFlags. contains ( where: { $0. contains ( " CLib/include " ) } ) )
7016+ XCTAssertTrue ( myMacroTests. additionalFlags. contains ( where: { $0. contains ( " CLib-tool.build/module.modulemap " ) } ) )
7017+ let myMacro2Tests = try XCTUnwrap ( plan. targets. first ( where: { $0. module. name == " MyMacro2Tests " } ) ) . swift ( )
7018+ XCTAssertTrue ( myMacro2Tests. additionalFlags. contains ( where: { $0. contains ( " CLib2/include " ) } ) )
7019+ XCTAssertTrue ( myMacro2Tests. additionalFlags. contains ( where: { $0. contains ( " CLib2-tool.build/module.modulemap " ) } ) )
7020+ }
69397021}
0 commit comments