Skip to content

Commit

Permalink
Merge pull request #93 from touchlab/kpg/fix_spm_with_cocoapods
Browse files Browse the repository at this point in the history
Delay git path call until needed
  • Loading branch information
kpgalligan authored Oct 10, 2022
2 parents 975d73d + 0ca2f4d commit 85b2e19
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android.useAndroidX=true
org.gradle.jvmargs=-Xmx2g

GROUP=co.touchlab.faktory
VERSION_NAME=0.2.2
VERSION_NAME=0.2.3
KOTLIN_VERSION=1.6.21

POM_URL=https://github.com/touchlab/KMMBridge
Expand Down
10 changes: 1 addition & 9 deletions kmmbridge/src/main/kotlin/KmmBridgeExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import co.touchlab.faktory.dependencymanager.CocoapodsDependencyManager
import co.touchlab.faktory.dependencymanager.DependencyManager
import co.touchlab.faktory.dependencymanager.SpecRepo
import co.touchlab.faktory.dependencymanager.SpmDependencyManager
import co.touchlab.faktory.internal.procRunFailLog
import co.touchlab.faktory.versionmanager.GitTagVersionManager
import co.touchlab.faktory.versionmanager.GithubReleaseVersionManager
import co.touchlab.faktory.versionmanager.ManualVersionManager
Expand All @@ -31,7 +30,6 @@ import org.gradle.api.Project
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType
import java.io.File

interface KmmBridgeExtension {
/**
Expand Down Expand Up @@ -100,8 +98,7 @@ interface KmmBridgeExtension {
spmDirectory: String? = null,
packageName: String = project.name,
) {
val swiftPackageFolder = spmDirectory ?: findRepoRoot()
val dependencyManager = SpmDependencyManager(swiftPackageFolder, packageName)
val dependencyManager = SpmDependencyManager(spmDirectory, packageName)
dependencyManagers.set(dependencyManagers.getOrElse(emptyList()) + dependencyManager)
}

Expand All @@ -113,9 +110,4 @@ interface KmmBridgeExtension {
val dependencyManager = CocoapodsDependencyManager(specRepo)
dependencyManagers.set(dependencyManagers.getOrElse(emptyList()) + dependencyManager)
}
}

private fun Project.findRepoRoot(): String {
val repoFile = File(procRunFailLog("git", "rev-parse", "--show-toplevel").first())
return projectDir.toPath().relativize(repoFile.toPath()).toString()
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class SpmDependencyManager(
/**
* Folder where the Package.swift file lives
*/
private val swiftPackageFolder: String,
private val _swiftPackageFolder: String?,
private val packageName: String
) : DependencyManager {
private val swiftPackageFilePath: String
get() = "${stripEndSlash(swiftPackageFolder)}/Package.swift"
private fun Project.swiftPackageFolder(): String = _swiftPackageFolder ?: this.findRepoRoot()
private fun Project.swiftPackageFilePath(): String = "${stripEndSlash(swiftPackageFolder())}/Package.swift"

override fun configure(project: Project, uploadTask: Task, publishRemoteTask: Task) {
val updatePackageSwiftTask = project.task("updatePackageSwift") {
Expand Down Expand Up @@ -66,14 +66,14 @@ class SpmDependencyManager(
@Suppress("ObjectLiteralToLambda")
doLast(object : Action<Task> {
override fun execute(t: Task) {
project.writePackageFile(makeLocalDevPackageFileText(swiftPackageFolder, packageName, project))
project.writePackageFile(makeLocalDevPackageFileText(project.swiftPackageFolder(), packageName, project))
}
})
}
}

private fun Project.writePackageFile(packageName: String, url: String, checksum: String){
val swiftPackageFile = file(swiftPackageFilePath)
val swiftPackageFile = file(swiftPackageFilePath())
val packageText = makePackageFileText(packageName, url, checksum)
swiftPackageFile.parentFile.mkdirs()
swiftPackageFile.writeText(packageText)
Expand Down Expand Up @@ -108,7 +108,7 @@ class SpmDependencyManager(
}

private fun Project.writePackageFile(data:String){
file(swiftPackageFilePath).writeText(data)
file(swiftPackageFilePath()).writeText(data)
}

override val needsGitTags: Boolean = true
Expand Down Expand Up @@ -185,3 +185,8 @@ let package = Package(
]
)
""".trimIndent()

private fun Project.findRepoRoot(): String {
val repoFile = File(procRunFailLog("git", "rev-parse", "--show-toplevel").first())
return projectDir.toPath().relativize(repoFile.toPath()).toString()
}

0 comments on commit 85b2e19

Please sign in to comment.