Skip to content
Open
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
10 changes: 6 additions & 4 deletions Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ final class PrepareHandler {
"--remote_download_regex='.*\\.indexstore/.*|.*\\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$'"
]

// Allow prepare requests to be overridden if needed.
static let additionalStartupFlags: [String] = [
"--preemptible"
]

// The current Bazel build is always stored so that we can cancel it if requested by the LSP.
private var currentTaskLock = OSAllocatedUnfairLock<(RunningProcess, RequestID)?>(initialState: nil)

Expand Down Expand Up @@ -111,16 +116,13 @@ final class PrepareHandler {

nonisolated(unsafe) let completion = completion
try currentTaskLock.withLock { [commandRunner, initializedConfig] currentTask in
// Build the provided targets, on our special output base and taking into account special index flags.
// If using only one output base, add --preemptible to allow the task to be overridden if needed.
let preemptible = initializedConfig.baseConfig.useSeparateOutputBaseForAquery == false
let process = try commandRunner.bazelIndexAction(
baseConfig: initializedConfig.baseConfig,
outputBase: initializedConfig.outputBase,
cmd: "build \(labelsToBuild.joined(separator: " "))",
rootUri: initializedConfig.rootUri,
additionalFlags: Self.additionalBuildFlags,
additionalStartupFlags: preemptible ? ["--preemptible"] : []
additionalStartupFlags: Self.additionalStartupFlags
)
process.setTerminationHandler { code, stderr in
if code == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ final class BazelTargetAquerier {
// Run the aquery with the special index flags since that's what we will build with.
let output: Data = try commandRunner.bazelIndexAction(
baseConfig: config.baseConfig,
outputBase: config.aqueryOutputBase,
outputBase: config.outputBase,
cmd: cmd,
rootUri: config.rootUri
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,29 +295,8 @@ extension BazelTargetCompilerArgsExtractor {
) -> [String] {
let devDir = config.devDir
let rootUri = config.rootUri

// We ran the aquery on the aquery output base, but we need this
// to reflect the data of the real build output base.
let outputPath: String = {
let base: String = config.outputPath
guard config.aqueryOutputBase != config.outputBase else {
return base
}
return base.replacingOccurrences(
of: config.aqueryOutputBase,
with: config.outputBase
)
}()
let outputBase = {
let base: String = config.outputBase
guard config.aqueryOutputBase != config.outputBase else {
return base
}
return base.replacingOccurrences(
of: config.aqueryOutputBase,
with: config.outputBase
)
}()
let outputPath = config.outputPath
let outputBase = config.outputBase

var compilerArguments: [String] = []

Expand Down
3 changes: 0 additions & 3 deletions Sources/SourceKitBazelBSP/Server/BaseServerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ package struct BaseServerConfig: Equatable {
let buildTestSuffix: String
let buildTestPlatformPlaceholder: String
let filesToWatch: String?
let useSeparateOutputBaseForAquery: Bool
let indexBuildBatchSize: Int?

package init(
Expand All @@ -41,15 +40,13 @@ package struct BaseServerConfig: Equatable {
buildTestSuffix: String,
buildTestPlatformPlaceholder: String,
filesToWatch: String?,
useSeparateOutputBaseForAquery: Bool = false,
indexBuildBatchSize: Int? = nil
) {
self.bazelWrapper = bazelWrapper
self.indexFlags = indexFlags
self.buildTestSuffix = buildTestSuffix
self.buildTestPlatformPlaceholder = buildTestPlatformPlaceholder
self.filesToWatch = filesToWatch
self.useSeparateOutputBaseForAquery = useSeparateOutputBaseForAquery
self.indexBuildBatchSize = indexBuildBatchSize

// We need to post-process the target list provided by the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,4 @@ struct InitializedServerConfig: Equatable {
var indexStorePath: String {
outputPath + "/_global_index_store"
}

// We currently use a third output base for aquerying
// to prevent extracting compiler args from being blocked by index builds.
var aqueryOutputBase: String {
guard baseConfig.useSeparateOutputBaseForAquery else {
return outputBase
}
return outputBase + "-aq"
}
}
8 changes: 0 additions & 8 deletions Sources/sourcekit-bazel-bsp/Commands/Serve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ struct Serve: ParsableCommand {
)
var buildTestPlatformPlaceholder: String = Self.defaultBuildTestPlatformPlaceholder

// FIXME: This should be enabled by default, but I ran into some weird race condition issues with rules_swift I'm not sure about.
@Flag(
help:
"Whether to use a separate output base for compiler arguments requests. This greatly increases the performance of the server at the cost of more disk usage."
)
var separateAqueryOutput: Bool = false

@Option(help: "Comma separated list of file globs to watch for changes.")
var filesToWatch: String?

Expand Down Expand Up @@ -117,7 +110,6 @@ struct Serve: ParsableCommand {
buildTestSuffix: buildTestSuffix,
buildTestPlatformPlaceholder: buildTestPlatformPlaceholder,
filesToWatch: filesToWatch,
useSeparateOutputBaseForAquery: separateAqueryOutput,
indexBuildBatchSize: indexBuildBatchSize
)
let server = SourceKitBazelBSPServer(baseConfig: config)
Expand Down
52 changes: 0 additions & 52 deletions Tests/SourceKitBazelBSPTests/PrepareHandlerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,56 +126,4 @@ struct PrepareHandlerTests {
#expect(ranCommands[0].command == expectedCommand)
#expect(ranCommands[0].cwd == "/path/to/project")
}

@Test
func skipsPreemptibleFlagIfUsingSeparateOutputBaseForAquery() throws {
let commandRunner = CommandRunnerFake()
let connection = LSPConnectionFake()

let rootUri = "/path/to/project"
let baseConfig = BaseServerConfig(
bazelWrapper: "bazel",
targets: ["//HelloWorld"],
indexFlags: ["--config=index"],
buildTestSuffix: "_(PLAT)_skbsp",
buildTestPlatformPlaceholder: "(PLAT)",
filesToWatch: nil,
useSeparateOutputBaseForAquery: true
)

let initializedConfig = InitializedServerConfig(
baseConfig: baseConfig,
rootUri: rootUri,
outputBase: "/tmp/output_base",
outputPath: "/tmp/output_path",
devDir: "/Applications/Xcode.app/Contents/Developer",
devToolchainPath: "/a/b/XcodeDefault.xctoolchain/",
executionRoot: "/tmp/output_path/execoot/_main",
sdkRootPaths: ["iphonesimulator": "bar"]
)

let expectedCommand =
"bazel --output_base=/tmp/output_base build //HelloWorld:HelloWorld --remote_download_regex=\'.*\\.indexstore/.*|.*\\.(a|cfg|c|C|cc|cl|cpp|cu|cxx|c++|def|h|H|hh|hpp|hxx|h++|hmap|ilc|inc|inl|ipp|tcc|tlh|tli|tpp|m|modulemap|mm|pch|swift|swiftdoc|swiftmodule|swiftsourceinfo|yaml)$\' --config=index"
commandRunner.setResponse(for: expectedCommand, cwd: rootUri, response: "")

let handler = PrepareHandler(
initializedConfig: initializedConfig,
targetStore: BazelTargetStoreImpl(initializedConfig: initializedConfig),
commandRunner: commandRunner,
connection: connection
)

let semaphore = DispatchSemaphore(value: 0)
try handler.build(bazelLabels: baseConfig.targets, id: RequestID.number(1)) { error in
#expect(error == nil)
semaphore.signal()
}

#expect(semaphore.wait(timeout: .now() + 1) == .success)

let ranCommands = commandRunner.commands
#expect(ranCommands.count == 1)
#expect(ranCommands[0].command == expectedCommand)
#expect(ranCommands[0].cwd == rootUri)
}
}
6 changes: 0 additions & 6 deletions rules/setup_sourcekit_bsp.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ def _setup_sourcekit_bsp_impl(ctx):
bsp_config_argv.append(ctx.attr.build_test_suffix)
bsp_config_argv.append("--build-test-platform-placeholder")
bsp_config_argv.append(ctx.attr.build_test_platform_placeholder)
if ctx.attr.separate_aquery_output:
bsp_config_argv.append("--separate-aquery-output")
if ctx.attr.index_build_batch_size:
bsp_config_argv.append("--index-build-batch-size")
bsp_config_argv.append(ctx.attr.index_build_batch_size)
Expand Down Expand Up @@ -108,10 +106,6 @@ setup_sourcekit_bsp = rule(
doc = "The expected platform placeholder for build_test targets.",
default = "(PLAT)",
),
"separate_aquery_output": attr.bool(
doc = "Whether to use a separate output base for compiler arguments requests. This greatly increases the performance of the server at the cost of more disk usage.",
default = False,
),
"index_build_batch_size": attr.int(
doc = "The number of targets to prepare in parallel. If not specified, SourceKit-LSP will calculate an appropriate value based on the environment. Requires using the pre-built SourceKit-LSP binary from the release archive.",
mandatory = False,
Expand Down