Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct BazelTargetGraphReport: Codable, Equatable {
let platform: String
let minimumOsVersion: String
let cpuArch: String
let sdkName: String
}

let topLevelTargets: [TopLevelTarget]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ import Foundation
struct BazelTargetPlatformInfo {
let label: String
let topLevelParentLabel: String
let topLevelParentRuleType: TopLevelRuleType
let topLevelParentConfig: BazelTargetConfigurationInfo

var platformSdkName: String {
topLevelParentRuleType.sdkName
}
}

// Information about a target's Bazel configuration, used to determine
Expand All @@ -48,4 +43,5 @@ struct BazelTargetConfigurationInfo: Hashable {
let minimumOsVersion: String
let platform: String
let cpuArch: String
let sdkName: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ final class BazelTargetQuerier {

/// Runs an aquery across the codebase over a list of specific target dependencies.
func aquery(
topLevelTargets: [(String, TopLevelRuleType)],
topLevelTargets: [(String, TopLevelRuleType, UInt32)],
config: InitializedServerConfig,
mnemonics: [String]
) throws -> ProcessedAqueryResult {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ protocol BazelTargetStore: AnyObject {
enum BazelTargetStoreError: Error, LocalizedError {
case unknownBSPURI(URI)
case unableToMapBazelLabelToParents(String)
case unableToMapBazelLabelToTopLevelRuleType(String)
case unableToMapBazelLabelToTopLevelConfig(String)
case unableToMapBazelLabelToParentConfig(String)
case unableToMapConfigToTopLevelLabels(UInt32)
case unableToMapConfigIdToTopLevelConfig(UInt32)
case unableToMapBSPURIToParentConfig(URI)
case unableToMapConfigIdToTopLevelLabels(UInt32)
case unableToMapTopLevelLabelToConfig(String)
case noCachedAquery

var errorDescription: String? {
Expand All @@ -55,14 +55,14 @@ enum BazelTargetStoreError: Error, LocalizedError {
return "Unable to map '\(uri)' to a Bazel target label"
case .unableToMapBazelLabelToParents(let label):
return "Unable to map '\(label)' to its parents"
case .unableToMapBazelLabelToTopLevelRuleType(let label):
return "Unable to map '\(label)' to its top-level rule type"
case .unableToMapBazelLabelToTopLevelConfig(let label):
return "Unable to map '\(label)' to its top-level configuration"
case .unableToMapBazelLabelToParentConfig(let label):
return "Unable to map '\(label)' to its parent configuration"
case .unableToMapConfigToTopLevelLabels(let config):
return "Unable to map configuration '\(config)' to its top-level labels"
case .unableToMapConfigIdToTopLevelConfig(let config):
return "Unable to map configId '\(config)' to its top-level configuration"
case .unableToMapBSPURIToParentConfig(let uri):
return "Unable to map '\(uri)' to its parent configuration"
case .unableToMapConfigIdToTopLevelLabels(let config):
return "Unable to map configId '\(config)' to its top-level labels"
case .unableToMapTopLevelLabelToConfig(let label):
return "Unable to map top-level label '\(label)' to its configuration"
case .noCachedAquery:
return "No cached aquery result found in the store."
}
Expand Down Expand Up @@ -132,34 +132,26 @@ final class BazelTargetStoreImpl: BazelTargetStore, @unchecked Sendable {
return bspURIs
}

/// Retrieves the top-level rule type for a given Bazel **top-level** target label.
func topLevelRuleType(forBazelLabel label: String) throws -> TopLevelRuleType {
guard let ruleType = cqueryResult?.topLevelLabelToRuleMap[label] else {
throw BazelTargetStoreError.unableToMapBazelLabelToTopLevelRuleType(label)
}
return ruleType
}

/// Retrieves the configuration information for a given Bazel **top-level** target label.
func topLevelConfigInfo(forBazelLabel label: String) throws -> BazelTargetConfigurationInfo {
guard let config = aqueryResult?.topLevelLabelToConfigMap[label] else {
throw BazelTargetStoreError.unableToMapBazelLabelToTopLevelConfig(label)
func topLevelConfigInfo(forConfig configId: UInt32) throws -> BazelTargetConfigurationInfo {
guard let config = aqueryResult?.topLevelConfigIdToInfoMap[configId] else {
throw BazelTargetStoreError.unableToMapConfigIdToTopLevelConfig(configId)
}
return config
}

/// Retrieves the configuration for a given Bazel target label.
func parentConfig(forBazelLabel label: String) throws -> UInt32 {
guard let config = cqueryResult?.bazelLabelToParentConfigMap[label] else {
throw BazelTargetStoreError.unableToMapBazelLabelToParentConfig(label)
/// Retrieves the available configurations for a given Bazel target label.
func parentConfig(forBSPURI uri: URI) throws -> UInt32 {
guard let config = cqueryResult?.bspUriToParentConfigMap[uri] else {
throw BazelTargetStoreError.unableToMapBSPURIToParentConfig(uri)
}
return config
}

/// Retrieves the list of top-level labels for a given configuration.
func topLevelLabels(forConfig config: UInt32) throws -> [String] {
guard let labels = cqueryResult?.configurationToTopLevelLabelsMap[config] else {
throw BazelTargetStoreError.unableToMapConfigToTopLevelLabels(config)
throw BazelTargetStoreError.unableToMapConfigIdToTopLevelLabels(config)
}
return labels
}
Expand All @@ -168,19 +160,14 @@ final class BazelTargetStoreImpl: BazelTargetStore, @unchecked Sendable {
/// This is used to determine the correct set of compiler flags for the target / platform combo.
func platformBuildLabelInfo(forBSPURI uri: URI) throws -> BazelTargetPlatformInfo {
let bazelLabel = try bazelTargetLabel(forBSPURI: uri)
let configId = try parentConfig(forBazelLabel: bazelLabel)
let configId = try parentConfig(forBSPURI: uri)
let config = try topLevelConfigInfo(forConfig: configId)
let parents = try topLevelLabels(forConfig: configId)
// FIXME: When a target can compile to multiple platforms, the way Xcode handles it is by selecting
// the one matching your selected simulator in the IDE. We don't have any sort of special IDE integration
// at the moment, so for now we just select the first parent.
// We are also not processing the different variants at all (see FIXME in BazelTargetQuerierParser.swift).
// Since the config of these parents are all the same, it doesn't matter which one we pick here.
let parentToUse = parents[0]
let rule = try topLevelRuleType(forBazelLabel: parentToUse)
let config = try topLevelConfigInfo(forBazelLabel: parentToUse)
return BazelTargetPlatformInfo(
label: bazelLabel,
topLevelParentLabel: parentToUse,
topLevelParentRuleType: rule,
topLevelParentConfig: config
)
}
Expand Down Expand Up @@ -271,9 +258,8 @@ extension BazelTargetStoreImpl {
var reportTopLevel: [BazelTargetGraphReport.TopLevelTarget] = []
var reportConfigurations: [UInt32: BazelTargetGraphReport.Configuration] = [:]
let topLevelTargets = cqueryResult?.topLevelTargets ?? []
for (label, ruleType) in topLevelTargets {
let topLevelConfig = try topLevelConfigInfo(forBazelLabel: label)
let configId = try parentConfig(forBazelLabel: label)
for (label, ruleType, configId) in topLevelTargets {
let topLevelConfig = try topLevelConfigInfo(forConfig: configId)
reportTopLevel.append(
.init(
label: label,
Expand All @@ -286,15 +272,16 @@ extension BazelTargetStoreImpl {
id: configId,
platform: topLevelConfig.platform,
minimumOsVersion: topLevelConfig.minimumOsVersion,
cpuArch: topLevelConfig.cpuArch
cpuArch: topLevelConfig.cpuArch,
sdkName: topLevelConfig.sdkName
)
)
}
var reportDependencies: [BazelTargetGraphReport.DependencyTarget] = []
let dependencyTargets = cqueryResult?.buildTargets ?? []
for target in dependencyTargets {
guard let label = target.displayName else { continue }
let configId = try parentConfig(forBazelLabel: label)
let configId = try parentConfig(forBSPURI: target.id.uri)
reportDependencies.append(.init(label: label, configId: configId))
}
return BazelTargetGraphReport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ struct ProcessedAqueryResult: Hashable {
let targets: [String: Analysis_Target]
let actions: [UInt32: [Analysis_Action]]
let configurations: [UInt32: Analysis_Configuration]
let topLevelLabelToConfigMap: [String: BazelTargetConfigurationInfo]
let topLevelConfigIdToInfoMap: [UInt32: BazelTargetConfigurationInfo]
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ private let logger = makeFileLevelBSPLogger()

struct ProcessedCqueryResult {
let buildTargets: [BuildTarget]
let topLevelTargets: [(String, TopLevelRuleType)]
let topLevelTargets: [(String, TopLevelRuleType, UInt32)]
let bspURIsToBazelLabelsMap: [URI: String]
let bspURIsToSrcsMap: [URI: SourcesItem]
let srcToBspURIsMap: [URI: [URI]]
let topLevelLabelToRuleMap: [String: TopLevelRuleType]
let configurationToTopLevelLabelsMap: [UInt32: [String]]
let bazelLabelToParentConfigMap: [String: UInt32]
let bspUriToParentConfigMap: [URI: UInt32]
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,38 +99,4 @@ public enum TopLevelRuleType: String, CaseIterable, ExpressibleByArgument, Senda
default: return false
}
}

// FIXME: Not the best way to handle this as we need to eventually
// handle device builds as well
var sdkName: String {
switch self {
case .iosApplication: return "iphonesimulator"
case .iosAppClip: return "iphonesimulator"
case .iosExtension: return "iphonesimulator"
case .iosUnitTest: return "iphonesimulator"
case .iosUiTest: return "iphonesimulator"
case .iosBuildTest: return "iphonesimulator"
case .watchosApplication: return "watchsimulator"
case .watchosExtension: return "watchsimulator"
case .watchosUnitTest: return "watchsimulator"
case .watchosUiTest: return "watchsimulator"
case .watchosBuildTest: return "watchsimulator"
case .macosApplication: return "macosx"
case .macosExtension: return "macosx"
case .macosCommandLineApplication: return "macosx"
case .macosUnitTest: return "macosx"
case .macosUiTest: return "macosx"
case .macosBuildTest: return "macosx"
case .tvosApplication: return "appletvsimulator"
case .tvosExtension: return "appletvsimulator"
case .tvosUnitTest: return "appletvsimulator"
case .tvosUiTest: return "appletvsimulator"
case .tvosBuildTest: return "appletvsimulator"
case .visionosApplication: return "xrsimulator"
case .visionosExtension: return "xrsimulator"
case .visionosUnitTest: return "xrsimulator"
case .visionosUiTest: return "xrsimulator"
case .visionosBuildTest: return "xrsimulator"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,17 @@ final class InitializeHandler {
}

func getSDKRootPaths(with commandRunner: CommandRunner) -> [String: String] {
let supportedSDKTypes = Set(baseConfig.topLevelRulesToDiscover.map { $0.sdkName }).sorted()
let supportedSDKTypes = [
"appletvsimulator",
"appletvos",
"iphonesimulator",
"iphoneos",
"macosx",
"watchsimulator",
"watchos",
"xrsimulator",
"xros",
]
let sdkRootPaths: [String: String] = supportedSDKTypes.reduce(into: [:]) { result, sdkType in
// This will fail if the user doesn't have the SDK installed, which is fine.
guard let sdkRootPath: String? = try? commandRunner.run("xcrun --sdk \(sdkType) --show-sdk-path") else {
Expand Down
10 changes: 5 additions & 5 deletions Sources/SourceKitBazelBSP/RequestHandlers/PrepareHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class PrepareHandler {
) {
let targetsToBuild = request.targets
guard !targetsToBuild.isEmpty else {
logger.info("No targets to build.")
logger.debug("No targets to build.")
reply(.success(VoidResponse()))
return
}
Expand Down Expand Up @@ -143,9 +143,9 @@ final class PrepareHandler {
completion: @escaping ((ResponseError?) -> Void)
) throws {
if labelsToBuild.count == 1 {
logger.info("Will build \(labelsToBuild[0].joined(separator: ", "), privacy: .public)")
logger.debug("Will build \(labelsToBuild[0].joined(separator: ", "), privacy: .public)")
} else {
logger.info(
logger.debug(
"Will build \(labelsToBuild.flatMap { $0 }.joined(separator: ", "), privacy: .public) over \(labelsToBuild.count, privacy: .public) invocations"
)
}
Expand Down Expand Up @@ -175,11 +175,11 @@ final class PrepareHandler {
)
process.setTerminationHandler { code, stderr in
if code == 0 {
logger.info("Finished building! (Request ID: \(id.description, privacy: .public))")
logger.debug("Finished building! (Request ID: \(id.description, privacy: .public))")
completion(nil)
} else {
if code == 8 {
logger.info("Build (Request ID: \(id.description, privacy: .public)) was cancelled.")
logger.debug("Build (Request ID: \(id.description, privacy: .public)) was cancelled.")
completion(ResponseError.cancelled)
} else {
logger.logFullObjectInMultipleLogMessages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ final class BazelTargetCompilerArgsExtractor {
return []
}

logger.info(
logger.debug(
"Fetching SKOptions for \(platformInfo.label), strategy: \(strategy)",
)

Expand All @@ -137,14 +137,14 @@ final class BazelTargetCompilerArgsExtractor {
strategy: strategy
)

logger.info("Fetching compiler args for \(cacheKey, privacy: .public)")
logger.debug("Fetching compiler args for \(cacheKey, privacy: .public)")
if let cached = argsCache[cacheKey] {
logger.debug("Returning cached results")
return cached
}

// First, determine the SDK root based on the platform the target is built for.
let platformSdk = platformInfo.platformSdkName
let platformSdk = platformInfo.topLevelParentConfig.sdkName
guard let sdkRoot: String = config.sdkRootPaths[platformSdk] else {
throw BazelTargetCompilerArgsExtractorError.sdkRootNotFound(platformSdk)
}
Expand All @@ -165,7 +165,7 @@ final class BazelTargetCompilerArgsExtractor {
effectiveConfigName: platformInfo.topLevelParentConfig.effectiveConfigurationName
)

logger.info("Finished processing compiler arguments")
logger.debug("Finished processing compiler arguments")
logger.logFullObjectInMultipleLogMessages(
level: .debug,
header: "Parsed compiler arguments",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ final class TargetSourcesHandler {
_: RequestID
) throws -> BuildTargetSourcesResponse {
let targets = request.targets
logger.info("Fetching sources for \(targets.count, privacy: .public) targets")
logger.debug("Fetching sources for \(targets.count, privacy: .public) targets")

let srcs: [SourcesItem] = try targetStore.stateLock.withLockUnchecked {
try targets.map { try targetStore.bazelTargetSrcs(forBSPURI: $0.uri) }
}

logger.info(
logger.debug(
"Returning \(srcs.count, privacy: .public) source specs"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ final class WatchedFileChangeHandler {
}

guard !changes.isEmpty else {
logger.info("No (supported) file changes to process.")
logger.debug("No (supported) file changes to process.")
return
}

Expand All @@ -75,11 +75,11 @@ final class WatchedFileChangeHandler {

// If we received this notification before the build graph was calculated, we should stop.
guard targetStore.isInitialized else {
logger.info("Received file changes before the build graph was calculated. Ignoring.")
logger.debug("Received file changes before the build graph was calculated. Ignoring.")
return []
}

logger.info("Received \(changes.count, privacy: .public) file changes")
logger.debug("Received \(changes.count, privacy: .public) file changes")

let deletedFiles = changes.filter { $0.type == .deleted }
let createdFiles = changes.filter { $0.type == .created }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ final class BSPMessageHandler: MessageHandler {
}

func handle<Notification: NotificationType>(_ notification: Notification) {
logger.info("Received notification: \(Notification.method, privacy: .public)")
logger.debug("Received notification: \(Notification.method, privacy: .public)")
do {
let handler = try getHandler(for: notification, state: state)
try handler(notification)
Expand All @@ -74,13 +74,13 @@ final class BSPMessageHandler: MessageHandler {
id: RequestID,
reply: @escaping (LSPResult<Request.Response>) -> Void
) {
logger.info("Received request: \(Request.method, privacy: .public)")
logger.debug("Received request: \(Request.method, privacy: .public)")
do {
let handler = try getHandler(for: request, id, reply, state: state)
handler(request, id) { [buildLSPError] result in
do {
let response = try result.get()
logger.info("Replying to \(Request.method, privacy: .public)")
logger.debug("Replying to \(Request.method, privacy: .public)")
reply(.success(response))
} catch {
logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct ShellCommandRunner: CommandRunner {

runningProcess.attachPipes()

logger.info("Running shell: \(cmd, privacy: .public)")
logger.debug("Running shell: \(cmd, privacy: .public)")
try process.run()

return runningProcess
Expand Down
Loading