introduce custom options for messages in proto files
This commit is contained in:
@@ -53,10 +53,15 @@ public val PROTO_PATHS: List<ProtoPath> = listOf(
|
||||
ProtoPath("core/descriptor.loader.java/src/jvm_descriptors.proto")
|
||||
)
|
||||
|
||||
private val EXT_OPTIONS_PROTO_PATH = ProtoPath("core/deserialization/src/ext_options.proto")
|
||||
private val PROTOBUF_PROTO_PATHS = listOf("./", "core/deserialization/src")
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
try {
|
||||
checkVersion()
|
||||
|
||||
modifyAndExecProtoc(EXT_OPTIONS_PROTO_PATH)
|
||||
|
||||
for (protoPath in PROTO_PATHS) {
|
||||
execProtoc(protoPath.file, protoPath.outPath)
|
||||
modifyAndExecProtoc(protoPath)
|
||||
@@ -85,7 +90,7 @@ fun checkVersion() {
|
||||
}
|
||||
|
||||
fun execProtoc(protoPath: String, outPath: String) {
|
||||
val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, protoPath, "--java_out=$outPath"), null)
|
||||
val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, protoPath, "--java_out=$outPath") + PROTOBUF_PROTO_PATHS.map { "--proto_path=$it" }, null)
|
||||
print(processOutput.getStdout())
|
||||
if (processOutput.getStderr().isNotEmpty()) {
|
||||
throw AssertionError(processOutput.getStderr())
|
||||
@@ -101,9 +106,15 @@ fun modifyAndExecProtoc(protoPath: ProtoPath) {
|
||||
}
|
||||
|
||||
fun modifyForDebug(protoPath: ProtoPath): String {
|
||||
return File(protoPath.file).readText()
|
||||
var text = File(protoPath.file).readText()
|
||||
.replace("option java_outer_classname = \"${protoPath.className}\"",
|
||||
"option java_outer_classname = \"${protoPath.debugClassName}\"") // give different name for class
|
||||
.replace("option optimize_for = LITE_RUNTIME;", "") // using default instead
|
||||
.replace(".proto\"", ".debug.proto\"") // for "import" statement in proto
|
||||
//.replace(".proto\"", ".debug.proto\"") // for "import" statement in proto
|
||||
(listOf(EXT_OPTIONS_PROTO_PATH) + PROTO_PATHS).forEach {
|
||||
val file = it.file
|
||||
val newFile = file.replace(".proto", ".debug.proto")
|
||||
text = text.replace(file, newFile)
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user