Skip to content

Commit 85fafec

Browse files
committed
Ensure module output directories are explicitly created by the build system
The driver may store temporary response files in these directories, so we should create them eagerly rdar://157302464
1 parent 8196398 commit 85fafec

File tree

9 files changed

+43
-13
lines changed

9 files changed

+43
-13
lines changed

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ public final class BuiltinMacros {
506506
public static let CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_EXPLICIT_MODULES_WITH_COMPILER_LAUNCHER")
507507
public static let CLANG_EXPLICIT_MODULES_LIBCLANG_PATH = BuiltinMacros.declareStringMacro("CLANG_EXPLICIT_MODULES_LIBCLANG_PATH")
508508
public static let CLANG_EXPLICIT_MODULES_IGNORE_LIBCLANG_VERSION_MISMATCH = BuiltinMacros.declareBooleanMacro("CLANG_EXPLICIT_MODULES_IGNORE_LIBCLANG_VERSION_MISMATCH")
509-
public static let CLANG_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declareStringMacro("CLANG_EXPLICIT_MODULES_OUTPUT_PATH")
510-
public static let SWIFT_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declareStringMacro("SWIFT_EXPLICIT_MODULES_OUTPUT_PATH")
509+
public static let CLANG_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("CLANG_EXPLICIT_MODULES_OUTPUT_PATH")
510+
public static let SWIFT_EXPLICIT_MODULES_OUTPUT_PATH = BuiltinMacros.declarePathMacro("SWIFT_EXPLICIT_MODULES_OUTPUT_PATH")
511511
public static let CLANG_ENABLE_COMPILE_CACHE = BuiltinMacros.declareBooleanMacro("CLANG_ENABLE_COMPILE_CACHE")
512512
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS") as EnumMacroDeclaration<FineGrainedCachingSetting>
513513
public static let CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION = BuiltinMacros.declareEnumMacro("CLANG_CACHE_FINE_GRAINED_OUTPUTS_VERIFICATION") as EnumMacroDeclaration<FineGrainedCachingVerificationSetting>

Sources/SWBCore/SpecImplementations/Tools/CCompiler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ public class ClangCompilerSpec : CompilerSpec, SpecIdentifierType, GCCCompatible
977977
usesCompilerLauncher: usesCompilerLauncher,
978978
// This path is scoped to the project, so ideally different targets that use the same modules would
979979
// share precompiled modules.
980-
outputPath: Path(cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH)),
980+
outputPath: cbc.scope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH),
981981
scanningOutputPath: scanningOutputPath,
982982
casOptions: casOptions,
983983
cacheFallbackIfNotAvailable: cbc.scope.evaluate(BuiltinMacros.CLANG_CACHE_FALLBACK_IF_UNAVAILABLE),

Sources/SWBCore/SpecImplementations/Tools/SwiftCompiler.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,7 +1809,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
18091809
// Instructs the driver to perform build planning with explicit module builds
18101810
if explicitModuleBuildEnabled {
18111811
args.append("-explicit-module-build")
1812-
let explicitDependencyOutputPath = Path(cbc.scope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH))
1812+
let explicitDependencyOutputPath = cbc.scope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH)
18131813
args.append(contentsOf: ["-module-cache-path", explicitDependencyOutputPath.str])
18141814
let moduleCacheDir = cbc.scope.evaluate(BuiltinMacros.MODULE_CACHE_DIR)
18151815
if LibSwiftDriver.supportsDriverFlag(spelled: "-clang-scanner-module-cache-path"),
@@ -2296,7 +2296,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
22962296
previewPayload: previewPayload,
22972297
localizationPayload: localizationPayload,
22982298
numExpectedCompileSubtasks: isUsingWholeModuleOptimization ? 1 : cbc.inputs.count,
2299-
driverPayload: await driverPayload(uniqueID: String(args.hashValue), scope: cbc.scope, delegate: delegate, compilationMode: compilationMode, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization, args: args, tempDirPath: objectFileDir, explicitModulesTempDirPath: Path(cbc.scope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH)), variant: variant, arch: arch + compilationMode.moduleBaseNameSuffix, commandLine: ["builtin-SwiftDriver", "--"] + args, ruleInfo: ruleInfo(compilationMode.ruleNameIntegratedDriver, targetName), casOptions: casOptions, linkerResponseFilePath: moduleLinkerArgsPath), previewStyle: cbc.scope.previewStyle
2299+
driverPayload: await driverPayload(uniqueID: String(args.hashValue), scope: cbc.scope, delegate: delegate, compilationMode: compilationMode, isUsingWholeModuleOptimization: isUsingWholeModuleOptimization, args: args, tempDirPath: objectFileDir, explicitModulesTempDirPath: cbc.scope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH), variant: variant, arch: arch + compilationMode.moduleBaseNameSuffix, commandLine: ["builtin-SwiftDriver", "--"] + args, ruleInfo: ruleInfo(compilationMode.ruleNameIntegratedDriver, targetName), casOptions: casOptions, linkerResponseFilePath: moduleLinkerArgsPath), previewStyle: cbc.scope.previewStyle
23002300
)
23012301

