Skip to content

Commit 48e67b3

Browse files
committed
Replace Build.kt autogen with PaperVisionBuildInfo.json autogen
1 parent 7df0e72 commit 48e67b3

20 files changed

Lines changed: 168 additions & 125 deletions

File tree

EOCVSimPlugin/src/main/plugin.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author-email = "dev@deltacv.org"
44
version = "{{version}}" # This will be replaced by Gradle using the artifact version
55
description = "Create your custom OpenCV algorithms using a user-friendly node editor, inspired by industry-leading interfaces! Quickly prototype your vision as you edit. "
66

7-
min-api-version = "4.0.0"
7+
min-api-version = "4.2.0"
88

99
super-access = true
1010
super-access-reason = "PaperVision requires your permision to fully support all features related to rendering user interaction and filesystem access."

LwjglPlatform/Standalone/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ dependencies {
1212
implementation "ch.qos.logback:logback-classic:$logback_classic_version"
1313
}
1414

15-
task(runEv, dependsOn: 'classes', type: JavaExec) {
16-
main = 'org.deltacv.papervision.platform.lwjgl.AppMain'
15+
tasks.register('runPv', JavaExec) {
16+
dependsOn 'classes'
17+
mainClass = 'org.deltacv.papervision.platform.lwjgl.AppMain'
1718
classpath = sourceSets.main.runtimeClasspath
1819

1920
if (org.gradle.internal.os.OperatingSystem.current().isMacOsX()) {

PaperVision/build.gradle

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import java.nio.file.Paths
21
import java.time.LocalDateTime
32
import java.time.format.DateTimeFormatter
43

@@ -13,15 +12,7 @@ plugins {
1312
apply from: '../build.common.gradle'
1413

1514

16-
def generatedSourcesDir = layout.buildDirectory.dir("generated/sources/buildinfo/java/main")
17-
18-
sourceSets {
19-
main {
20-
java {
21-
srcDirs += generatedSourcesDir
22-
}
23-
}
24-
}
15+
def generatedResourcesDir = layout.buildDirectory.dir("generated/resources/main")
2516

2617
dependencies {
2718
compileOnly "org.jetbrains.kotlin:kotlin-stdlib"
@@ -54,38 +45,39 @@ ksp {
5445
arg("codecTypeClassesMetadataClassName", "CodecTypeMetadata")
5546
}
5647

57-
tasks.register('writeBuildClass') {
58-
outputs.dir(generatedSourcesDir)
48+
tasks.register('writeBuildInfo') {
49+
outputs.dir(generatedResourcesDir)
50+
inputs.property('version', version.toString())
51+
inputs.property('standardVersion', standardVersion.toString())
5952

6053
doLast {
6154
String date = DateTimeFormatter.ofPattern("yyyy-M-d hh:mm:ss").format(LocalDateTime.now())
6255

63-
def packageStr = "org.deltacv.papervision"
64-
def packagePath = packageStr.replace('.', '/')
65-
66-
def outputDir = file("${generatedSourcesDir.get().asFile}/$packagePath")
56+
def outputDir = generatedResourcesDir.get().asFile
6757
outputDir.mkdirs()
6858

69-
def versionFile = file("${outputDir}/Build.kt")
70-
71-
versionFile.text = """package $packageStr
72-
73-
/*
74-
* Autogenerated file! Do not manually edit this file, as
75-
* it is regenerated any time the build task is run.
76-
*
77-
* Based from PhotonVision PhotonVersion generator task
78-
*/
79-
object Build {
80-
const val VERSION_STRING = "$version";
81-
const val STANDARD_VERSION_STRING = "$standardVersion";
82-
const val BUILD_DATE = "$date";
83-
const val IS_DEV = ${version.contains("dev")};
84-
}
85-
"""
59+
def buildInfoFile = file("${outputDir}/PaperVisionBuildInfo.json")
60+
61+
// Generate JSON with build information
62+
def json = """{
63+
"versionString": "$version",
64+
"standardVersionString": "$standardVersion",
65+
"buildDate": "$date",
66+
"isDev": ${version.contains("dev")}
67+
}"""
68+
69+
// Only write if content has changed (no-op on repeated builds)
70+
if (!buildInfoFile.exists() || buildInfoFile.text != json) {
71+
buildInfoFile.text = json
72+
}
8673
}
8774
}
8875

89-
tasks.matching { it.name == "compileKotlin" || it.name == "kspKotlin" }.configureEach {
90-
dependsOn writeBuildClass
91-
}
76+
tasks.named('processResources').configure {
77+
dependsOn writeBuildInfo
78+
from(generatedResourcesDir)
79+
}
80+
81+
// Remove the old source set configuration since we're not generating Kotlin anymore
82+
83+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package org.deltacv.papervision
2+
3+
import kotlinx.serialization.Serializable
4+
import kotlinx.serialization.json.Json
5+
6+
@Serializable
7+
private data class BuildInfoData(
8+
val versionString: String,
9+
val standardVersionString: String,
10+
val buildDate: String,
11+
val isDev: Boolean
12+
)
13+
14+
/**
15+
* Build information loaded from the generated PaperVisionBuildInfo.json resource file.
16+
* This object provides build-time metadata about PaperVision, including version and build date.
17+
*/
18+
object BuildInfo {
19+
private val buildInfo: BuildInfoData by lazy {
20+
// Load the JSON resource file from the classpath
21+
val resourceUrl = BuildInfo::class.java.getResource("/PaperVisionBuildInfo.json")
22+
23+
if (resourceUrl != null) {
24+
val jsonString = resourceUrl.readText(Charsets.UTF_8)
25+
Json.decodeFromString<BuildInfoData>(jsonString)
26+
} else {
27+
// Fallback if resource is not found (should not occur in normal builds)
28+
throw IllegalStateException("PaperVisionBuildInfo.json resource not found in classpath")
29+
}
30+
}
31+
32+
/**
33+
* The full version string, including dev suffix if applicable
34+
* (e.g. "1.1.0-dev" or "1.1.0")
35+
*/
36+
val VERSION_STRING: String by lazy { buildInfo.versionString }
37+
38+
/**
39+
* The semantic version without any dev suffix or build metadata
40+
* (e.g. "1.1.0")
41+
*/
42+
@Suppress("unused")
43+
val STANDARD_VERSION_STRING: String by lazy { buildInfo.standardVersionString }
44+
45+
/**
46+
* Human-readable build date/time
47+
* (formatted timestamp for all builds)
48+
*/
49+
val BUILD_DATE: String by lazy { buildInfo.buildDate }
50+
51+
/**
52+
* Whether this is a development build (contains "dev" suffix)
53+
*/
54+
val IS_DEV: Boolean by lazy { buildInfo.isDev }
55+
}
56+
57+
58+
59+

PaperVision/src/main/kotlin/org/deltacv/papervision/PaperVision.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class PaperVision(
119119
lateinit var defaultFont: Font
120120

121121
fun init() = containers.withContext {
122-
logger.info("-- Starting PaperVision v${Build.VERSION_STRING} --\n\n${IntroModalWindow.iconLogo}\n")
122+
logger.info("-- Starting PaperVision v${BuildInfo.VERSION_STRING} --\n\n${IntroModalWindow.iconLogo}\n")
123123
logger.info("Using the ${platformSetupCallback.name} platform")
124124

125125
initPlatform()

PaperVision/src/main/kotlin/org/deltacv/papervision/attribute/vision/structs/LineParametersAttribute.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.deltacv.papervision.attribute.TypedAttribute
2727
import org.deltacv.papervision.codegen.CodeGen
2828
import org.deltacv.papervision.codegen.GenValue
2929
import org.deltacv.papervision.codegen.resolve.resolved
30-
import org.deltacv.papervision.gui.font.Font
3130
import org.deltacv.papervision.gui.font.FontAwesomeIcons
3231
import org.deltacv.papervision.node.Link
3332
import org.deltacv.papervision.node.vision.overlay.LineParametersNode
@@ -71,7 +70,7 @@ class LineParametersAttribute(
7170
}
7271

7372
override fun genValue(current: CodeGen.Current) = readGenValue<GenValue.LineParameters>(
74-
current, GenValue.LineParameters.Actual(
73+
current, GenValue.LineParameters.Components(
7574
GenValue.Scalar.Components(GenValue.Double.ZERO, GenValue.Double.Actual(255.0.resolved()), GenValue.Double.ZERO, GenValue.Double.ZERO),
7675
GenValue.Int.Actual(3.resolved())
7776
)

PaperVision/src/main/kotlin/org/deltacv/papervision/codegen/GenValue.kt

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package org.deltacv.papervision.codegen
2020

2121
import org.deltacv.papervision.attribute.Attribute
2222
import org.deltacv.papervision.codegen.build.Value
23-
import org.deltacv.papervision.codegen.build.language.jvm.JvmOpenCv
2423
import org.deltacv.papervision.codegen.resolve.Resolvable
2524
import org.deltacv.papervision.codegen.resolve.from
2625
import org.deltacv.papervision.codegen.resolve.resolved
@@ -295,28 +294,19 @@ sealed class GenValue {
295294

296295
sealed class LineParameters : GenValue() {
297296
companion object {
298-
fun wrap(color: Scalar, thickness: Int): LineParameters {
297+
fun wrap(color: Scalar, thickness: Int, langHolder: CodeGen.LanguageHolder): LineParameters {
299298
return when (color) {
300-
is Scalar.Components if thickness is Int.Actual -> {
301-
Actual(color, thickness)
299+
is Scalar.Components -> {
300+
Components(color, thickness)
302301
}
303-
304-
is Scalar.Inst if thickness is Int.Runtime -> {
305-
Runtime(color, thickness)
306-
}
307-
308-
else -> {
309-
throw IllegalArgumentException(
310-
"Invalid types for LineParameters wrap(): " +
311-
"color must be either Scalar.Components or Scalar.Inst, " +
312-
"thickness must be either Int.Actual or Int.Runtime"
313-
)
302+
is Scalar.Inst -> {
303+
Runtime(color, thickness.toRuntime(langHolder))
314304
}
315305
}
316306
}
317307
}
318308

319-
data class Actual(val color: Scalar.Components, val thickness: Int.Actual) : LineParameters()
309+
data class Components(val color: Scalar.Components, val thickness: Int) : LineParameters()
320310

321311
data class Runtime(val color: Scalar.Inst, val thicknessValue: Int.Runtime) : LineParameters() {
322312
companion object {
@@ -414,7 +404,7 @@ sealed class GenValue {
414404
Runtime(value, Resolvable.Now(T::class))
415405
}
416406

417-
fun <R> switch(
407+
fun <R> match(
418408
ifActual: (Actual<E>) -> R,
419409
ifRuntime: (Runtime<E>) -> R,
420410
): R = when (this) {

PaperVision/src/main/kotlin/org/deltacv/papervision/codegen/build/language/cpython/CPythonOpenCv.kt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,42 +23,31 @@ import org.deltacv.papervision.codegen.GenValue
2323
import org.deltacv.papervision.codegen.build.ConValue
2424
import org.deltacv.papervision.codegen.build.Value
2525
import org.deltacv.papervision.codegen.language.interpreted.CPythonLanguage
26+
import org.deltacv.papervision.codegen.resolve.resolved
2627

2728
object CPythonOpenCv {
2829
object cv2 : CPythonType("cv2") {
29-
val RETR_LIST = ConValue(this, "cv2.RETR_LIST").apply {
30-
additionalImports(this)
31-
}
30+
val RETR_LIST = ConValue(this, "cv2.RETR_LIST")
3231

33-
val RETR_EXTERNAL = ConValue(this, "cv2.RETR_EXTERNAL").apply {
34-
additionalImports(this)
35-
}
32+
val RETR_EXTERNAL = ConValue(this, "cv2.RETR_EXTERNAL")
3633

37-
val CHAIN_APPROX_SIMPLE = ConValue(this, "cv2.CHAIN_APPROX_SIMPLE").apply {
38-
additionalImports(this)
39-
}
34+
val CHAIN_APPROX_SIMPLE = ConValue(this, "cv2.CHAIN_APPROX_SIMPLE")
4035

41-
val MORPH_RECT = ConValue(this, "cv2.MORPH_RECT").apply {
42-
additionalImports(this)
43-
}
36+
val MORPH_RECT = ConValue(this, "cv2.MORPH_RECT")
4437

45-
val HOUGH_GRADIENT = ConValue(this, "cv2.HOUGH_GRADIENT").apply {
46-
additionalImports(this)
47-
}
38+
val HOUGH_GRADIENT = ConValue(this, "cv2.HOUGH_GRADIENT")
4839

49-
val contourArea = ConValue(this, "cv2.contourArea").apply {
50-
additionalImports(this)
51-
}
40+
val contourArea = ConValue(this, "cv2.contourArea")
5241
}
5342

5443
val np = CPythonType("numpy", null, "np")
5544

56-
val npArray = object: CPythonType("np.ndarray") {
45+
val npArray = object : CPythonType("np.ndarray") {
5746
override var overridenImport = np
5847
}
5948

6049
fun scalarTuple(scalar: GenValue.Scalar, languageHolder: CodeGen.LanguageHolder) = languageHolder.language {
61-
scalar.switch(
50+
scalar.match(
6251
ifActual = { list ->
6352
val elements = list.elements.map { it.v }.toTypedArray()
6453
CPythonLanguage.tuple(*elements)
@@ -70,8 +59,20 @@ object CPythonOpenCv {
7059
)
7160
}
7261

62+
fun toRuntimeLineParameters(params: GenValue.LineParameters, languageHolder: CodeGen.LanguageHolder) =
63+
when (params) {
64+
is GenValue.LineParameters.Components -> {
65+
val color = scalarTuple(params.color, languageHolder)
66+
val thickness = params.thickness.toRuntime(languageHolder)
67+
68+
GenValue.LineParameters.Runtime(GenValue.Scalar.Inst(color.resolved()), thickness)
69+
}
70+
71+
is GenValue.LineParameters.Runtime -> params
72+
}
73+
7374
fun toRectTuple(rect: GenValue.Rect, languageHolder: CodeGen.LanguageHolder) = languageHolder.language {
74-
when(rect) {
75+
when (rect) {
7576
is GenValue.Rect.Components -> {
7677
val pos = rect.position.toRuntime(languageHolder)
7778
val size = rect.size.toRuntime(languageHolder)
@@ -85,19 +86,20 @@ object CPythonOpenCv {
8586
}
8687
}
8788

88-
fun toRotatedRectTuple(rect: GenValue.RotatedRect, languageHolder: CodeGen.LanguageHolder) = languageHolder.language {
89-
when(rect) {
90-
is GenValue.RotatedRect.Components -> {
91-
CPythonLanguage.tuple(
92-
CPythonLanguage.tuple(rect.x.v, rect.y.v),
93-
CPythonLanguage.tuple(rect.w.v, rect.h.v),
94-
rect.angle.v
95-
)
89+
fun toRotatedRectTuple(rect: GenValue.RotatedRect, languageHolder: CodeGen.LanguageHolder) =
90+
languageHolder.language {
91+
when (rect) {
92+
is GenValue.RotatedRect.Components -> {
93+
CPythonLanguage.tuple(
94+
CPythonLanguage.tuple(rect.x.v, rect.y.v),
95+
CPythonLanguage.tuple(rect.w.v, rect.h.v),
96+
rect.angle.v
97+
)
98+
}
99+
100+
is GenValue.RotatedRect.Inst -> rect.value.v
96101
}
97-
98-
is GenValue.RotatedRect.Inst -> rect.value.v
99102
}
100-
}
101103

102104
}
103105

PaperVision/src/main/kotlin/org/deltacv/papervision/codegen/build/language/jvm/JvmOpenCv.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ object JvmOpenCv {
120120
): GenValue.LineParameters.Runtime {
121121
return current {
122122
when (line) {
123-
is GenValue.LineParameters.Actual -> {
123+
is GenValue.LineParameters.Components -> {
124124
val color = uniqueVariable(
125125
"lineColor", Scalar.new(
126126
line.color.a.v,
@@ -130,7 +130,7 @@ object JvmOpenCv {
130130
)
131131
)
132132

133-
val thickness = uniqueVariable("lineThickness", line.thickness.value.v)
133+
val thickness = uniqueVariable("lineThickness", line.thickness.v)
134134

135135
group {
136136
public(color)

PaperVision/src/main/kotlin/org/deltacv/papervision/codegen/language/interpreted/CPythonLanguage.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ object CPythonLanguage : BaseLanguage(
274274
override fun int(value: Value) = if(value.type != IntType && value.type != LongType)
275275
callValue("int", language.IntType, value)
276276
else value
277+
277278
override fun int(value: Int) = ConValue(IntType, value.toString())
278279

279280
override fun long(value: Value) = int(value)

0 commit comments

Comments
 (0)