Skip to content

Commit f95f16a

Browse files
committed
Add buildSrc, bump deps, use K2
1 parent 9fbc090 commit f95f16a

File tree

16 files changed

+250
-98
lines changed

16 files changed

+250
-98
lines changed

build.gradle.kts

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
group = "com.github.Lipen"
45

56
plugins {
6-
kotlin("jvm") version "1.7.20"
7+
kotlin("jvm") version Versions.kotlin
78
application
8-
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
9-
id("fr.brouillard.oss.gradle.jgitver") version "0.9.1"
10-
id("com.github.ben-manes.versions") version "0.44.0"
9+
id(Plugins.Shadow, apply = false)
10+
id(Plugins.JGitver)
1111
`maven-publish`
1212
}
1313

@@ -25,12 +25,11 @@ dependencies {
2525
// ...
2626

2727
// Logging
28-
implementation("io.github.microutils:kotlin-logging:3.0.4")
29-
runtimeOnly("ch.qos.logback:logback-classic:1.4.4")
28+
implementation(Libs.kotlin_logging)
29+
runtimeOnly(Libs.slf4j_simple)
3030

3131
// Test
3232
testImplementation(kotlin("test"))
33-
testImplementation("com.soywiz.korlibs.klock:klock-jvm:3.4.0")
3433
}
3534

3635
tasks.test {
@@ -40,8 +39,16 @@ tasks.test {
4039
}
4140
}
4241

42+
tasks.withType<JavaCompile> {
43+
sourceCompatibility = "1.8"
44+
targetCompatibility = "1.8"
45+
options.encoding = "UTF-8"
46+
}
47+
4348
tasks.withType<KotlinCompile> {
44-
kotlinOptions.jvmTarget = "1.8"
49+
compilerOptions {
50+
jvmTarget.set(JvmTarget.JVM_1_8)
51+
}
4552
}
4653

4754
application {
@@ -72,7 +79,7 @@ publishing {
7279
}
7380

7481
tasks.wrapper {
75-
gradleVersion = "7.5.1"
82+
gradleVersion = "8.8"
7683
distributionType = Wrapper.DistributionType.ALL
7784
}
7885

buildSrc/build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}

buildSrc/settings.gradle.kts

Whitespace-only changes.
+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import org.gradle.kotlin.dsl.apply
2+
import org.gradle.kotlin.dsl.version
3+
import org.gradle.plugin.use.PluginDependenciesSpec
4+
5+
object Versions {
6+
const val okio = "3.9.0"
7+
const val jgitver = "0.9.1"
8+
const val kotlin = "2.0.0"
9+
const val junit = "5.8.1"
10+
const val slf4j = "1.7.36"
11+
const val shadow = "8.1.1"
12+
const val kotlin_logging = "7.0.0"
13+
}
14+
15+
object Libs {
16+
fun dep(group: String, name: String, version: String): String = "$group:$name:$version"
17+
18+
// https://github.com/junit-team/junit5
19+
const val junit_bom = "org.junit:junit-bom:${Versions.junit}"
20+
const val junit_jupiter = "org.junit.jupiter:junit-jupiter"
21+
22+
// https://github.com/oshai/kotlin-logging
23+
val kotlin_logging = dep(
24+
group = "io.github.oshai",
25+
name = "kotlin-logging-jvm",
26+
version = Versions.kotlin_logging
27+
)
28+
29+
// https://github.com/qos-ch/slf4j
30+
val slf4j_simple = dep(
31+
group = "org.slf4j",
32+
name = "slf4j-simple",
33+
version = Versions.slf4j
34+
)
35+
36+
// https://github.com/square/okio
37+
val okio = dep(
38+
group = "com.squareup.okio",
39+
name = "okio",
40+
version = Versions.okio
41+
)
42+
}
43+
44+
object Plugins {
45+
abstract class Plugin(val version: String, val id: String)
46+
47+
// https://github.com/johnrengelman/shadow
48+
object Shadow : Plugin(
49+
version = Versions.shadow,
50+
id = "com.github.johnrengelman.shadow"
51+
)
52+
53+
// https://github.com/jgitver/jgitver
54+
object JGitver : Plugin(
55+
version = Versions.jgitver,
56+
id = "fr.brouillard.oss.gradle.jgitver"
57+
)
58+
}
59+
60+
fun PluginDependenciesSpec.id(plugin: Plugins.Plugin, apply: Boolean = true) {
61+
id(plugin.id) version plugin.version apply apply
62+
}

