Skip to content

Commit aea1e14

Browse files
authored
Merge pull request #796 from Kotlin/buildConfig
Build config and Debug mode
2 parents 459f885 + 48b332b commit aea1e14

File tree

7 files changed

+60
-2
lines changed

7 files changed

+60
-2
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ so do familiarize yourself with the following guidelines.
5252

5353
## PR workflow
5454

55-
0. The contributor builds the library locally and runs all unit tests via the Gradle task `dataframe:test`
56-
(see the ["Building"](#building) chapter).
55+
0. The contributor builds the library locally and runs all unit tests via the Gradle task
56+
`dataframe:test -Pkotlin.dataframe.debug=true` (see the ["Building"](#building) chapter).
5757
1. The contributor submits the PR if the local build is successful and the tests are green.
5858
2. The reviewer puts their name in the "Reviewers" section of the proposed PR at the start of the review process.
5959
3. The reviewer leaves comments or marks the PR with the abbreviation "LGTM" (Looks good to me).
@@ -103,6 +103,8 @@ This library is built with Gradle.
103103
* Run `./gradlew build` to build. It also runs all the tests and checks the linter.
104104
* Run `./gradlew <module>:test` to test the module you are looking at to speed
105105
things up during development.
106+
* Make sure to pass the extra parameter `-Pkotlin.dataframe.debug=true` to enable debug mode. This flag will
107+
make sure some extra checks are run, which are important but too heavy for production.
106108

107109
You can import this project into IDEA, but you have to delegate the build actions
108110
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)

build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
2+
import com.github.gmazzo.buildconfig.BuildConfigExtension
23
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
34
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
45
import org.jetbrains.kotlinx.dataframe.AnyFrame
@@ -25,6 +26,7 @@ plugins {
2526
alias(docProcessor) apply false
2627
alias(simpleGit) apply false
2728
alias(dependencyVersions)
29+
alias(buildconfig) apply false
2830

2931
// dependence on our own plugin
3032
alias(dataframe) apply false
@@ -154,6 +156,18 @@ allprojects {
154156

155157
// set the java toolchain version to 11 for all subprojects for CI stability
156158
extensions.findByType<KotlinJvmProjectExtension>()?.jvmToolchain(11)
159+
160+
// Attempts to configure buildConfig for each sub-project that uses it
161+
try {
162+
configure<BuildConfigExtension> {
163+
packageName = "org.jetbrains.kotlinx.dataframe"
164+
className = "BuildConfig"
165+
buildConfigField("VERSION", "${project.version}")
166+
buildConfigField("DEBUG", findProperty("kotlin.dataframe.debug")?.toString()?.toBoolean() ?: false)
167+
}
168+
} catch (_: UnknownDomainObjectException) {
169+
logger.warn("Could not set buildConfig on :${this.name}")
170+
}
157171
}
158172
}
159173

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ plugins {
1919
alias(ktlint)
2020
alias(docProcessor)
2121
alias(simpleGit)
22+
alias(buildconfig)
2223

2324
// dependence on our own plugin
2425
alias(dataframe)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package org.jetbrains.kotlinx.dataframe.impl.columns
22

3+
import org.jetbrains.kotlinx.dataframe.BuildConfig
34
import org.jetbrains.kotlinx.dataframe.DataColumn
45
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
6+
import org.jetbrains.kotlinx.dataframe.impl.isArray
7+
import org.jetbrains.kotlinx.dataframe.impl.isPrimitiveArray
8+
import kotlin.reflect.KClass
59
import kotlin.reflect.KType
10+
import kotlin.reflect.full.isSubclassOf
611

712
internal abstract class DataColumnImpl<T>(
813
protected val values: List<T>,
@@ -12,6 +17,31 @@ internal abstract class DataColumnImpl<T>(
1217
) : DataColumn<T>,
1318
DataColumnInternal<T> {
1419

20+
private infix fun <T> T?.matches(type: KType) =
21+
when {
22+
this == null -> type.isMarkedNullable
23+
24+
this.isPrimitiveArray ->
25+
type.isPrimitiveArray &&
26+
this!!::class.qualifiedName == type.classifier?.let { (it as KClass<*>).qualifiedName }
27+
28+
this.isArray -> type.isArray
29+
30+
// cannot check the precise type of array
31+
else -> this!!::class.isSubclassOf(type.classifier as KClass<*>)
32+
}
33+
34+
init {
35+
// Check for [Issue #713](https://github.com/Kotlin/dataframe/issues/713).
36+
// This only runs with `kotlin.dataframe.debug=true` in gradle.properties.
37+
if (BuildConfig.DEBUG) {
38+
require(values.all { it matches type }) {
39+
val types = values.map { if (it == null) "Nothing?" else it!!::class.simpleName }.distinct()
40+
"Values of column '$name' have types '$types' which are not compatible given with column type '$type'"
41+
}
42+
}
43+
}
44+
1545
protected val distinct = distinct ?: lazy { values.toSet() }
1646

1747
override fun name() = name
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.jetbrains.kotlinx.dataframe.jupyter
22

3+
import org.jetbrains.kotlinx.dataframe.BuildConfig
34
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
45

56
public class JupyterConfiguration {
67
public val display: DisplayConfiguration = DisplayConfiguration()
78

9+
/** Version of the library. */
10+
public val version: String = BuildConfig.VERSION
11+
812
/** DSL accessor. */
913
public operator fun invoke(block: JupyterConfiguration.() -> Unit): JupyterConfiguration = apply(block)
1014
}

gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ org.gradle.jvmargs=-Xmx4G
1111
# This makes it mandatory to explicitly apply your own version of the
1212
# KSP plugin in the modules that use it.
1313
kotlin.dataframe.add.ksp=false
14+
15+
# Enables debug mode for dataframe.
16+
# This can make certain tests run that should not be run in production.
17+
# It can also be turned on from the command line with `-Pkotlin.dataframe.debug=true`
18+
kotlin.dataframe.debug=false

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ android-gradle-api = "7.3.1" # Can't be updated to 7.4.0+ due to Java 8 compatib
5757
ktor-server-netty = "2.3.8"
5858
kotlin-compile-testing = "1.6.0"
5959
duckdb = "0.10.0"
60+
buildconfig = "5.4.0"
6061

6162
[libraries]
6263
ksp-gradle = { group = "com.google.devtools.ksp", name = "symbol-processing-gradle-plugin", version.ref = "ksp" }
@@ -149,3 +150,4 @@ kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }
149150
dependencyVersions = { id = "com.github.ben-manes.versions", version.ref = "dependencyVersions" }
150151
plugin-publish = { id = "com.gradle.plugin-publish", version.ref = "plugin-publish" }
151152
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
153+
buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" }

0 commit comments

Comments
 (0)