Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bazel support to guided setup #851

Merged
merged 1 commit into from
Dec 19, 2024
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
1 change: 1 addition & 0 deletions Sources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ swift_library(
swift_binary(
name = "Frontend",
srcs = [
"Frontend/BazelProjectSetupGuide.swift",
"Frontend/Commands/CheckUpdateCommand.swift",
"Frontend/Commands/ClearCacheCommand.swift",
"Frontend/Commands/FrontendCommand.swift",
Expand Down
32 changes: 32 additions & 0 deletions Sources/Frontend/BazelProjectSetupGuide.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation
import Logger
import ProjectDrivers
import Shared
import SystemPackage

final class BazelProjectSetupGuide: SetupGuideHelpers, SetupGuide {
static func detect() -> Self? {
guard BazelProjectDriver.isSupported else { return nil }
return Self()
}

var projectKindName: String {
"Bazel"
}

func perform() throws -> ProjectKind {
print(colorize("\nAdd the following snippet to your MODULE.bazel file:", .bold))
print(colorize("""
bazel_dep(name = "periphery", version = "\(PeripheryVersion)")
use_repo(use_extension("@periphery//bazel:generated.bzl", "generated"), "periphery_generated")
""", .lightGray))
print(colorize("\nEnter to continue when ready ", .bold), terminator: "")
_ = readLine()

return .bazel
}

var commandLineOptions: [String] {
["--bazel"]
}
}
13 changes: 11 additions & 2 deletions Sources/Frontend/GuidedSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ final class GuidedSetup: SetupGuideHelpers {
}
#endif

if let guide = BazelProjectSetupGuide.detect() {
projectGuides.append(guide)
}

var projectGuide_: SetupGuide?

if projectGuides.count > 1 {
print(colorize("Please select which project to use:", .bold))
print(colorize("Select which project to use:", .bold))
let kindName = select(single: projectGuides.map(\.projectKindName))
projectGuide_ = projectGuides.first { $0.projectKindName == kindName }
print("")
Expand Down Expand Up @@ -85,6 +89,11 @@ final class GuidedSetup: SetupGuideHelpers {
}

let parts = [bareCommand] + options
return parts.joined(separator: " \\\n ")

if options.count > 1 {
return parts.joined(separator: " \\\n ")
}

return parts.joined(separator: " ")
}
}
2 changes: 1 addition & 1 deletion Sources/Logger/Logger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum ANSIColor: String {
case magenta = "\u{001B}[0;35m"
case boldMagenta = "\u{001B}[0;1;35m"
case cyan = "\u{001B}[0;36m"
case white = "\u{001B}[0;37m"
case lightGray = "\u{001B}[0;37m"
case gray = "\u{001B}[0;1;30m"
}

Expand Down
Loading