examples/build.gradle.kts

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
23
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
34

45
plugins {
56
kotlin("jvm")
6-
id("com.github.johnrengelman.shadow")
7+
id(Plugins.Shadow)
78
}
89

910
repositories {
@@ -15,14 +16,21 @@ dependencies {
1516
implementation(kotlin("stdlib-jdk8"))
1617

1718
implementation(rootProject)
18-
implementation("io.github.microutils:kotlin-logging:3.0.4")
19-
runtimeOnly("ch.qos.logback:logback-classic:1.4.4")
20-
implementation("com.soywiz.korlibs.klock:klock-jvm:3.3.1")
21-
implementation("com.squareup.okio:okio:3.2.0")
19+
implementation(Libs.kotlin_logging)
20+
runtimeOnly(Libs.slf4j_simple)
21+
implementation(Libs.okio)
22+
}
23+
24+
tasks.withType<JavaCompile> {
25+
sourceCompatibility = "1.8"
26+
targetCompatibility = "1.8"
27+
options.encoding = "UTF-8"
2228
}
2329

2430
tasks.withType<KotlinCompile> {
25-
kotlinOptions.jvmTarget = "1.8"
31+
compilerOptions {
32+
jvmTarget.set(JvmTarget.JVM_1_8)
33+
}
2634
}
2735

2836
tasks.withType<ShadowJar> {

examples/src/main/kotlin/com/github/lipen/bdd/Dichotomic.kt

+16-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.github.lipen.bdd
22

3-
import com.soywiz.klock.PerformanceCounter
4-
import com.soywiz.klock.measureTime
53
import kotlin.math.absoluteValue
4+
import kotlin.time.Duration
5+
import kotlin.time.DurationUnit
6+
import kotlin.time.TimeSource
7+
import kotlin.time.measureTime
68

79
fun dichotomic(pigeons: Int, holes: Int = pigeons - 1) {
8-
val timeStart = PerformanceCounter.reference
10+
val timeStart = TimeSource.Monotonic.markNow()
911

1012
val clauses = generatePhpClauses(pigeons, holes).toList()
1113
var nvars = clauses.maxOf { clause -> clause.maxOf { lit -> lit.absoluteValue } }
@@ -25,7 +27,7 @@ fun dichotomic(pigeons: Int, holes: Int = pigeons - 1) {
2527
val bdd = BDD(storageBits = 20)
2628
var f = bdd.one
2729

28-
var stepsTime = 0.0
30+
var stepsTime = Duration.ZERO
2931
var count = 0
3032

3133
fun step(name: String, allowGC: Boolean = false, block: () -> Unit) {
@@ -38,14 +40,14 @@ fun dichotomic(pigeons: Int, holes: Int = pigeons - 1) {
3840
}
3941
}
4042
}
41-
stepsTime += steptime.seconds
43+
stepsTime += steptime
4244
val fsize = bdd.descendants(f).size
4345
println(
4446
("Step #$count ($name) in %.3fms," +
4547
" bdd.size=${bdd.size}, bdd.realSize=${bdd.realSize}," +
4648
" f=$f (v=${bdd.getTriplet(f)?.v}), f.size=$fsize," +
47-
" hits=${bdd.cacheHits}, misses=${bdd.cacheMisses}}")
48-
.format(steptime.milliseconds)
49+
" hits=${bdd.cacheHits}, misses=${bdd.cacheMisses}}"
50+
).format(steptime.toDouble(DurationUnit.MILLISECONDS))
4951
)
5052
}
5153

@@ -101,8 +103,13 @@ fun dichotomic(pigeons: Int, holes: Int = pigeons - 1) {
101103
}
102104
printBddStats()
103105

104-
val totalTime = PerformanceCounter.reference - timeStart
105-
println("PHP($pigeons, $holes) done in %.2fs (stepsTime=%.2fs)".format(totalTime.seconds, stepsTime))
106+
val totalTime = timeStart.elapsedNow()
107+
println(
108+
"PHP($pigeons, $holes) done in %.2fs (stepsTime=%.2fs)".format(
109+
totalTime.toDouble(DurationUnit.SECONDS),
110+
stepsTime.toDouble(DurationUnit.SECONDS)
111+
)
112+
)
106113
}
107114

