Skip to content

Commit

Permalink
Reimplement collectScreenshots
Browse files Browse the repository at this point in the history
  • Loading branch information
edwinRNDR committed Aug 31, 2021
1 parent 9a2f10f commit 46dfc06
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 176 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/generate-screenshots.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Generate screenshots
on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: 16
- uses: openrndr/setup-opengl@v1.1
- name: Test glxinfo
run: |
echo $LD_LIBRARY_PATH
export GALLIUM_DRIVER=swr
xvfb-run glxinfo
- uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Collect screenshots
run: xvfb-run ./gradlew collectScreenshots
- name: Build main readme
run: xvfb-run ./gradlew buildMainReadme
- name: Prepare media branch
run: |
git config --global user.email "actions@openrndr.org"
git config --global user.name "OPENRNDR Actions"
git reset HEAD -- .
(git add README.md && git commit -m "add auto-generated README" && git push origin master) || true
(git add [a-z-]*/README.md && git commit -m "add demos to README.md" && git push origin master) || true
git checkout --orphan media
git reset HEAD -- .
git add [a-z-]*/images/*.png
git commit -m "add auto-generated media"
git push -f origin media
142 changes: 6 additions & 136 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ buildscript {

plugins {
// remember to update all the versions here when upgrading kotlin version
id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false
id 'org.jetbrains.kotlin.multiplatform' version '1.5.30' apply false
id 'org.jetbrains.kotlin.jvm' apply false
id 'org.jetbrains.kotlin.multiplatform' apply false
id 'org.jetbrains.kotlin.plugin.serialization' version '1.5.30' apply false
}

Expand All @@ -32,7 +32,6 @@ def multiplatformModules = [
"orx-shader-phrases",
"orx-shapes",
"orx-quadtree",

]

project.ext {
Expand Down Expand Up @@ -101,62 +100,6 @@ dokka {
sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") })
}

//allprojects {
// apply plugin: 'idea'
// apply plugin: 'java'
// apply plugin: 'kotlin'
// apply plugin: 'nebula.release'
//
// apply plugin: "com.github.ben-manes.versions"
//
// group 'org.openrndr.extra'
//
// repositories {
// if (openrndrUseSnapshot) {
// mavenLocal()
// }
//
// mavenCentral()
// jcenter()
// maven {
// url "https://dl.bintray.com/spekframework/spek"
// }
// }
//
// dependencies {
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
// implementation 'io.github.microutils:kotlin-logging-jvm:2.0.6'
// implementation "org.openrndr:openrndr-application:$openrndrVersion"
// implementation "org.openrndr:openrndr-shape:$openrndrVersion"
// implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.4.3'
// testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spekVersion"
// testImplementation "org.amshove.kluent:kluent:1.65"
// testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
// testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spekVersion"
// testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
// }
//
// java {
// sourceCompatibility = JavaVersion.VERSION_1_8
// targetCompatibility = JavaVersion.VERSION_1_8
// }
// javadoc {
// options.addBooleanOption 'Xdoclint:none', true
// }
//
// test {
// useJUnitPlatform {
// includeEngines 'spek2'
// }
// }
// tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
// kotlinOptions {
// jvmTarget = "1.8"
// }
// }
//}

task buildMainReadme {
doFirst {
def subProjects = project.subprojects
Expand Down Expand Up @@ -238,80 +181,9 @@ task buildMainReadme {
}
}

task collectScreenshots {
doFirst {
def demoProjects = project.subprojects.findAll { it.sourceSets.hasProperty("demo") }
for (sub in demoProjects) {
if (sub.name == "openrndr-demos")
continue
if (sub.name == "orx-rabbit-control")
continue
if (sub.name == "orx-runway")
continue
if (sub.name == "orx-chataigne")
continue
if (sub.name == "orx-video-profiles")
continue
if (sub.name == "orx-realsense2")
continue
def set = sub.sourceSets.demo
def ucl = new URLClassLoader(set.runtimeClasspath.collect { it.toURI().toURL() } as URL[])

def runDemos = []

for (x in set.output) {
if (x.exists()) {
for (y in x.listFiles()) {
def name = y.name
if (!name.contains('$') && name.contains(".class")) {
def klassName = y.name.replace(".class", "")
def klass = ucl.loadClass(klassName)
try {
def mainMethod = klass.getMethod("main")
println "Collecting screenshot for ${klassName}"
javaexec {
classpath += set.runtimeClasspath
classpath += set.compileClasspath
def className = y.name.replace(".class", "")
main = className
jvmArgs += "-DtakeScreenshot=true"
jvmArgs += "-DscreenshotPath=${sub.name}/images/${className}.png"
jvmArgs += "-Dorg.openrndr.exceptions=JVM"
}
runDemos.add(klassName)
} catch (e) {
e.printStackTrace()
}
}
}
}
}
runDemos = runDemos.sort()
def readme = sub.file("README.md")
if (readme.exists()) {
def lines = readme.readLines()
def screenshotsLine = lines.findIndexOf { it == "<!-- __demos__ -->" }
if (screenshotsLine != -1) {
lines = lines.subList(0, screenshotsLine)
}
lines.add("<!-- __demos__ -->")
lines.add("## Demos")
for (demo in runDemos) {
lines.add("### ${demo[0..-3]}")
lines.add("[source code](src/demo/kotlin/${demo[0..-3]}.kt)")
lines.add("")
lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/${sub.name}/images/${demo}.png)")
lines.add("")
}
readme.delete()
readme.write(lines.join("\n"))
}
}
}
}

configure(allprojects.findAll { !multiplatformModules.contains(it.name) }) {
apply plugin: 'idea'
// apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
Expand Down Expand Up @@ -360,8 +232,6 @@ configure(allprojects.findAll { !multiplatformModules.contains(it.name) }) {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi"]
}


}

configure(allprojects.findAll { it.name != "openrndr-demos" }) {
Expand All @@ -370,6 +240,6 @@ configure(allprojects.findAll { it.name != "openrndr-demos" }) {
}


collectScreenshots.dependsOn {
project.subprojects.findAll { it.sourceSets.hasProperty("demo") }.collect { it.tasks.demoClasses }
}
//collectScreenshots.dependsOn {
// project.subprojects.findAll { it.sourceSets.hasProperty("demo") }.collect { it.tasks.demoClasses }
//}
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ plugins {

repositories {
mavenCentral()
gradlePluginPortal()
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
}
90 changes: 90 additions & 0 deletions buildSrc/src/main/kotlin/orx.collect-screenshots.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
import java.net.URLClassLoader

abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
@get:Incremental
@get:PathSensitive(PathSensitivity.NAME_ONLY)
@get:InputDirectory
abstract val inputDir: DirectoryProperty

@get:Input
abstract val runtimeDependencies: Property<FileCollection>

@get:OutputDirectory
abstract val outputDir: DirectoryProperty

@get:Input
abstract val ignore: ListProperty<String>


init {
ignore.set(emptyList())
}
@TaskAction
fun execute(inputChanges: InputChanges) {
inputChanges.getFileChanges(inputDir).forEach { change ->
if (change.fileType == FileType.DIRECTORY) return@forEach
if (change.file.extension == "class" && !(change.file.name.contains("$"))) {
val klassName = change.file.nameWithoutExtension
if (klassName.dropLast(2) in ignore.get())
return@forEach

val cp = (runtimeDependencies.get().map { it.toURI().toURL() } + inputDir.get().asFile.toURI().toURL())
.toTypedArray()

val ucl = URLClassLoader(cp)




val klass = ucl.loadClass(klassName)
println("Collecting screenshot for ${klassName} ${klass}")

val mainMethod = klass.getMethod("main")
println(mainMethod)
project.javaexec {
this.classpath += project.files(inputDir.get().asFile)
this.classpath += runtimeDependencies.get()
this.mainClass.set(klassName)
this.workingDir(project.rootProject.projectDir)
jvmArgs("-DtakeScreenshot=true", "-DscreenshotPath=${outputDir.get().asFile}/$klassName.png")
}
}
}
// this is only executed if there are chances in the inputDir
val runDemos = outputDir.get().asFile.listFiles { file: File ->
file.extension == "png"
}.map { it.nameWithoutExtension }
val readme = File(project.projectDir, "README.md")
if (readme.exists()) {
var lines = readme.readLines().toMutableList()
val screenshotsLine = lines.indexOfFirst { it == "<!-- __demos__ -->" }
if (screenshotsLine != -1) {
lines = lines.subList(0, screenshotsLine)
}
lines.add("<!-- __demos__ -->")
lines.add("## Demos")
for (demo in runDemos) {
lines.add("### ${demo.dropLast(2)}")
lines.add("[source code](src/demo/kotlin/${demo.dropLast(2)}.kt)")
lines.add("")
lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/${project.name}/images/${demo}.png)")
lines.add("")
}
readme.delete()
readme.writeText(lines.joinToString("\n"))
}
}
}

object ScreenshotsHelper {
fun KotlinJvmCompilation.collectScreenshots(config: CollectScreenshotsTask.() -> Unit): CollectScreenshotsTask {
val task = this.project.tasks.register<CollectScreenshotsTask>("collectScreenshots").get()
task.outputDir.set(project.file(project.projectDir.toString() + "/images"))
task.inputDir.set(output.classesDirs.first())
task.runtimeDependencies.set(runtimeDependencyFiles)
task.config()
return task
}
}

20 changes: 10 additions & 10 deletions orx-color/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme

![DemoColorRange04Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoColorRange04Kt.png)

### DemoHSLUV01
[source code](src/demo/kotlin/DemoHSLUV01.kt)

![DemoHSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV01Kt.png)

### DemoHSLUV02
[source code](src/demo/kotlin/DemoHSLUV02.kt)

![DemoHSLUV02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV02Kt.png)

### DemoHistogram01
[source code](src/demo/kotlin/DemoHistogram01.kt)

Expand All @@ -104,6 +94,16 @@ Two color spaces are added: `ColorHSLUVa` and `ColorHPLUVa`, they are an impleme

![DemoHistogram03Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHistogram03Kt.png)

### DemoHSLUV01
[source code](src/demo/kotlin/DemoHSLUV01.kt)

![DemoHSLUV01Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV01Kt.png)

### DemoHSLUV02
[source code](src/demo/kotlin/DemoHSLUV02.kt)

![DemoHSLUV02Kt](https://raw.githubusercontent.com/openrndr/orx/media/orx-color/images/DemoHSLUV02Kt.png)

### DemoXSLUV01
[source code](src/demo/kotlin/DemoXSLUV01.kt)

Expand Down
5 changes: 3 additions & 2 deletions orx-color/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Orx_embed_shaders_gradle.EmbedShadersTask
import Orx_collect_screenshots_gradle.ScreenshotsHelper.collectScreenshots

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("orx.embed-shaders")
id("orx.collect-screenshots")
}

val kotlinxSerializationVersion: String by rootProject.extra
Expand Down Expand Up @@ -36,6 +36,7 @@ kotlin {
runtimeOnly("org.openrndr:openrndr-gl3-natives-$openrndrOS:$openrndrVersion")
implementation(compilations["main"]!!.output.allOutputs)
}
collectScreenshots { }
}
}
compilations.all {
Expand Down
Loading

0 comments on commit 46dfc06

Please sign in to comment.