-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[6.1] Fix duplicate modulemap errors with macro and plugin deps (#8472) #8491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/6.1
Are you sure you want to change the base?
Changes from all commits
ed30d34
1eee904
f5c4413
f52c354
df20ebf
007f295
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6842,4 +6842,86 @@ final class BuildPlanTests: XCTestCase { | |
XCTAssertMatch(contents, .regex(#"args: \[.*"-I","/testpackagedep/SomeArtifact.xcframework/macos/Headers".*,"/testpackage/Sources/CLib/lib.c".*]"#)) | ||
XCTAssertMatch(contents, .regex(#"args: \[.*"-module-name","SwiftLib",.*"-I","/testpackagedep/SomeArtifact.xcframework/macos/Headers".*]"#)) | ||
} | ||
|
||
func testMacroPluginDependencyLeakage() async throws { | ||
// Make sure the include paths from macro and plugin executables don't leak into dependents | ||
let observability = ObservabilitySystem.makeForTesting() | ||
let fs = InMemoryFileSystem(emptyFiles: [ | ||
"/LeakTest/Sources/CLib/include/Clib.h", | ||
"/LeakTest/Sources/CLib/Clib.c", | ||
"/LeakTest/Sources/MyMacro/MyMacro.swift", | ||
"/LeakTest/Sources/MyPluginTool/MyPluginTool.swift", | ||
"/LeakTest/Sources/MyLib/MyLib.swift", | ||
"/LeakTest/Plugins/MyPlugin/MyPlugin.swift", | ||
"/LeakTest/Tests/MyMacroTests/MyMacroTests.swift", | ||
"/LeakTest/Tests/MyMacro2Tests/MyMacro2Tests.swift", | ||
"/LeakLib/Sources/CLib2/include/Clib.h", | ||
"/LeakLib/Sources/CLib2/Clib.c", | ||
"/LeakLib/Sources/MyMacro2/MyMacro.swift", | ||
"/LeakLib/Sources/MyPluginTool2/MyPluginTool.swift", | ||
"/LeakLib/Sources/MyLib2/MyLib.swift", | ||
"/LeakLib/Plugins/MyPlugin2/MyPlugin.swift", | ||
]) | ||
|
||
let graph = try loadModulesGraph(fileSystem: fs, manifests: [ | ||
Manifest.createFileSystemManifest( | ||
displayName: "LeakLib", | ||
path: "/LeakLib", | ||
products: [ | ||
ProductDescription(name: "MyLib2", type: .library(.automatic), targets: ["MyLib2"]), | ||
ProductDescription(name: "MyMacros2", type: .macro, targets: ["MyMacro2"]), | ||
], | ||
targets: [ | ||
TargetDescription(name: "CLib2"), | ||
TargetDescription(name: "MyMacro2", dependencies: ["CLib2"], type: .macro), | ||
TargetDescription(name: "MyPluginTool2", dependencies: ["CLib2"], type: .executable), | ||
TargetDescription(name: "MyPlugin2", dependencies: ["MyPluginTool2"], type: .plugin, pluginCapability: .buildTool), | ||
TargetDescription(name: "MyLib2", dependencies: ["CLib2", "MyMacro2"], pluginUsages: [.plugin(name: "MyPlugin2", package: nil)]), | ||
] | ||
), | ||
Manifest.createRootManifest( | ||
displayName: "LeakTest", | ||
path: "/LeakTest", | ||
dependencies: [ | ||
.fileSystem(path: "/LeakLib") | ||
], | ||
targets: [ | ||
TargetDescription(name: "CLib"), | ||
TargetDescription(name: "MyMacro", dependencies: ["CLib"], type: .macro), | ||
TargetDescription(name: "MyPluginTool", dependencies: ["CLib"], type: .executable), | ||
TargetDescription(name: "MyPlugin", dependencies: ["MyPluginTool"], type: .plugin, pluginCapability: .buildTool), | ||
TargetDescription( | ||
name: "MyLib", | ||
dependencies: ["CLib", "MyMacro", .product(name: "MyLib2", package: "LeakLib")], | ||
pluginUsages: [.plugin(name: "MyPlugin", package: nil)] | ||
), | ||
TargetDescription(name: "MyMacroTests", dependencies: ["MyMacro"], type: .test), | ||
TargetDescription( | ||
name: "MyMacro2Tests", | ||
dependencies: [.product(name: "MyMacros2", package: "LeakLib")], | ||
type: .test | ||
) | ||
] | ||
) | ||
], observabilityScope: observability.topScope) | ||
XCTAssertNoDiagnostics(observability.diagnostics) | ||
|
||
let plan = try await mockBuildPlan( | ||
graph: graph, | ||
fileSystem: fs, | ||
observabilityScope: observability.topScope | ||
) | ||
XCTAssertNoDiagnostics(observability.diagnostics) | ||
|
||
let myLib = try XCTUnwrap(plan.targets.first(where: { $0.module.name == "MyLib" })).swift() | ||
XCTAssertFalse(myLib.additionalFlags.contains(where: { $0.contains("-tool")}), "flags shouldn't contain tools items") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: the change on branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
// Make sure the tests do have the include path and the module map from the lib | ||
let myMacroTests = try XCTUnwrap(plan.targets.first(where: { $0.module.name == "MyMacroTests" })).swift() | ||
XCTAssertTrue(myMacroTests.additionalFlags.contains(where: { $0.contains("CLib/include") })) | ||
XCTAssertTrue(myMacroTests.additionalFlags.contains(where: { $0.contains("CLib-tool.build/module.modulemap") })) | ||
let myMacro2Tests = try XCTUnwrap(plan.targets.first(where: { $0.module.name == "MyMacro2Tests" })).swift() | ||
XCTAssertTrue(myMacro2Tests.additionalFlags.contains(where: { $0.contains("CLib2/include") })) | ||
XCTAssertTrue(myMacro2Tests.additionalFlags.contains(where: { $0.contains("CLib2-tool.build/module.modulemap") })) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the change on
main
callsswiftTarget.recursiveDependencies
. Is it intentional to call thisrecursiveLinkDependencies
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a new change on main to fix to call LinkDeps. This isn't a cherry pick any more, I am fixing both at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.