108115
fun main(args: Array<String>) {

examples/src/main/kotlin/com/github/lipen/bdd/Geffe.kt

+23-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
package com.github.lipen.bdd
22

3-
import com.soywiz.klock.PerformanceCounter
4-
import com.soywiz.klock.measureTimeWithResult
3+
import io.github.oshai.kotlinlogging.KotlinLogging
54
import okio.buffer
65
import okio.sink
76
import java.io.File
87
import kotlin.math.absoluteValue
8+
import kotlin.time.Duration
9+
import kotlin.time.DurationUnit
10+
import kotlin.time.TimeSource
11+
import kotlin.time.measureTimedValue
912

10-
private val logger = mu.KotlinLogging.logger {}
13+
private val logger = KotlinLogging.logger {}
1114

1215
private fun readClauses(cnfFile: File): List<List<Int>> {
1316
val result: MutableList<List<Int>> = mutableListOf()
@@ -28,10 +31,10 @@ private fun readClauses(cnfFile: File): List<List<Int>> {
2831
fun geffe() {
2932
println("Running Geffe...")
3033

31-
val timeStart = PerformanceCounter.reference
34+
val timeStart = TimeSource.Monotonic.markNow()
3235
val bdd = BDD(1 shl 24)
3336
var f = bdd.one
34-
var totaltime = 0.0
37+
var totaltime = Duration.ZERO
3538
// val cnfFile = File("data/geffe/geffe_100.cnf")
3639
val cnfFile = File("data/geffe/geffe_30.cnf")
3740
// val cnfFile = File("data/geffe/geffe_30_out1.cnf")
@@ -80,7 +83,7 @@ fun geffe() {
8083

8184
fun <T> step(name: String, allowGC: Boolean = false, block: () -> T): T {
8285
count++
83-
val (result, steptime) = measureTimeWithResult {
86+
val (result, steptime) = measureTimedValue {
8487
block().also {
8588
if (allowGC) {
8689
if (count % 500 == 0 || bdd.realSize > 10000) {
@@ -93,14 +96,17 @@ fun geffe() {
9396
println(
9497
("Step #$count $name in %.3fs, bdd.size=${bdd.size}, bdd.realSize=${bdd.realSize}," +
9598
" f=$f (f.v=${bdd.getTriplet(f)?.v}), f.size=$fsize," +
96-
" hits=${bdd.cacheHits}, misses=${bdd.cacheMisses}")
97-
.format(steptime.seconds)
99+
" hits=${bdd.cacheHits}, misses=${bdd.cacheMisses}"
100+
).format(steptime.toDouble(DurationUnit.SECONDS))
98101
)
99-
totaltime += steptime.seconds
102+
totaltime += steptime
100103
val nameSafe = name.replace(" ", "_")
101104
writeUtf8(
102105
"$count $nameSafe ${bdd.realSize} $fsize %.3f %.3f ${bdd.cacheHits} ${bdd.cacheMisses}\n"
103-
.format(steptime.seconds, totaltime)
106+
.format(
107+
steptime.toDouble(DurationUnit.SECONDS),
108+
totaltime.toDouble(DurationUnit.SECONDS)
109+
)
104110
)
105111
return result
106112
}
@@ -356,8 +362,13 @@ fun geffe() {
356362
}
357363

358364
println("-".repeat(42))
359-
val totalTime = PerformanceCounter.reference - timeStart
360-
println("Done in %.2fs (totaltime=%.2f)".format(totalTime.seconds, totaltime))
365+
val totalTime = timeStart.elapsedNow()
366+
println(
367+
"Done in %.2fs (totaltime=%.2f)".format(
368+
totalTime.toDouble(DurationUnit.SECONDS),
369+
totaltime.toDouble(DurationUnit.SECONDS)
370+
)
371+
)
361372
}
362373

363374
fun main() {

0 commit comments

Comments
 (0)