Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ jobs:
run: ./gradlew --no-daemon build
- name: Archive protogram test results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: protogram-report
path: protogram/build/reports/tests/allTests
- name: Archive tinsel test results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: tinsel-report
path: tinsel/build/reports/tests/allTests
- name: Archive test test results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: test-report
path: test/build/reports/tests/allTests
- name: Archive cli test results
if: always()
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v4
with:
name: cli-report
path: cli/build/reports/tests/test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
.idea
*.iml

.kotlin
kotlin-js-store

# Gradle
.gradle
gradlew.bat
Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import org.jetbrains.kotlin.gradle.plugin.kotlinToolingVersion

plugins {
base
kotlin("multiplatform") version "1.6.21" apply false
kotlin("jvm") version "1.6.21" apply false
kotlin("js") version "1.6.21" apply false
id("org.jlleitschuh.gradle.ktlint") version "9.1.1" apply false
kotlin("multiplatform") version "2.2.20" apply false
kotlin("jvm") version "2.2.20" apply false
kotlin("js") version "2.2.20" apply false
id("org.jlleitschuh.gradle.ktlint") version "12.1.0" apply false
}

subprojects {
Expand Down
60 changes: 30 additions & 30 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
id("org.jlleitschuh.gradle.ktlint") apply false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • apply ktlint everywhere. It's a pain right now and don't wanna configure it

}

kotlin {
jvmToolchain(17)
}

