Skip to content

Commit

Permalink
codecov + gradle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dogacel committed Oct 7, 2023
1 parent 27d418e commit 4e1f48f
Show file tree
Hide file tree
Showing 28 changed files with 229 additions and 329 deletions.
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{kt,kts}]
ktlint_no-wildcard-imports = disabled
5 changes: 5 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ jobs:
- uses: gradle/gradle-build-action@v2
with:
arguments: build --scan

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Generate kotlin data classes from `protobuf` files that supports _Kotlin Native_
deserialized to protobuf using [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization).

> [!NOTE]
> Full documentation for the project including setup instruction can be found
> at [GitHub Pages](https://dogacel.github.io/kotlinx-protobuf-gen).
> Setup instructions and detailed documentation can be found
> at [Setup and Documentation](https://dogacel.github.io/kotlinx-protobuf-gen).
![Demonstrate Code](./docs/src/doc/docs/assets/demonstrate_code.png)

Expand All @@ -23,16 +23,13 @@ deserialized to protobuf using [kotlinx.serialization](https://github.com/Kotlin

## Roadmap

I will probably move those stuff to issues and projects later on. For now, here is a list of stuff that I have
been thinking about,

Our goal is to eventually support all features of Protobuf in Kotlin without depending on the Java library. Here
is a list of features we are working on that are required to release first stable version.
The goal is to eventually support all features of Protobuf in Kotlin without depending on the Java library. Here
is a list of features we are working on that are required to release first stable version:

- [ ] Proper serialization / deserialization of all types. Check "Known Issues" section below to see all major
issues.
- [ ] Make data classes with `ByteArray` implement equals and hashcode correctly.
- [ ] Run full conformance tests on the generated code.
- [ ] Run full conformance tests on the generated code.]
- [ ] Support Protobuf JSON format.

And here is a list of features that we are planning to work on after the first stable release.

Expand All @@ -42,9 +39,9 @@ And here is a list of features that we are planning to work on after the first s
- More WKT additions will be added.
- [ ] Support various options such as `deprecated`, `default`, `json_name`.
- [ ] Auto-generated comments from `.proto` files in the generated code.
- [ ] Support Protobuf JSON format by default.
- [x] gRPC support.
- Stub generation is completed but it does not include any functionality to call or receive gRPC yet.
- It is tricky to support gRPC without depending on the Java library.
- [ ] Plugin and more option support for customizing the generated code. (Such as non-enforced nullability to
gimmick proto2 required fields based on certain rules)

Expand All @@ -61,8 +58,8 @@ Focusing on core functionality, here is a list of known major issues:
- [ ] Generated `repeated` fields with `fixedXX`, `sfixedXX` and `uintXX` types can't be serialized.
- [ ] Generated `repeated` fields with `sintXX` deserializes incorrectly.
- [ ] Generated `map` fields with `fixedXX` and `sfixedXX` keys can't be serialized.
- [ ] Generated `enum` fields with negative values can't be serialized / deserialized.
- PR opened in `kotlinx.serialization`: https://github.com/Kotlin/kotlinx.serialization/pull/2400
- [x] Generated `enum` fields with negative values can't be serialized / deserialized.
- [ ] Make data classes with `ByteArray` implement equals and hashcode correctly.

## Contribution

Expand Down
14 changes: 1 addition & 13 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ plugins {
id("org.jetbrains.kotlin.jvm")
kotlin("plugin.serialization")
id("com.google.protobuf")
id("org.jlleitschuh.gradle.ktlint")
id("org.jetbrains.kotlinx.kover")
application
`maven-publish`
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.kover")
}

repositories {
Expand Down Expand Up @@ -40,17 +39,6 @@ java {
}
}

ktlint {
ignoreFailures.set(true)
filter {
exclude { entry ->
val condition =
entry.file.toString().contains("generated") || entry.file.toString().contains("testgen")
condition
}
}
}

application {
// Define the main class for the application.
mainClass.set("dogacel.kotlinx.protobuf.gen.AppKt")
Expand Down
26 changes: 13 additions & 13 deletions app/src/main/kotlin/dogacel/kotlinx/protobuf/gen/CodeGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CodeGenerator {
*/
constructor(
request: PluginProtos.CodeGeneratorRequest,
options: CodeGeneratorOptions = CodeGeneratorOptions(),
options: CodeGeneratorOptions = CodeGeneratorOptions()
) {
this.options = options
// https://protobuf.dev/reference/java/api-docs/com/google/protobuf/compiler/PluginProtos.CodeGeneratorRequest
Expand All @@ -48,7 +48,7 @@ class CodeGenerator {
val files = mutableMapOf<String, Descriptors.FileDescriptor>()
filesInOrder = request.protoFileList.map { file ->
files.computeIfAbsent(
file.name,
file.name
) {
val deps = file.dependencyList.map { dep ->
files[dep] ?: throw IllegalStateException("Dependency $dep not found for file ${file.name}")
Expand All @@ -67,7 +67,7 @@ class CodeGenerator {
*/
constructor(
vararg fileDescriptors: Descriptors.FileDescriptor,
options: CodeGeneratorOptions = CodeGeneratorOptions(),
options: CodeGeneratorOptions = CodeGeneratorOptions()
) {
this.options = options

Expand Down Expand Up @@ -116,8 +116,8 @@ class CodeGenerator {
}

/**
* Whether to generate a class for the given descriptor or not. Currently we do not create classes for
* well-known types.
* Whether to generate a class for the given descriptor or not. Currently, we do not create classes for
* well-known types. They are imported from "io.github.dogacel:kotlinx-protobuf-runtime-common" library.
*/
fun shouldGenerateClass(descriptor: Descriptors.Descriptor): Boolean {
return options.wellKnownTypes.getFor(descriptor) == null
Expand Down Expand Up @@ -234,7 +234,7 @@ class CodeGenerator {
typeSpec.addProperty(
PropertySpec.builder(fieldName, type)
.initializer(fieldName)
.build(),
.build()
)
}

Expand Down Expand Up @@ -275,7 +275,7 @@ class CodeGenerator {
valueDescriptor.name,
TypeSpec.anonymousClassBuilder()
.addAnnotations(Annotations.annotationsOf(valueDescriptor))
.build(),
.build()
)
}

Expand All @@ -294,7 +294,7 @@ class CodeGenerator {
*/
private fun generateSingleService(
serviceDescriptor: Descriptors.ServiceDescriptor,
isGrpcCompatible: Boolean,
isGrpcCompatible: Boolean
): TypeSpec.Builder {
val typeSpec = TypeSpec
.classBuilder(serviceDescriptor.name)
Expand Down Expand Up @@ -344,11 +344,11 @@ class CodeGenerator {
private fun getEnumLink(
enumDescriptor: Descriptors.EnumDescriptor,
packageName: String,
simpleNames: List<String>,
simpleNames: List<String>
): Link {
return Link(
enumDescriptor,
ClassName(packageName, simpleNames + enumDescriptor.name),
ClassName(packageName, simpleNames + enumDescriptor.name)
)
}

Expand All @@ -361,7 +361,7 @@ class CodeGenerator {
private fun getAllLinks(
descriptor: Descriptors.Descriptor,
packageName: String,
simpleNames: List<String>,
simpleNames: List<String>
): List<Link> {
val wellKnownType = options.wellKnownTypes.getFor(descriptor)

Expand All @@ -379,7 +379,7 @@ class CodeGenerator {

val self = Link(
descriptor,
ClassName(packageName, simpleNames + descriptor.name),
ClassName(packageName, simpleNames + descriptor.name)
)
return (messages + enums + self)
}
Expand All @@ -391,7 +391,7 @@ class CodeGenerator {
*/
private fun getAllLinks(
fileDescriptor: Descriptors.FileDescriptor,
packagePrefix: String = "",
packagePrefix: String = ""
): List<Link> {
val publicDependencies = fileDescriptor.publicDependencies.flatMap {
getAllLinks(it, packagePrefix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class CodeGeneratorOptions(
val generateServices: Boolean = true,
val generateGrpcServices: Boolean = true,
val generateGrpcMethodsSuspend: Boolean = true,
val wellKnownTypes: WellKnownTypes = NoWellKnownTypes,
val wellKnownTypes: WellKnownTypes = NoWellKnownTypes
) {
companion object {
fun parse(parameter: String): CodeGeneratorOptions {
Expand All @@ -41,7 +41,7 @@ data class CodeGeneratorOptions(
generateGrpcMethodsSuspend = flags.contains("disable_grpc_methods_suspend").not(),
wellKnownTypes = flags.contains("use_well_known_types").let {
if (it) DefaultWellKnownTypes else NoWellKnownTypes
},
}
)
}
}
Expand Down
Loading

0 comments on commit 4e1f48f

Please sign in to comment.