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

Support downloading prebuilt distributions >= 1.9.20 from Maven Central #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class KotlinNativeCompilerDirs(compilerVersion: CompilerVersion) {
hostPlatform = HostPlatform.current
)

val compilerDir = KotlinNativeCompilerInfo.konanDir.resolve(compilerInfo.dependencyNameWithVersion)
val compilerDir = KotlinNativeCompilerInfo.konanDir.resolve(compilerInfo.rootDirName)
val platformKlibsDir = compilerDir.resolve("klib").resolve("platform")
val completeKotlinExtractionDir = platformKlibsDir.resolve("tmp-complete-kotlin")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal class KotlinNativeCompilerInfo(
val konanDir = File(System.getProperty("user.home")).resolve(".konan")
}

private val isPublishedToMavenCentral = compilerVersion.isAtLeast(CompilerVersion.fromString("1.9.20"))

private val kindaSimpleOsName: String = when {
compilerVersion.supportsPlatformName() -> when (hostPlatform) {
HostPlatform.current -> HostPlatform.platformName
Expand All @@ -26,23 +28,60 @@ internal class KotlinNativeCompilerInfo(
else -> hostPlatform.simpleOsName
}

val dependencyName: String = "kotlin-native-prebuilt-$kindaSimpleOsName"
val dependencyNameWithVersion: String = "$dependencyName-$compilerVersion"
private val artifactId: String = "kotlin-native-prebuilt"

/**
* The name of the root directory contained inside the Native compiler archive, or as seen in the .konan directory.
* This follows the old style pattern `kotlin-native-prebuilt-<platform>-<version>` for all versions.
*
* Example: `kotlin-native-prebuilt-windows-x86_64-2.0.20`
*/
val rootDirName: String = "$artifactId-$kindaSimpleOsName-$compilerVersion"

/**
* The name of the Kotlin/Native prebuilt archive, without the extension.
*
* * On JetBrains CDN (for versions < 1.9.20), the pattern is `kotlin-native-prebuilt-<platform>-<version>`.
* * On Maven Central (for versions >= 1.9.20), the pattern is `kotlin-native-prebuilt-<version>-<platform>`.
*
* Examples:
* * `kotlin-native-prebuilt-1.9.10-windows-x86_64`
* * `kotlin-native-prebuilt-windows-x86_64-2.0.20`
*/
val archiveNameWithoutExtension: String = if (isPublishedToMavenCentral) {
"$artifactId-$compilerVersion-$kindaSimpleOsName"
} else {
"$artifactId-$kindaSimpleOsName-$compilerVersion"
}

val useZip = hostPlatform == HostPlatform.Windows
val archiveExtension: String = if (useZip) "zip" else "tar.gz"

/**
* The URL of the repository, including the path to the directory that directly contains the artifact.
*
* Examples:
* * `https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.20`
* * `https://complete-kotlin-prebuilt.louiscad.com/kotlin/native/builds/releases/1.9.10/macos-x86_64`
*/
val repoUrl: String
get() = "https://complete-kotlin-prebuilt.louiscad.com/kotlin/native/builds".let { baseDownloadUrl ->
val releasePath = when (compilerVersion.meta) {
MetaVersion.DEV -> "dev"
else -> "releases"
get() = if (isPublishedToMavenCentral) {
"https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/$compilerVersion"
} else {
"https://complete-kotlin-prebuilt.louiscad.com/kotlin/native/builds".let { baseDownloadUrl ->
val releasePath = when (compilerVersion.meta) {
MetaVersion.DEV -> "dev"
else -> "releases"
}
"$baseDownloadUrl/$releasePath/$compilerVersion/$kindaSimpleOsName"
}
"$baseDownloadUrl/$releasePath/$compilerVersion/$kindaSimpleOsName"
}

/**
* The direct URL to the prebuilt Kotlin/Native distribution archive.
*
* Example: `https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-native-prebuilt/2.0.20/kotlin-native-prebuilt-2.0.20-macos-x86_64.tar.gz`
*/
val dependencyUrl: String
get() {
val dependencyFileName = "$dependencyNameWithVersion.$archiveExtension"
return "$repoUrl/$dependencyFileName"
}
get() = "$repoUrl/$archiveNameWithoutExtension.$archiveExtension"
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ internal class PlatformKlibsInstaller(
return project.repositories.ivy {
setUrl(repoUrl)
patternLayout {
artifact("[artifact]-[revision].[ext]")
// We shove everything into 'artifact' for 2 reasons:
// 1) We want to support both the old and new archive names and they don't have the same pattern.
// 2) Ivy doesn't seem to have a concept of classifier, so we can't support the new format
// (kotlin-native-prebuilt-<version>-<platform>.<extension>) by keeping the version separate.
// Examples:
// - kotlin-native-prebuilt-1.9.10-windows-x86_64.zip
// - kotlin-native-prebuilt-windows-x86_64-2.0.20.zip
artifact("[artifact].[ext]")
}
metadataSources {
artifact()
Expand All @@ -49,8 +56,7 @@ internal class PlatformKlibsInstaller(

val compilerDependency = project.dependencies.create(
mapOf(
"name" to platformCompilerInfo.dependencyName,
"version" to platformCompilerInfo.compilerVersion.toString(),
"name" to platformCompilerInfo.archiveNameWithoutExtension, // corresponds to Ivy's `artifact`
"ext" to platformCompilerInfo.archiveExtension
)
)
Expand All @@ -76,7 +82,7 @@ internal class PlatformKlibsInstaller(
logger.lifecycleWithDuration("Unpack of the magic to $compilerDirectory finished,") {
project.copy {
from(archiveFileTree(archive)) {
include("${platformCompilerInfo.dependencyNameWithVersion}/klib/platform/**")
include("${platformCompilerInfo.rootDirName}/klib/platform/**")
}
into(hostCompilerDirs.completeKotlinExtractionDir)
}
Expand All @@ -85,7 +91,7 @@ internal class PlatformKlibsInstaller(
file.isDirectory
}?.asSequence()?.map { it.name }?.toList() ?: emptyList()
hostCompilerDirs.completeKotlinExtractionDir
.resolve(platformCompilerInfo.dependencyNameWithVersion)
.resolve(platformCompilerInfo.rootDirName)
.resolve("klib")
.resolve("platform")
.listFiles { file ->
Expand Down