Skip to content

Commit 6c258c1

Browse files
authored
Fix overlapping plugins/products build database access (#7273)
This regression was introduced in https://github.com/apple/swift-package-manager/pull/7164/files#diff-7d5950f89d75bc14a591deb8270ebd32308c18248892c7abcb9d0ee3c6b14fd5L201. We can restore the previous behavior in a hacky way by making sure that build parameters passed to plugin builds and invocations have the database path set in the same way as previously. This somewhat defeats the point of tools/products build parameters isolation, but we're able to isolate it only to a few lines in a single function. I've added an explicit test case for this in new `PluginsBuildPlanTests.swift` file, so we can be sure it doesn't regress again. Resolves rdar://120560817
1 parent c0d1c6b commit 6c258c1

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

Sources/Build/BuildOperation.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,16 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
455455
let prebuildCommandResults: [ResolvedTarget.ID: [PrebuildCommandResult]]
456456
// Invoke any build tool plugins in the graph to generate prebuild commands and build commands.
457457
if let pluginConfiguration, !self.productsBuildParameters.shouldSkipBuilding {
458+
// Hacky workaround for rdar://120560817, but it replicates precisely enough the original behavior before
459+
// products/tools build parameters were split. Ideally we want to have specify the correct path at the time
460+
// when `toolsBuildParameters` is initialized, but we have too many places in the codebase where that's
461+
// done, which makes it hard to realign them all at once.
462+
var pluginsBuildParameters = self.toolsBuildParameters
463+
pluginsBuildParameters.dataPath = pluginsBuildParameters.dataPath.parentDirectory.appending(components: ["plugins", "tools"])
458464
let buildOperationForPluginDependencies = BuildOperation(
459-
productsBuildParameters: self.productsBuildParameters,
460-
toolsBuildParameters: self.toolsBuildParameters,
465+
// FIXME: this doesn't maintain the products/tools split cleanly
466+
productsBuildParameters: pluginsBuildParameters,
467+
toolsBuildParameters: pluginsBuildParameters,
461468
cacheBuildManifest: false,
462469
packageGraphLoader: { return graph },
463470
additionalFileRules: self.additionalFileRules,
@@ -469,7 +476,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
469476
)
470477
buildToolPluginInvocationResults = try graph.invokeBuildToolPlugins(
471478
outputDir: pluginConfiguration.workDirectory.appending("outputs"),
472-
buildParameters: self.toolsBuildParameters,
479+
buildParameters: pluginsBuildParameters,
473480
additionalFileRules: self.additionalFileRules,
474481
toolSearchDirectories: [self.toolsBuildParameters.toolchain.swiftCompilerPath.parentDirectory],
475482
pkgConfigDirectories: self.pkgConfigDirectories,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Basics
14+
import SPMTestSupport
15+
import XCTest
16+
17+
final class PluginsBuildPlanTests: XCTestCase {
18+
func testBuildToolsDatabasePath() throws {
19+
try fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in
20+
let (stdout, stderr) = try executeSwiftBuild(fixturePath)
21+
XCTAssertMatch(stdout, .contains("Build complete!"))
22+
XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugins/tools/build.db"))))
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)