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 @@ -24,9 +24,12 @@ import Foundation
struct BazelTargetGraphReport: Codable, Equatable {

struct TopLevelTarget: Codable, Equatable {
enum LaunchType: String, Codable, Equatable {
case app
case test
}
let label: String
let ruleType: String
let isTest: Bool
let launchType: LaunchType
let configId: UInt32
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ final class BazelTargetStoreImpl: BazelTargetStore, @unchecked Sendable {

reportQueue.async { [weak self] in
guard let self = self else { return }
let outputPath: String = self.initializedConfig.outputPath
let fileName = "sourcekit-bazel-bsp-graph.json"
self.writeReport(toPath: outputPath + "/" + fileName)
let graphDir = self.initializedConfig.rootUri + "/.bsp/skbsp_generated"
let graphPath = graphDir + "/graph.json"
self.writeReport(toPath: graphPath, creatingDirectoryAt: graphDir)
}

return result
Expand All @@ -248,7 +248,12 @@ final class BazelTargetStoreImpl: BazelTargetStore, @unchecked Sendable {
}

extension BazelTargetStoreImpl {
private func writeReport(toPath path: String) {
private func writeReport(toPath path: String, creatingDirectoryAt directoryPath: String) {
try? FileManager.default.createDirectory(
atPath: directoryPath,
withIntermediateDirectories: true,
attributes: nil
)
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
do {
Expand All @@ -272,8 +277,7 @@ extension BazelTargetStoreImpl {
reportTopLevel.append(
.init(
label: label,
ruleType: ruleType.rawValue,
isTest: ruleType.testBundleRule != nil,
launchType: ruleType.testBundleRule != nil ? .test : .app,
configId: configId
)
)
Expand All @@ -287,8 +291,9 @@ extension BazelTargetStoreImpl {
)
}
var reportDependencies: [BazelTargetGraphReport.DependencyTarget] = []
let dependencyTargets = cqueryResult?.buildTargets.compactMap { $0.displayName } ?? []
for label in dependencyTargets {
let dependencyTargets = cqueryResult?.buildTargets ?? []
for target in dependencyTargets {
guard let label = target.displayName else { continue }
let configId = try parentConfig(forBazelLabel: label)
reportDependencies.append(.init(label: label, configId: configId))
}
Expand Down