Skip to content

Commit d318e76

Browse files
committed
Add opt-out --no-check-devices flag for skip doctor and checkup
1 parent 61e4c1f commit d318e76

2 files changed

Lines changed: 26 additions & 18 deletions

File tree

Sources/SkipBuild/Commands/CheckupCommand.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ This command performs a full system checkup to ensure that Skip can create and b
5252
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Fail immediately when an error occurs"))
5353
var failFast: Bool = true
5454

55+
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Check for connected Android devices/emulators", valueName: "check-devices"))
56+
var checkDevices: Bool = true
57+
5558
@Option(name: [.long], help: ArgumentHelp("Name of checkup project", valueName: "name"))
5659
var projectName: String = "hello-skip"
5760

@@ -99,7 +102,7 @@ This command performs a full system checkup to ensure that Skip can create and b
99102
}
100103

101104
func runCheckup(with out: MessageQueue) async throws {
102-
let hasAndroidDevices = try await runDoctor(checkNative: isNative, with: out)
105+
let hasAndroidDevices = try await runDoctor(checkNative: isNative, checkDevices: checkDevices, with: out)
103106

104107
@Sendable func buildSampleProject(packageResolvedURL: URL? = nil, launchAndroid: Bool) async throws -> (projectURL: URL, project: AppProjectLayout, artifacts: [URL: String?]) {
105108
let primary = packageResolvedURL == nil

Sources/SkipBuild/Commands/DoctorCommand.swift

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ This command will check for system configuration and prerequisites. It is a subs
3434
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Fail immediately when an error occurs"))
3535
var failFast: Bool = false
3636

37+
@Flag(inversion: .prefixedNo, help: ArgumentHelp("Check for connected Android devices/emulators", valueName: "check-devices"))
38+
var checkDevices: Bool = true
39+
3740
func performCommand(with out: MessageQueue) async {
3841
await withLogStream(with: out) {
3942
await out.yield(MessageBlock(status: nil, "Skip Doctor"))
4043

41-
_ = try await runDoctor(checkNative: self.native, with: out)
44+
_ = try await runDoctor(checkNative: self.native, checkDevices: self.checkDevices, with: out)
4245
let latestVersion = await checkSkipUpdates(with: out)
4346
if let latestVersion = latestVersion, latestVersion != skipVersion {
4447
await out.yield(MessageBlock(status: .warn, "A new version is Skip (\(latestVersion)) is available to update with: skip upgrade"))
@@ -51,8 +54,8 @@ extension ToolOptionsCommand where Self : StreamingCommand {
5154
// TODO: check license validity: https://github.com/skiptools/skip/issues/388
5255

5356
/// Runs the `skip doctor` command and stream the results to the messenger.
54-
/// Returns true if Android devices/emulators are attached, false otherwise.
55-
func runDoctor(checkNative: Bool, with out: MessageQueue) async throws -> Bool {
57+
/// Returns true if Android devices/emulators are attached, false otherwise (or if checkDevices is false).
58+
func runDoctor(checkNative: Bool, checkDevices: Bool = true, with out: MessageQueue) async throws -> Bool {
5659
/// Invokes the given command and attempts to parse the output against the given regular expression pattern to validate that it is a semantic version string
5760
func checkVersion(title: String, cmd: [String], min: Version? = nil, pattern: String, watch: Bool = false, hint: String? = nil) async throws {
5861

@@ -145,21 +148,23 @@ extension ToolOptionsCommand where Self : StreamingCommand {
145148
try await checkVersion(title: "Android Debug Bridge version", cmd: ["adb", "version"], min: Version("1.0.40"), pattern: "version ([0-9.]+)")
146149

147150
var hasAndroidDevices = false
148-
_ = await outputOptions.monitor(with: out, "Android devices", watch: false, resultHandler: { result in
149-
do {
150-
let devices = try result?.get() ?? []
151-
hasAndroidDevices = !devices.isEmpty
152-
if devices.isEmpty {
153-
return (result, MessageBlock(status: .warn, "No Android devices running. Xcode builds will fail until you attach a device, launch an emulator in Android Studio, or run: skip android emulator launch"))
154-
} else {
155-
return (result, MessageBlock(status: .pass, "Android devices: \(devices.count) connected"))
151+
if checkDevices {
152+
_ = await outputOptions.monitor(with: out, "Android devices", watch: false, resultHandler: { result in
153+
do {
154+
let devices = try result?.get() ?? []
155+
hasAndroidDevices = !devices.isEmpty
156+
if devices.isEmpty {
157+
return (result, MessageBlock(status: .warn, "No Android devices running. Xcode builds will fail until you attach a device, launch an emulator in Android Studio, or run: skip android emulator launch"))
158+
} else {
159+
return (result, MessageBlock(status: .pass, "Android devices: \(devices.count) connected"))
160+
}
161+
} catch {
162+
return (result, MessageBlock(status: .fail, "Android devices: error running adb devices"))
156163
}
157-
} catch {
158-
return (result, MessageBlock(status: .fail, "Android devices: error running adb devices"))
159-
}
160-
}, monitorAction: { _ in
161-
try await getAndroidDevices()
162-
})
164+
}, monitorAction: { _ in
165+
try await getAndroidDevices()
166+
})
167+
}
163168

164169
if let androidHome = ProcessInfo.androidHome {
165170
let exists = FileManager.default.fileExists(atPath: androidHome)

0 commit comments

Comments
 (0)