Skip to content

Commit

Permalink
Merge pull request #108 from touchlab/kpg/info-command-15.3
Browse files Browse the repository at this point in the history
Fix info command for 15.3
  • Loading branch information
samhill303 authored Jun 11, 2024
2 parents 595d5b0 + 22c40a7 commit e2c52ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/macosMain/kotlin/co/touchlab/xcode/cli/XcodeHelper.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package co.touchlab.xcode.cli

import co.touchlab.kermit.Logger
import co.touchlab.xcode.cli.XcodeHelper.Defaults.nonApplePlugins
import co.touchlab.xcode.cli.util.BackupHelper
import co.touchlab.xcode.cli.util.Console
import co.touchlab.xcode.cli.util.File
import co.touchlab.xcode.cli.util.fromString
import co.touchlab.xcode.cli.util.Path
import co.touchlab.xcode.cli.util.PropertyList
import co.touchlab.xcode.cli.util.Shell
import co.touchlab.xcode.cli.util.Version
import co.touchlab.xcode.cli.util.fromString
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -85,7 +84,7 @@ object XcodeHelper {
checkNotNull(versionPlist.build?.trim()) { "Couldn't get build number of Xcode at $path." }
}

if (Version.fromString(version) >= Version.fromString("15.3")) {
if (version15_3_orHigher(version)) {
return XcodeInstallation(
version = version,
build = build,
Expand All @@ -94,10 +93,11 @@ object XcodeHelper {
}

val xcodeInfoPath = path / "Contents" / "Info"
val pluginCompatabilityIdResult = Shell.exec("/usr/bin/defaults", "read", xcodeInfoPath.value, "DVTPlugInCompatibilityUUID")
.checkSuccessful {
"Couldn't get plugin compatibility UUID from Xcode at ${path}."
}
val pluginCompatabilityIdResult =
Shell.exec("/usr/bin/defaults", "read", xcodeInfoPath.value, "DVTPlugInCompatibilityUUID")
.checkSuccessful {
"Couldn't get plugin compatibility UUID from Xcode at ${path}."
}
val pluginCompatabilityId = checkNotNull(pluginCompatabilityIdResult.output?.trim()) {
"Couldn't get plugin compatibility ID of Xcode at path: ${path}."
}
Expand Down Expand Up @@ -167,8 +167,13 @@ object XcodeHelper {
val pluginCompatabilityId: String? = null,
) {
val name: String = "Xcode $version ($build)"

fun supported(supportedXcodeUuids: Set<String>): Boolean = version15_3_orHigher(version) ||
supportedXcodeUuids.contains(pluginCompatabilityId)
}

fun version15_3_orHigher(version: String) = Version.fromString(version) >= Version.fromString("15.3")

@Serializable
private data class SystemProfilerOutput(
@SerialName("SPDeveloperToolsDataType")
Expand Down Expand Up @@ -216,6 +221,7 @@ object XcodeHelper {
NonApplePlugins(value.dictionary)
}
}

fun PropertyList.nonApplePlugins(xcodeVersion: String): NonApplePlugins {
val backingDictionary = root.dictionary.getOrPut(nonApplePluginsKeyPrefix + xcodeVersion) {
PropertyList.Object.Dictionary(
Expand Down
5 changes: 3 additions & 2 deletions src/macosMain/kotlin/co/touchlab/xcode/cli/command/Info.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class Info: BaseXcodeListSubcommand("info", "Shows information about the plugin"
echo("Installed Xcode versions:")
val longestNameLength = xcodeInstallations.maxOf { it.name.length }
for (install in xcodeInstallations) {
val spacesAfterName = (1..(longestNameLength - install.name.length)).joinToString(separator = "") { " " }
val compatibilityMark = if (supportedXcodeUuids.contains(install.pluginCompatabilityId)) "" else "x"
val spacesAfterName =
(1..(longestNameLength - install.name.length)).joinToString(separator = "") { " " }
val compatibilityMark = if (install.supported(supportedXcodeUuids)) "" else "x"
echo("$compatibilityMark\t${install.name}$spacesAfterName\t${install.pluginCompatabilityId}\t${install.path}")
}

Expand Down

0 comments on commit e2c52ba

Please sign in to comment.