23022302
// Finally, assemble the input and output paths and create the Swift compiler command.

Sources/SWBCore/WorkspaceContext.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public final class WorkspaceContext: Sendable {
352352
private let headerIndexCache = AsyncSingleValueCache<WorkspaceHeaderIndex, Never>()
353353

354354
public var buildDirectoryMacros: [PathMacroDeclaration] {
355-
return [BuiltinMacros.DSTROOT, BuiltinMacros.OBJROOT, BuiltinMacros.SYMROOT, BuiltinMacros.BUILT_PRODUCTS_DIR, BuiltinMacros.EAGER_LINKING_INTERMEDIATE_TBD_DIR]
355+
return [BuiltinMacros.DSTROOT, BuiltinMacros.OBJROOT, BuiltinMacros.SYMROOT, BuiltinMacros.BUILT_PRODUCTS_DIR, BuiltinMacros.EAGER_LINKING_INTERMEDIATE_TBD_DIR, BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH, BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH]
356356
}
357357

358358
/// The path to the module session file for the workspace given a set of build parameters.

Sources/SWBTaskExecution/BuildDescriptionManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ package final class BuildDescriptionManager: Sendable {
198198

199199
moduleCachePathsPerTarget[target] = [
200200
settings.globalScope.evaluate(BuiltinMacros.MODULE_CACHE_DIR),
201-
Path(settings.globalScope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH)),
202-
Path(settings.globalScope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH)),
201+
settings.globalScope.evaluate(BuiltinMacros.SWIFT_EXPLICIT_MODULES_OUTPUT_PATH),
202+
settings.globalScope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH),
203203
]
204204

