Skip to content

Do not report missing dependencies between targets in different domains #344

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

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/SWBBuildSystem/BuildOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,10 @@ package final class BuildOperation: BuildSystemOperation {
guard targetSettings.platform?.name == antecedentSettings.platform?.name && targetSettings.sdkVariant?.name == antecedentSettings.sdkVariant?.name else {
return
}
// Implicit dependency domains allow projects to build multiple copies of a module in a workspace with implicit dependencies enabled, so never diagnose a cross-domain dependency.
guard targetSettings.globalScope.evaluate(BuiltinMacros.IMPLICIT_DEPENDENCY_DOMAIN) == antecedentSettings.globalScope.evaluate(BuiltinMacros.IMPLICIT_DEPENDENCY_DOMAIN) else {
return
}

let message: DiagnosticData
if self.userPreferences.enableDebugActivityLogs {
Expand Down
99 changes: 95 additions & 4 deletions Tests/SWBBuildSystemTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4518,7 +4518,7 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.macOS), .disabled(if: getEnvironmentVariable("CI")?.isEmpty == false, "Test relies on timing which would require costly delays in CI"))
@Test(.requireSDKs(.macOS))
func diagnosingMissingTargetDependencies() async throws {
try await withTemporaryDirectory { tmpDir in
let testWorkspace = try await TestWorkspace(
Expand Down Expand Up @@ -4565,8 +4565,6 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {
"Framework3",
type: .framework,
buildPhases: [
// Ensure that we always happen to build the targets in the right order, even though the dependency is missing.
TestShellScriptBuildPhase(name: "Sleep", originalObjectID: "A", contents: "sleep 10", alwaysOutOfDate: true),
TestSourcesBuildPhase(["file_3.swift"]),
]),
])])
Expand Down Expand Up @@ -4610,7 +4608,7 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {

for warningLevel in [BooleanWarningLevel.yes, .yesError] {
let parameters = BuildParameters(configuration: "Debug", overrides: ["DIAGNOSE_MISSING_TARGET_DEPENDENCIES": warningLevel.rawValue])
let buildRequest = BuildRequest(parameters: parameters, buildTargets: tester.workspace.projects[0].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }), continueBuildingAfterErrors: false, useParallelTargets: true, useImplicitDependencies: false, useDryRun: false)
let buildRequest = BuildRequest(parameters: parameters, buildTargets: tester.workspace.projects[0].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }), continueBuildingAfterErrors: false, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on deprecated manual ordering isn't ideal, but it's better than script phases calling sleep IMO


try await tester.checkBuild(runDestination: .macOS, buildRequest: buildRequest, persistent: true) { results in
switch warningLevel {
Expand All @@ -4631,6 +4629,99 @@ fileprivate struct SwiftDriverTests: CoreBasedTests {
}
}

@Test(.requireSDKs(.macOS))
func diagnosingMissingTargetDependenciesWithDependencyDomains() async throws {
try await withTemporaryDirectory { tmpDir in
let testWorkspace = try await TestWorkspace(
"Test",
sourceRoot: tmpDir.join("Test"),
projects: [
TestProject(
"aProject",
groupTree: TestGroup(
"Sources",
children: [
TestFile("Framework1.h"),
TestFile("file_1.c"),
TestFile("file_2.swift"),
]),
buildConfigurations: [TestBuildConfiguration(
"Debug",
buildSettings: [
"PRODUCT_NAME": "$(TARGET_NAME)",
"CLANG_ENABLE_MODULES": "YES",
"_EXPERIMENTAL_CLANG_EXPLICIT_MODULES": "YES",
"SWIFT_ENABLE_EXPLICIT_MODULES": "YES",
"SWIFT_VERSION": swiftVersion,
"DEFINES_MODULE": "YES",
"VALID_ARCHS": "arm64",
"DSTROOT": tmpDir.join("dstroot").str,
"DIAGNOSE_MISSING_TARGET_DEPENDENCIES": "YES",
])],
targets: [
TestStandardTarget(
"Framework1",
type: .framework,
buildConfigurations: [TestBuildConfiguration(
"Debug",
buildSettings: [
"IMPLICIT_DEPENDENCY_DOMAIN": "One"
])],
buildPhases: [
TestHeadersBuildPhase([TestBuildFile("Framework1.h", headerVisibility: .public)]),
TestSourcesBuildPhase(["file_1.c"]),
]),
TestStandardTarget(
"Framework2",
type: .framework,
buildConfigurations: [TestBuildConfiguration(
"Debug",
buildSettings: [
"IMPLICIT_DEPENDENCY_DOMAIN": "Two"
])],
buildPhases: [
TestSourcesBuildPhase(["file_2.swift"]),
]),
])])

let tester = try await BuildOperationTester(getCore(), testWorkspace, simulated: false)

try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/Framework1.h")) { stream in
stream <<<
"""
void foo(void);
"""
}

try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file_1.c")) { stream in
stream <<<
"""
#include <Framework1/Framework1.h>
void foo(void) {}
"""
}

try await tester.fs.writeFileContents(testWorkspace.sourceRoot.join("aProject/file_2.swift")) { stream in
stream <<<
"""
import Framework1
public func baz() {
foo()
}
"""
}

let parameters = BuildParameters(configuration: "Debug")
let buildRequest = BuildRequest(parameters: parameters, buildTargets: tester.workspace.projects[0].targets.map({ BuildRequest.BuildTargetInfo(parameters: parameters, target: $0) }), continueBuildingAfterErrors: false, useParallelTargets: false, useImplicitDependencies: false, useDryRun: false)

try await tester.checkBuild(runDestination: .macOS, buildRequest: buildRequest, persistent: true) { results in
// Normally, we would report "'Framework2' is missing a dependency on 'Framework1' because dependency scan of Swift module 'Framework2' discovered a dependency on 'Framework1'"
// However, because the targets are in different domains, we shouldn't report any diagnostics.
results.checkNoDiagnostics()
}
}
}

@Test(.requireSDKs(.macOS))
func explicitPCMDeduplicationWithBuildVariant() async throws {
try await withTemporaryDirectory { tmpDirPath async throws -> Void in
Expand Down