@@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
33import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
44import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
55import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
6+ import java.util.Locale
67
78plugins {
89 alias(libs.plugins.kotlin.mutliplatform)
@@ -22,9 +23,109 @@ repositories {
2223}
2324
2425apiValidation {
25- ignoredProjects + = listOf (" benchmark" , " test-suites" )
26+ ignoredProjects + = listOf (" benchmark" , " test-suites" , " generator " )
2627}
2728
29+ val generatedSourceDirectory: Provider <Directory > = layout.buildDirectory.dir(" generated/source/unicode" )
30+
31+ // region Generation tasks block
32+ val generatorConfiguration: Configuration by configurations.creating
33+
34+ dependencies {
35+ generatorConfiguration(project(" :generator" ))
36+ }
37+
38+ val dumpDir: Provider <Directory > = layout.buildDirectory.dir(" unicode_dump" )
39+
40+ val dumpCharacterData by tasks.register<JavaExec >(" dumpCharacterData" ) {
41+ onlyIf {
42+ dumpDir.get().asFile.run { ! exists() || listFiles().isNullOrEmpty() }
43+ }
44+ outputs.dir(dumpDir)
45+ classpath(generatorConfiguration)
46+ mainClass.set(" io.github.optimumcode.unocode.generator.Main" )
47+ args(
48+ " dump" ,
49+ " -o" ,
50+ dumpDir.get(),
51+ )
52+ }
53+
54+ val generateCharacterDirectionData by tasks.register<JavaExec >(" generateCharacterDirectionData" ) {
55+ inputs.dir(dumpDir)
56+ outputs.dir(generatedSourceDirectory)
57+
58+ dependsOn(dumpCharacterData)
59+
60+ classpath(generatorConfiguration)
61+ mainClass.set(" io.github.optimumcode.unocode.generator.Main" )
62+ args(
63+ " character-direction" ,
64+ " -p" ,
65+ " io.github.optimumcode.json.schema.internal.unicode" ,
66+ " -o" ,
67+ generatedSourceDirectory.get(),
68+ " -d" ,
69+ dumpDir.get(),
70+ )
71+ }
72+
73+ val generateCharacterCategoryData by tasks.register<JavaExec >(" generateCharacterCategoryData" ) {
74+ inputs.dir(dumpDir)
75+ outputs.dir(generatedSourceDirectory)
76+
77+ dependsOn(dumpCharacterData)
78+
79+ classpath(generatorConfiguration)
80+ mainClass.set(" io.github.optimumcode.unocode.generator.Main" )
81+ args(
82+ " character-category" ,
83+ " -p" ,
84+ " io.github.optimumcode.json.schema.internal.unicode" ,
85+ " -o" ,
86+ generatedSourceDirectory.get(),
87+ " -d" ,
88+ dumpDir.get(),
89+ )
90+ }
91+
92+ val generateDerivedProperties by tasks.register<JavaExec >(" generateDerivedProperties" ) {
93+ val dataFile = layout.projectDirectory.dir(" generator" ).dir(" data" ).file(" rfc5895_appendix_b_1.txt" )
94+ inputs.file(dataFile)
95+ outputs.dir(generatedSourceDirectory)
96+
97+ classpath(generatorConfiguration)
98+ mainClass.set(" io.github.optimumcode.unocode.generator.Main" )
99+ args(
100+ " derived-properties" ,
101+ " -p" ,
102+ " io.github.optimumcode.json.schema.internal.unicode" ,
103+ " -o" ,
104+ generatedSourceDirectory.get(),
105+ " -d" ,
106+ dataFile,
107+ )
108+ }
109+
110+ val generateJoiningTypes by tasks.register<JavaExec >(" generateJoiningTypes" ) {
111+ val dataFile = layout.projectDirectory.dir(" generator" ).dir(" data" ).file(" DerivedJoiningType.txt" )
112+ inputs.file(dataFile)
113+ outputs.dir(generatedSourceDirectory)
114+
115+ classpath(generatorConfiguration)
116+ mainClass.set(" io.github.optimumcode.unocode.generator.Main" )
117+ args(
118+ " joining-types" ,
119+ " -p" ,
120+ " io.github.optimumcode.json.schema.internal.unicode" ,
121+ " -o" ,
122+ generatedSourceDirectory.get(),
123+ " -d" ,
124+ dataFile,
125+ )
126+ }
127+ // endregion
128+
28129kotlin {
29130 explicitApi()
30131
@@ -74,9 +175,18 @@ kotlin {
74175
75176 sourceSets {
76177 commonMain {
178+ kotlin.srcDirs(generatedSourceDirectory)
179+
77180 dependencies {
78181 api(libs.kotlin.serialization.json)
79182 implementation(libs.uri)
183+ // When using approach like above you won't be able to add because block
184+ implementation(libs.kotlin.codepoints.get().toString()) {
185+ because(" simplifies work with unicode codepoints" )
186+ }
187+ implementation(libs.normalize.get().toString()) {
188+ because(" provides normalization required by IDN-hostname format" )
189+ }
80190 }
81191 }
82192 commonTest {
@@ -94,6 +204,19 @@ kotlin {
94204 }
95205 }
96206
207+ targets.configureEach {
208+ val capitalizedTargetName =
209+ name.replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale .getDefault()) else it.toString() }
210+ tasks.named(" compileKotlin$capitalizedTargetName " ) {
211+ dependsOn(
212+ generateCharacterDirectionData,
213+ generateCharacterCategoryData,
214+ generateDerivedProperties,
215+ generateJoiningTypes,
216+ )
217+ }
218+ }
219+
97220 afterEvaluate {
98221 fun Task.dependsOnTargetTests (targets : List <KotlinTarget >) {
99222 targets.forEach {
@@ -122,11 +245,48 @@ kotlin {
122245 }
123246}
124247
248+ afterEvaluate {
249+ val taskNames = setOf (" compile" , " detekt" , " runKtlint" )
250+ tasks.configureEach {
251+ // There is something wrong with compileCommonMainKotlinMetadata task
252+ // Gradle cannot find it, but this task uses the generated source directory
253+ // and Gradle reports implicit dependency.
254+ // As a workaround I do this - seems like it is working.
255+ // However, I might be missing something. Need to revisit this later.
256+
257+ if (taskNames.any { name.startsWith(it) }) {
258+ mustRunAfter(
259+ generateCharacterDirectionData,
260+ generateCharacterCategoryData,
261+ generateDerivedProperties,
262+ generateJoiningTypes,
263+ )
264+ }
265+ }
266+ }
267+
268+ koverReport {
269+ filters {
270+ excludes {
271+ packages(
272+ " io.github.optimumcode.json.schema.internal.unicode.*" ,
273+ " io.github.optimumcode.json.schema.internal.unicode" ,
274+ )
275+ }
276+ }
277+ }
278+
125279ktlint {
126280 version.set(libs.versions.ktlint)
127281 reporters {
128282 reporter(ReporterType .HTML )
129283 }
284+ filter {
285+ exclude { el ->
286+ val absolutePath = el.file.absolutePath
287+ absolutePath.contains(" generated" ).and (! el.isDirectory)
288+ }
289+ }
130290}
131291
132292afterEvaluate {
0 commit comments