From ba2ba6a3c30fbde3c47361e0d4b1c401d4e90e2e Mon Sep 17 00:00:00 2001 From: arturm Date: Sun, 20 Feb 2022 12:46:42 +0200 Subject: [PATCH 1/4] [WIP] Cocoapods detection --- .../doctor/diagnostics/CocoapodsDiagnostic.kt | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt index fcdad3d..f9f8605 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt @@ -4,12 +4,31 @@ import org.jetbrains.kotlin.doctor.entity.Application import org.jetbrains.kotlin.doctor.entity.System import org.jetbrains.kotlin.doctor.entity.Version import org.jetbrains.kotlin.doctor.entity.execute -import org.jetbrains.kotlin.doctor.entity.getEnvVar class CocoapodsDiagnostic : Diagnostic("Cocoapods") { + override fun runChecks(): List { val messages = mutableListOf() + val (code, output, error) = System.execute("brew", "list", "cocoapods") + + val cocoapodsFormulae = System.execute("brew", "list", "", "cocoapods", "").output + ?.lines() + + val cocoapodsFromHomebrew = cocoapodsFormulae?.let { lines -> + lines.find { it.contains("cocoapods:") } + ?.split("/") + ?.find { it.matches(Regex(COCOAPODS_VERSION_PATTERN)) } + ?.substringAfter("_") + ?.let { version -> + Application(name = "cocoapods", version = Version(version)) + } + } + + if (cocoapodsFromHomebrew != null) { + messages.addSuccess("Found cocoapods in Homebrew: ${cocoapodsFromHomebrew.name} (${cocoapodsFromHomebrew.version})") + } + val rubyVersion = System.execute("ruby", "-v").output val rubyLocation = System.execute("which", "ruby").output if (rubyLocation == null || rubyVersion == null) { @@ -62,8 +81,13 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { Application(name, version) } - val cocoapods = cocoapodsGems?.firstOrNull { it.name == "cocoapods" } - if (cocoapods == null) { + val cocoapodsFromGem = cocoapodsGems?.firstOrNull { it.name == "cocoapods" } + + if (cocoapodsFromGem != null) { + messages.addSuccess("Found cocoapods in Gem: ${cocoapodsFromGem.name} (${cocoapodsFromGem.version})") + } + + if (cocoapodsFromGem == null && cocoapodsFromHomebrew == null) { messages.addFailure( "cocoapods not found", "Get cocoapods from https://guides.cocoapods.org/using/getting-started.html#installation" @@ -71,7 +95,9 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { return messages } - messages.addSuccess("${cocoapods.name} (${cocoapods.version})") + if (cocoapodsFromGem == null) { + return messages + } val cocoapodsGenerate = cocoapodsGems.firstOrNull { it.name == "cocoapods-generate" } if (cocoapodsGenerate == null) { @@ -97,7 +123,7 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { Consider adding the following to ${System.getShell()?.profile ?: "shell profile"} export LC_ALL=en_US.UTF-8 """.trimIndent() - if (cocoapods.version > Version(1, 10, 2)) { + if (cocoapodsFromGem.version > Version(1, 10, 2)) { messages.addFailure("CocoaPods requires your terminal to be using UTF-8 encoding.", hint) } else { messages.addWarning("CocoaPods requires your terminal to be using UTF-8 encoding.", hint) @@ -106,4 +132,8 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { return messages } + + companion object { + private const val COCOAPODS_VERSION_PATTERN = "^\\d\\.\\d{1,2}.\\d{1,2}\$" + } } \ No newline at end of file From 4d85ca0a4ffcfc3070ee66a44537e2b8fb8e7880 Mon Sep 17 00:00:00 2001 From: arturm Date: Sun, 20 Feb 2022 16:47:01 +0200 Subject: [PATCH 2/4] Implemented detection of Cocoapods installed via Homebrew --- .../kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt index f9f8605..8392085 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt @@ -10,16 +10,14 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { override fun runChecks(): List { val messages = mutableListOf() - val (code, output, error) = System.execute("brew", "list", "cocoapods") - - val cocoapodsFormulae = System.execute("brew", "list", "", "cocoapods", "").output + val cocoapodsFormulae = System.execute("brew", "list", "cocoapods").output ?.lines() val cocoapodsFromHomebrew = cocoapodsFormulae?.let { lines -> - lines.find { it.contains("cocoapods:") } + lines.find { it.contains("/bin/pod") } ?.split("/") ?.find { it.matches(Regex(COCOAPODS_VERSION_PATTERN)) } - ?.substringAfter("_") + ?.substringBefore("_") ?.let { version -> Application(name = "cocoapods", version = Version(version)) } @@ -29,7 +27,7 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { messages.addSuccess("Found cocoapods in Homebrew: ${cocoapodsFromHomebrew.name} (${cocoapodsFromHomebrew.version})") } - val rubyVersion = System.execute("ruby", "-v").output + val rubyVersion = System.execute("ruby", "-v", verbose = true).output val rubyLocation = System.execute("which", "ruby").output if (rubyLocation == null || rubyVersion == null) { messages.addFailure( @@ -134,6 +132,6 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { } companion object { - private const val COCOAPODS_VERSION_PATTERN = "^\\d\\.\\d{1,2}.\\d{1,2}\$" + private const val COCOAPODS_VERSION_PATTERN = "^\\d\\.\\d{1,2}.\\d{1,2}(_\\d)?$" } } \ No newline at end of file From 3651b0ec5b549600e7e09562e8a8b524c4b94b32 Mon Sep 17 00:00:00 2001 From: amatsehor Date: Mon, 21 Feb 2022 13:53:15 +0200 Subject: [PATCH 3/4] Removed non-existing parameter, thus made the branch compilable (oops) --- .../jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt index 8392085..5bcd472 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt @@ -27,7 +27,7 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { messages.addSuccess("Found cocoapods in Homebrew: ${cocoapodsFromHomebrew.name} (${cocoapodsFromHomebrew.version})") } - val rubyVersion = System.execute("ruby", "-v", verbose = true).output + val rubyVersion = System.execute("ruby", "-v").output val rubyLocation = System.execute("which", "ruby").output if (rubyLocation == null || rubyVersion == null) { messages.addFailure( From 7e931c3c6e28040e7d7a029ea8e066403d2ebd19 Mon Sep 17 00:00:00 2001 From: Viacheslav Kormushkin Date: Fri, 25 Mar 2022 13:53:30 +0300 Subject: [PATCH 4/4] Cocoapods via Homebrew: refactored as per PR comments --- .../doctor/diagnostics/CocoapodsDiagnostic.kt | 80 +++++++++---------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt index 5bcd472..5c0a123 100644 --- a/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt +++ b/kdoctor/src/commonMain/kotlin/org/jetbrains/kotlin/doctor/diagnostics/CocoapodsDiagnostic.kt @@ -6,27 +6,9 @@ import org.jetbrains.kotlin.doctor.entity.Version import org.jetbrains.kotlin.doctor.entity.execute class CocoapodsDiagnostic : Diagnostic("Cocoapods") { - override fun runChecks(): List { val messages = mutableListOf() - val cocoapodsFormulae = System.execute("brew", "list", "cocoapods").output - ?.lines() - - val cocoapodsFromHomebrew = cocoapodsFormulae?.let { lines -> - lines.find { it.contains("/bin/pod") } - ?.split("/") - ?.find { it.matches(Regex(COCOAPODS_VERSION_PATTERN)) } - ?.substringBefore("_") - ?.let { version -> - Application(name = "cocoapods", version = Version(version)) - } - } - - if (cocoapodsFromHomebrew != null) { - messages.addSuccess("Found cocoapods in Homebrew: ${cocoapodsFromHomebrew.name} (${cocoapodsFromHomebrew.version})") - } - val rubyVersion = System.execute("ruby", "-v").output val rubyLocation = System.execute("which", "ruby").output if (rubyLocation == null || rubyVersion == null) { @@ -70,34 +52,47 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { val gems = Application("ruby gems", Version(rubyGemsVersion)) messages.addSuccess("${gems.name} (${gems.version})") - val gemList = System.execute("gem", "list", "--local", "cocoapods").output - val cocoapodsGems = gemList?.split("\n")?.mapNotNull { - val nameAndVersion = it.split(" ", limit = 2) - val name = nameAndVersion.firstOrNull() ?: return@mapNotNull null - val versionString = nameAndVersion.lastOrNull()?.trim('(', ')') - val version = if (versionString != null) Version(versionString) else Version.unknown - Application(name, version) + var cocoapods: Application? = null + val cocoapodsVersionOutput = System.execute("pod", "--version").output + if (cocoapodsVersionOutput != null) { + val cocoapodsVersion = Version(cocoapodsVersionOutput) + cocoapods = Application("cocoapods", cocoapodsVersion) } - - val cocoapodsFromGem = cocoapodsGems?.firstOrNull { it.name == "cocoapods" } - - if (cocoapodsFromGem != null) { - messages.addSuccess("Found cocoapods in Gem: ${cocoapodsFromGem.name} (${cocoapodsFromGem.version})") - } - - if (cocoapodsFromGem == null && cocoapodsFromHomebrew == null) { + if (cocoapods == null) { + //check if installed via brew but not linked to /usr/bin + val cocoapodsBrewInstallation = System.execute("brew", "list", "cocoapods", "--versions").output + if (cocoapodsBrewInstallation?.isNotBlank() == true) { + messages.addFailure( + "Cocoapods are installed via Homebrew but not linked to /usr/local/bin", + "Execute 'brew link --overwrite cocoapods'" + ) + } else { + messages.addFailure( + "cocoapods not found", + "Get cocoapods from https://guides.cocoapods.org/using/getting-started.html#installation" + ) + } + return messages + } else if (cocoapods.version < Version(1, 8, 0)) { messages.addFailure( - "cocoapods not found", - "Get cocoapods from https://guides.cocoapods.org/using/getting-started.html#installation" + "cocoapods version ${cocoapods.version.version} is outdated", + "Update your cocoapods installation to the latest available version" ) return messages } - - if (cocoapodsFromGem == null) { - return messages + messages.addSuccess("${cocoapods.name} (${cocoapods.version})") + + var cocoapodsGenerate: Application? = null + val cocoapodsGenerateName = "cocoapods-generate" + val plugins = System.execute("pod", "plugins", "installed", "--no-ansi").output + val cocoaPodsGenerateEntry = plugins?.lines()?.find { it.contains(cocoapodsGenerateName) } + if (cocoaPodsGenerateEntry != null) { + val version = cocoaPodsGenerateEntry.split(":").lastOrNull()?.let { Version(it.trim()) } + if (version != null) { + cocoapodsGenerate = Application(cocoapodsGenerateName, version) + } } - val cocoapodsGenerate = cocoapodsGems.firstOrNull { it.name == "cocoapods-generate" } if (cocoapodsGenerate == null) { messages.addFailure( "cocoapods-generate plugin not found", @@ -105,6 +100,7 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { ) return messages } + if (cocoapodsGenerate.version < Version(2, 2, 2)) { messages.addFailure( "Cocoapods-generate version ${cocoapodsGenerate.version} is not supported", @@ -121,7 +117,7 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { Consider adding the following to ${System.getShell()?.profile ?: "shell profile"} export LC_ALL=en_US.UTF-8 """.trimIndent() - if (cocoapodsFromGem.version > Version(1, 10, 2)) { + if (cocoapods.version > Version(1, 10, 2)) { messages.addFailure("CocoaPods requires your terminal to be using UTF-8 encoding.", hint) } else { messages.addWarning("CocoaPods requires your terminal to be using UTF-8 encoding.", hint) @@ -130,8 +126,4 @@ class CocoapodsDiagnostic : Diagnostic("Cocoapods") { return messages } - - companion object { - private const val COCOAPODS_VERSION_PATTERN = "^\\d\\.\\d{1,2}.\\d{1,2}(_\\d)?$" - } } \ No newline at end of file