Refactor kotlin-stdlib-gen
- Make targetsToGenerate Collection to accept set in addition to list - Unify generated file name schema to '_<source name><platform suffix>.kt'
This commit is contained in:
@@ -61,15 +61,13 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
templateGroups.groupByFileAndWrite(targetsToGenerate = targetBaseDirs.keys.toList()) { (target, source) ->
|
templateGroups.groupByFileAndWrite(targetsToGenerate = targetBaseDirs.keys) { (target, source) ->
|
||||||
val targetDir = targetBaseDirs[target] ?: error("Target $target directory is not configured")
|
val targetDir = targetBaseDirs[target] ?: error("Target $target directory is not configured")
|
||||||
when (target) {
|
val platformSuffix = when (val platform = target.platform) {
|
||||||
KotlinTarget.Common -> targetDir.resolve("_${source.name.capitalize()}.kt")
|
Platform.Common -> ""
|
||||||
KotlinTarget.JVM -> targetDir.resolve("_${source.name.capitalize()}Jvm.kt")
|
else -> platform.name.toLowerCase().capitalize()
|
||||||
KotlinTarget.JS -> targetDir.resolve("_${source.name.capitalize()}Js.kt")
|
|
||||||
KotlinTarget.JS_IR -> targetDir.resolve("_${source.name.capitalize()}Js.kt")
|
|
||||||
KotlinTarget.Native -> targetDir.resolve("_${source.name.capitalize()}Native.kt")
|
|
||||||
}
|
}
|
||||||
|
targetDir.resolve("_${source.name.capitalize()}$platformSuffix.kt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ interface MemberTemplate {
|
|||||||
/** Specifies which platforms this member template should be generated for */
|
/** Specifies which platforms this member template should be generated for */
|
||||||
fun platforms(vararg platforms: Platform)
|
fun platforms(vararg platforms: Platform)
|
||||||
|
|
||||||
fun instantiate(targets: List<KotlinTarget> = KotlinTarget.values): Sequence<MemberBuilder>
|
fun instantiate(targets: Collection<KotlinTarget> = KotlinTarget.values): Sequence<MemberBuilder>
|
||||||
|
|
||||||
/** Registers parameterless member builder function */
|
/** Registers parameterless member builder function */
|
||||||
fun builder(b: MemberBuildAction)
|
fun builder(b: MemberBuildAction)
|
||||||
@@ -105,7 +105,7 @@ abstract class MemberTemplateDefinition<TParam> : MemberTemplate {
|
|||||||
} ?: this
|
} ?: this
|
||||||
|
|
||||||
|
|
||||||
override fun instantiate(targets: List<KotlinTarget>): Sequence<MemberBuilder> {
|
override fun instantiate(targets: Collection<KotlinTarget>): Sequence<MemberBuilder> {
|
||||||
val resultingTargets = targets.filter { it.platform in allowedPlatforms }
|
val resultingTargets = targets.filter { it.platform in allowedPlatforms }
|
||||||
val resultingPlatforms = resultingTargets.map { it.platform }.distinct()
|
val resultingPlatforms = resultingTargets.map { it.platform }.distinct()
|
||||||
val specificTargets by lazy { resultingTargets - KotlinTarget.Common }
|
val specificTargets by lazy { resultingTargets - KotlinTarget.Common }
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ data class TargetedSourceFile(
|
|||||||
|
|
||||||
@JvmName("groupByFileAndWriteGroups")
|
@JvmName("groupByFileAndWriteGroups")
|
||||||
fun Sequence<TemplateGroup>.groupByFileAndWrite(
|
fun Sequence<TemplateGroup>.groupByFileAndWrite(
|
||||||
targetsToGenerate: List<KotlinTarget>,
|
targetsToGenerate: Collection<KotlinTarget>,
|
||||||
fileNameBuilder: (TargetedSourceFile) -> File
|
fileNameBuilder: (TargetedSourceFile) -> File
|
||||||
) {
|
) {
|
||||||
flatMap { group ->
|
flatMap { group ->
|
||||||
@@ -51,7 +51,7 @@ fun Sequence<TemplateGroup>.groupByFileAndWrite(
|
|||||||
|
|
||||||
@JvmName("groupByFileAndWriteTemplates")
|
@JvmName("groupByFileAndWriteTemplates")
|
||||||
fun Sequence<MemberTemplate>.groupByFileAndWrite(
|
fun Sequence<MemberTemplate>.groupByFileAndWrite(
|
||||||
targetsToGenerate: List<KotlinTarget>,
|
targetsToGenerate: Collection<KotlinTarget>,
|
||||||
fileNameBuilder: (TargetedSourceFile) -> File
|
fileNameBuilder: (TargetedSourceFile) -> File
|
||||||
) {
|
) {
|
||||||
flatMap { it.instantiate(targetsToGenerate) }
|
flatMap { it.instantiate(targetsToGenerate) }
|
||||||
|
|||||||
Reference in New Issue
Block a user