205205
if shouldValidateCAS, settings.globalScope.evaluate(BuiltinMacros.CLANG_ENABLE_COMPILE_CACHE) || settings.globalScope.evaluate(BuiltinMacros.SWIFT_ENABLE_COMPILE_CACHE) {

Tests/SWBBuildSystemTests/CleanOperationTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fileprivate struct CleanOperationTests: CoreBasedTests {
106106
@Test(.requireSDKs(.macOS))
107107
func cleanFramework() async throws {
108108
try await withTestHarness { tester, tmpDirPath, _ in
109-
let buildFolderPaths = [ tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug")]
109+
let buildFolderPaths = [ tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug"), tmpDirPath.join("Test/aProject/build/ExplicitPrecompiledModules"), tmpDirPath.join("Test/aProject/build/SwiftExplicitPrecompiledModules")]
110110

111111
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
112112
// Check if build folder tasks have run as expected.
@@ -136,7 +136,7 @@ fileprivate struct CleanOperationTests: CoreBasedTests {
136136
@Test(.requireSDKs(.macOS))
137137
func cleanFrameworkInstall() async throws {
138138
try await withTestHarness(install: true) { tester, tmpDirPath, dstRoot in
139-
let buildFolderPaths = [ dstRoot, tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug")]
139+
let buildFolderPaths = [ dstRoot, tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug"), tmpDirPath.join("Test/aProject/build/ExplicitPrecompiledModules"), tmpDirPath.join("Test/aProject/build/SwiftExplicitPrecompiledModules")]
140140

141141
try await tester.checkBuild(runDestination: .macOS, persistent: true) { results in
142142
// Check if build folder tasks have run as expected.
@@ -212,7 +212,7 @@ fileprivate struct CleanOperationTests: CoreBasedTests {
212212
let buildRequest = BuildRequest(parameters: parameters, buildTargets: buildTargets, continueBuildingAfterErrors: true, useParallelTargets: true, useImplicitDependencies: false, useDryRun: false)
213213
try await tester.checkBuild(runDestination: .macOS, buildRequest: buildRequest, persistent: true) { results in
214214
results.checkTasks(.matchRuleType("CreateBuildDirectory")) { tasks in
215-
#expect(tasks.count == 6)
215+
#expect(tasks.count == 10)
216216
}
217217

218218
results.checkNoTask(.matchRuleType("CreateBuildDirectory"))
@@ -234,7 +234,7 @@ fileprivate struct CleanOperationTests: CoreBasedTests {
234234
@Test(.requireSDKs(.macOS))
235235
func cleanDoesNotDeleteManuallyCreatedFolders() async throws {
236236
try await withTestHarness { tester, tmpDirPath, _ in
237-
let buildFolderPaths = [ tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug")]
237+
let buildFolderPaths = [ tmpDirPath.join("Test/aProject/build"), tmpDirPath.join("Test/aProject/build/Debug"), tmpDirPath.join("Test/aProject/build/EagerLinkingTBDs/Debug"), tmpDirPath.join("Test/aProject/build/ExplicitPrecompiledModules"), tmpDirPath.join("Test/aProject/build/SwiftExplicitPrecompiledModules")]
238238

239239
for folder in buildFolderPaths {
240240
try tester.fs.createDirectory(folder, recursive: true)

Tests/SWBBuildSystemTests/PackageBuildOperationTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,11 +592,15 @@ fileprivate struct PackageBuildOperationTests: CoreBasedTests {
592592
packageBuildDirectory.join(configurationToBuild).str,
593593
packageBuildDirectory.join(configurationToBuild).join("PackageFrameworks").str,
594594
packageBuildDirectory.join("EagerLinkingTBDs").join(configurationToBuild).str,
595+
packageBuildDirectory.join("ExplicitPrecompiledModules").str,
596+
packageBuildDirectory.join("SwiftExplicitPrecompiledModules").str,
595597

596598
projectBuildDirectory.str,
597599
projectBuildDirectory.join(configurationToBuild).str,
598600
projectBuildDirectory.join(configurationToBuild).join("PackageFrameworks").str,
599601
projectBuildDirectory.join("EagerLinkingTBDs").join(configurationToBuild).str,
602+
projectBuildDirectory.join("ExplicitPrecompiledModules").str,
603+
projectBuildDirectory.join("SwiftExplicitPrecompiledModules").str,
600604
].sorted()
601605

602606
let tester = try await testerForBasicPackageProject(tmpDirPath: tmpDirPath, configurationToBuild: configurationToBuild)

Tests/SWBCoreTests/SettingsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ import SWBMacro
396396
if let project = settings.project {
397397
#expect(settings.globalScope.evaluate(BuiltinMacros.OBJROOT) == Path("\(project.sourceRoot.str)/build"))
398398
#expect(settings.globalScope.evaluate(BuiltinMacros.CONFIGURATION_BUILD_DIR) == Path("\(project.sourceRoot.str)/build/Config1"))
399-
#expect(settings.globalScope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH) == "\(project.sourceRoot.str)/build/ExplicitPrecompiledModules")
399+
#expect(settings.globalScope.evaluate(BuiltinMacros.CLANG_EXPLICIT_MODULES_OUTPUT_PATH).str == "\(project.sourceRoot.str)/build/ExplicitPrecompiledModules")
400400
}
401401

402402
// check that we get the right value for VERSION_INFO_STRING, which validates we parsed it correctly.

Tests/SWBTaskConstructionTests/TaskConstructionTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,8 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
21362136
.namePattern(.prefix("CreateBuildDirectory-/tmp/Test/aProject/build")),
21372137
.namePattern(.prefix("CreateBuildDirectory-/tmp/Test/aProject/build/Release\(runDestination.builtProductsDirSuffix)/BuiltProducts")),
21382138
.namePattern(.prefix("CreateBuildDirectory-/tmp/Test/aProject/build/EagerLinkingTBDs")),
2139+
.namePattern(.prefix("CreateBuildDirectory-/tmp/Test/aProject/build/SwiftExplicitPrecompiledModules")),
2140+
.namePattern(.prefix("CreateBuildDirectory-/tmp/Test/aProject/build/ExplicitPrecompiledModules")),
21392141
.namePattern(.and(.prefix("target"), .suffix("-begin-compiling"))),
21402142
])
21412143
} else {
@@ -8260,6 +8262,30 @@ fileprivate struct TaskConstructionTests: CoreBasedTests {
82608262
task.checkInputs([.path("\(tmpDir.str)/build/a/b/c/d")])
82618263
}
82628264

8265+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/b/c/d/ExplicitPrecompiledModules")) { task in
8266+
task.checkInputs([.path("\(tmpDir.str)/build/a/b/c/d")])
8267+
}
8268+
8269+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/b/c/d/SwiftExplicitPrecompiledModules")) { task in
8270+
task.checkInputs([.path("\(tmpDir.str)/build/a/b/c/d")])
8271+
}
8272+
8273+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/b/ExplicitPrecompiledModules")) { task in
8274+
task.checkInputs([.path("\(tmpDir.str)/build/a/b")])
8275+
}
8276+
8277+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/b/SwiftExplicitPrecompiledModules")) { task in
8278+
task.checkInputs([.path("\(tmpDir.str)/build/a/b")])
8279+
}
8280+
8281+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/ExplicitPrecompiledModules")) { task in
8282+
task.checkInputs([.path("\(tmpDir.str)/build/a")])
8283+
}
8284+
8285+
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/SwiftExplicitPrecompiledModules")) { task in
8286+
task.checkInputs([.path("\(tmpDir.str)/build/a")])
8287+
}
8288+
82638289
results.checkTask(.matchRuleType("CreateBuildDirectory"), .matchRuleItem("\(tmpDir.str)/build/a/b/c/d")) { task in
82648290
task.checkInputs([.path("\(tmpDir.str)/build/a/b")])
82658291
}

0 commit comments

Comments
 (0)