Skip to content

Commit

Permalink
build: have build path structure defined in BuildSystemProvider.Kind
Browse files Browse the repository at this point in the history
There are a few places that check the BuildSystemProvider.Kind is Xcode
to determine the build directory structure.  With the upcoming Swift
Build integration, which uses the "Xcode path" structure, we would need
to update all instances to check the two build system provider kinds.

Add an extension on the BuildSystemProvider.Kind that create a boolean
variable `useXcodeBuildSystemPath`, which determines whether the build
system should use the xcode path structure or not.  In addition, update
the code that requires a  "isXcodeBuildSystemEnabled" to return this
build system provider variable.

This will hopefully help address swiftlang#8272.
  • Loading branch information
bkhouri committed Feb 19, 2025
1 parent 71ab073 commit f639d68
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/CoreCommands/SwiftCommandState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public final class SwiftCommandState {
self.observabilityHandler.progress,
self.observabilityHandler.prompt
)
let isXcodeBuildSystemEnabled = self.options.build.buildSystem == .xcode
let isXcodeBuildSystemEnabled = self.options.build.buildSystem.useXcodeBuildSystemPath
let workspace = try Workspace(
fileSystem: self.fileSystem,
location: .init(
Expand All @@ -459,7 +459,7 @@ public final class SwiftCommandState {
configuration: .init(
skipDependenciesUpdates: options.resolver.skipDependencyUpdate,
prefetchBasedOnResolvedFile: options.resolver.shouldEnableResolverPrefetching,
shouldCreateMultipleTestProducts: toolWorkspaceConfiguration.wantsMultipleTestProducts || options.build.buildSystem == .xcode,
shouldCreateMultipleTestProducts: toolWorkspaceConfiguration.wantsMultipleTestProducts || options.build.buildSystem.useXcodeBuildSystemPath,
createREPLProduct: toolWorkspaceConfiguration.wantsREPLProduct,
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
sharedDependenciesCacheEnabled: self.options.caching.useDependenciesCache,
Expand Down Expand Up @@ -795,7 +795,7 @@ public final class SwiftCommandState {
workers: options.build.jobs ?? UInt32(ProcessInfo.processInfo.activeProcessorCount),
sanitizers: options.build.enabledSanitizers,
indexStoreMode: options.build.indexStoreMode.buildParameter,
isXcodeBuildSystemEnabled: options.build.buildSystem == .xcode,
isXcodeBuildSystemEnabled: options.build.buildSystem.useXcodeBuildSystemPath,
prepareForIndexing: prepareForIndexingMode,
debuggingParameters: .init(
debugInfoFormat: options.build.debugInfoFormat.buildParameter,
Expand Down
8 changes: 8 additions & 0 deletions Sources/SPMBuildCore/BuildSystem/BuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public struct BuildSystemProvider {
}
}

extension BuildSystemProvider.Kind {
public var useXcodeBuildSystemPath: Bool {
switch self {
case .native: return false
case .xcode: return true
}
}
}
private enum Errors: Swift.Error {
case buildSystemProviderNotRegistered(kind: BuildSystemProvider.Kind)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMBuildCore/Triple+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ extension Triple {
// Use "apple" as the subdirectory because in theory Xcode build system
// can be used to build for any Apple platform and it has its own
// conventions for build subpaths based on platforms.
buildSystem == .xcode ? "apple" : self.platformBuildPathComponent
buildSystem.useXcodeBuildSystemPath ? "apple" : self.platformBuildPathComponent
}
}
2 changes: 1 addition & 1 deletion Sources/swift-bootstrap/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ struct SwiftBootstrapBuildTool: AsyncParsableCommand {
triple: self.hostToolchain.targetTriple,
flags: buildFlags,
architectures: architectures,
isXcodeBuildSystemEnabled: buildSystem == .xcode,
isXcodeBuildSystemEnabled: buildSystem.useXcodeBuildSystemPath,
driverParameters: .init(
explicitTargetDependencyImportCheckingMode: explicitTargetDependencyImportCheck == .error ? .error : .none,
useIntegratedSwiftDriver: useIntegratedSwiftDriver,
Expand Down

0 comments on commit f639d68

Please sign in to comment.