dependencies {
Expand All @@ -14,41 +16,39 @@ dependencies {
testImplementation("com.google.jimfs", "jimfs", "1.1")
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

val fatJar = task("fatJar", type = Jar::class) {
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
with(tasks.jar.get() as CopySpec)
tasks {
val fatJar = register<Jar>("fatJar", {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
with(jar.get() as CopySpec)

archiveClassifier.set("fat")
archiveClassifier.set("fat")

manifest {
attributes["Main-Class"] = "com.mattprecious.protogram.Main"
}
}
manifest {
attributes["Main-Class"] = "com.mattprecious.protogram.Main"
}
})

val binaryJar = task("binaryJar") {
val binaryDir = File(buildDir, "bin")
val binaryFile = File(binaryDir, "protogram")
val binaryJar = register("binaryJar", {
val binaryDir = layout.buildDirectory.dir("bin").get().asFile
val binaryFile = binaryDir.resolve("protogram")

doLast {
val fatJarFile = fatJar.archiveFile.get().asFile
doLast {
val fatJarFile = fatJar.get().archiveFile.get().asFile

binaryFile.parentFile.mkdirs()
binaryFile.writeText("#!/bin/sh\n\nexec java -jar \$0 \"\$@\"\n\n")
binaryFile.appendBytes(fatJarFile.readBytes())
binaryFile.parentFile.mkdirs()
binaryFile.writeText("#!/bin/sh\n\nexec java -jar \$0 \"\$@\"\n\n")
binaryFile.appendBytes(fatJarFile.readBytes())

binaryFile.setExecutable(true)
}
}
binaryFile.setExecutable(true)
}
})

tasks {
"assemble" {
named("assemble") {
dependsOn(binaryJar)
}

binaryJar.dependsOn(fatJar)
binaryJar {
dependsOn(fatJar)
}
}
14 changes: 7 additions & 7 deletions cli/src/main/kotlin/com/mattprecious/protogram/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.ajalt.clikt.core.PrintHelpMessage
import com.github.ajalt.clikt.core.UsageError
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.convert
import com.squareup.wire.schema.Location
import com.github.ajalt.clikt.parameters.arguments.optional
import com.github.ajalt.clikt.parameters.groups.OptionGroup
import com.github.ajalt.clikt.parameters.groups.cooccurring
Expand All @@ -22,6 +23,7 @@ import java.io.PrintStream
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import okio.ByteString.Companion.decodeHex
import okio.FileSystem.Companion.asOkioFileSystem
import okio.buffer
import okio.source

Expand All @@ -30,7 +32,7 @@ fun main(vararg args: String) {
}

internal class ProtogramCli(
fs: FileSystem,
private val fs: FileSystem,
private val stdin: InputStream,
private val stdout: PrintStream,
private val stderr: PrintStream
Expand Down Expand Up @@ -63,12 +65,10 @@ internal class ProtogramCli(
if (protoOptions.dirs.isEmpty()) {
throw UsageError("At least one --source is required with --type")
}
val schemaLoader = SchemaLoader()
protoOptions.dirs.forEach {
schemaLoader.addSource(it)
}
schema = schemaLoader.load()
type = schema!!.getType(protoOptions.type)?.type
val schemaLoader = SchemaLoader(fs.asOkioFileSystem())
schemaLoader.initRoots(protoOptions.dirs.map { Location.get(it.toString()) })
schema = schemaLoader.loadSchema()
type = schema.getType(protoOptions.type)?.type
}

stdout.print(printProto(decodeBytes, schema, type))
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 9 additions & 3 deletions protogram/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
plugins {
kotlin("multiplatform")
id("org.jlleitschuh.gradle.ktlint")
id("org.jlleitschuh.gradle.ktlint") apply false
}

repositories {
mavenCentral()
}

kotlin {
jvmToolchain(17)

jvm()
js {
browser()
Expand All @@ -14,8 +20,8 @@ kotlin {
dependencies {
api(kotlin("stdlib-common"))
implementation(project(":tinsel"))
api("com.squareup.okio:okio-multiplatform:2.4.2")
api("com.squareup.wire:wire-schema-multiplatform:3.1.0")
api("com.squareup.okio:okio:3.7.0")
api("com.squareup.wire:wire-schema:4.9.7")
}
}
commonTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.squareup.wire.FieldEncoding.LENGTH_DELIMITED
import com.squareup.wire.FieldEncoding.VARINT
import com.squareup.wire.ProtoReader
import com.squareup.wire.schema.EnumType
import com.squareup.wire.schema.EnclosingType
import com.squareup.wire.schema.MessageType
import com.squareup.wire.schema.ProtoType
import com.squareup.wire.schema.Schema
Expand All @@ -34,6 +35,8 @@ private fun ProtoReader.readTree(schema: Schema?, type: ProtoType?): Tree {
var fieldName = tag.toString()
if (schema != null && type != null) {
when (val schemaType = schema.getType(type)) {
null -> {}
is EnclosingType -> {}
is MessageType -> {
val field = schemaType.field(tag)
if (field != null) {
Expand Down
4 changes: 3 additions & 1 deletion test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
plugins {
kotlin("multiplatform")
id("org.jlleitschuh.gradle.ktlint")
id("org.jlleitschuh.gradle.ktlint") apply false
}

kotlin {
jvmToolchain(17)

jvm()
js {
browser()
Expand Down
4 changes: 3 additions & 1 deletion tinsel/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
plugins {
kotlin("multiplatform")
id("org.jlleitschuh.gradle.ktlint")
id("org.jlleitschuh.gradle.ktlint") apply false
}

kotlin {
jvmToolchain(17)

jvm()
js {
browser()
Expand Down
2 changes: 1 addition & 1 deletion webapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Currently the website deploys automatically from the `master` branch.
Development
-----------

Run `./gradlew :webapp:run --continuous` and a local webserver and browser will be opened.
Run `./gradlew :webapp:jsBrowserDevelopmentRun --continuous` and a local webserver will be opened.
Code changes will be automatically picked up and compiled. The browser will also refresh
automatically.

Expand Down
29 changes: 20 additions & 9 deletions webapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
plugins {
kotlin("js")
id("org.jlleitschuh.gradle.ktlint")
kotlin("multiplatform")
id("org.jlleitschuh.gradle.ktlint") apply false
distribution
}

kotlin {
js {
browser()
browser {
webpackTask {
mainOutputFileName = "webapp.js"
}
}
binaries.executable()
}

sourceSets["main"].dependencies {
implementation(project(":protogram"))
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.3.3")
sourceSets {
val jsMain by getting {
dependencies {
implementation(project(":protogram"))
implementation(kotlin("stdlib-js"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-js:1.7.3")
}
}
}
}

distributions {
main {
contents {
from("src/main/resources")
from("$buildDir/distributions/webapp.js")
from("${layout.buildDirectory.get()}/distributions/webapp.js")
into("/")
}
}
}

listOf("distZip", "installDist").forEach {
tasks.named(it).configure {
dependsOn(tasks.getByName("browserWebpack"))
dependsOn(tasks.named("jsBrowserProductionWebpack"))
}
}

tasks.named("distTar").configure {
enabled = false
}