|
| 1 | +/* |
| 2 | + * Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. |
| 3 | + */ |
| 4 | + |
| 5 | +import kotlin.io.path.createDirectories |
| 6 | +import kotlin.io.path.writeText |
| 7 | + |
| 8 | +// ADD NEW VERSIONS HERE |
| 9 | +val versionDirs = mapOf( |
| 10 | + "v0_8" to CompatVersion("0.8.1", "2.2.0"), |
| 11 | + "v0_9" to CompatVersion("0.9.1", "2.2.0"), |
| 12 | + "v0_10" to CompatVersion("0.10.0", "2.2.20"), |
| 13 | +) |
| 14 | + |
| 15 | +// DON'T MODIFY BELOW THIS LINE |
| 16 | + |
| 17 | +val compatDir: java.nio.file.Path = settings.rootDir.toPath() |
| 18 | + .resolve("tests") |
| 19 | + .resolve("krpc-protocol-compatibility-tests") |
| 20 | + |
| 21 | +val libVersion = settings.extra["libVersion"] as? String |
| 22 | + ?: error("libVersion property is not set") |
| 23 | + |
| 24 | +class CompatVersion( |
| 25 | + val rpc: String, |
| 26 | + val kotlin: String, |
| 27 | +) |
| 28 | + |
| 29 | +versionDirs.forEach { (dir, version) -> |
| 30 | + val moduleDir = compatDir.resolve(dir) |
| 31 | + moduleDir.createDirectories() |
| 32 | + val buildFile = moduleDir.resolve("build.gradle.kts") |
| 33 | + buildFile.writeText( |
| 34 | + """ |
| 35 | + /* THIS FILE IS AUTO-GENERATED, DO NOT EDIT! */ |
| 36 | + |
| 37 | + import util.krpc_compat.setupCompat |
| 38 | +
|
| 39 | + setupCompat("${version.rpc}", "${version.kotlin}") |
| 40 | +
|
| 41 | + """.trimIndent() |
| 42 | + ) |
| 43 | + val propertiesFile = moduleDir.resolve("gradle.properties") |
| 44 | + propertiesFile.writeText( |
| 45 | + """ |
| 46 | + /* THIS FILE IS AUTO-GENERATED, DO NOT EDIT! */ |
| 47 | +
|
| 48 | + kotlin.compiler.runViaBuildToolsApi=true |
| 49 | + |
| 50 | + """.trimIndent() |
| 51 | + ) |
| 52 | + |
| 53 | + logger.lifecycle("Generating :tests:krpc-protocol-compatibility-tests:$dir") |
| 54 | + include(":tests:krpc-protocol-compatibility-tests:$dir") |
| 55 | +} |
| 56 | + |
| 57 | +val versionsConventionsFile: java.nio.file.Path = settings.rootDir.toPath() |
| 58 | + .resolve("gradle-conventions") |
| 59 | + .resolve("src") |
| 60 | + .resolve("main") |
| 61 | + .resolve("kotlin") |
| 62 | + .resolve("util") |
| 63 | + .resolve("krpc_compat") |
| 64 | + .resolve("versions.kt") |
| 65 | + |
| 66 | +logger.lifecycle("Generating krpc_compat/versions.kt") |
| 67 | +versionsConventionsFile.writeText( |
| 68 | + """ |
| 69 | + |/* THIS FILE IS AUTO-GENERATED, DO NOT EDIT! */ |
| 70 | + | |
| 71 | + |package util.krpc_compat |
| 72 | + | |
| 73 | + |val krpcCompatVersions = mapOf( |
| 74 | + | ${versionDirs.entries.joinToString("\n| ") { "\"${it.key}\" to \"${it.value.rpc}\"," }} |
| 75 | + | |
| 76 | + | "Latest" to "$libVersion", // current version |
| 77 | + |) |
| 78 | + | |
| 79 | + """.trimMargin() |
| 80 | +) |
0 commit comments