Skip to content
Closed
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
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
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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
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 "9.1.1" apply false
}

Expand Down
58 changes: 29 additions & 29 deletions cli/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.jlleitschuh.gradle.ktlint")
}

kotlin {
jvmToolchain(17)
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation(project(":protogram"))
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 @@ -14,6 +14,7 @@ import com.github.ajalt.clikt.parameters.options.multiple
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.path
import com.squareup.wire.schema.Location
import com.squareup.wire.schema.ProtoType
import com.squareup.wire.schema.Schema
import com.squareup.wire.schema.SchemaLoader
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.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 4 additions & 2 deletions protogram/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
}

kotlin {
jvmToolchain(17)

jvm()
js {
browser()
Expand All @@ -14,8 +16,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 @@ -11,6 +11,7 @@ import com.squareup.wire.FieldEncoding.FIXED64
import com.squareup.wire.FieldEncoding.LENGTH_DELIMITED
import com.squareup.wire.FieldEncoding.VARINT
import com.squareup.wire.ProtoReader
import com.squareup.wire.schema.EnclosingType
import com.squareup.wire.schema.EnumType
import com.squareup.wire.schema.MessageType
import com.squareup.wire.schema.ProtoType
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
2 changes: 2 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
}

kotlin {
jvmToolchain(17)

jvm()
js {
browser()
Expand Down
2 changes: 2 additions & 0 deletions tinsel/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ plugins {
}

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
26 changes: 18 additions & 8 deletions webapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,35 +1,45 @@
plugins {
kotlin("js")
kotlin("multiplatform")
id("org.jlleitschuh.gradle.ktlint")
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
}