-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add code request generator dumper and an ability to run generator from dumped file #765
Changes from 5 commits
8983e23
83e004f
a978fff
310737e
9387e64
1c4453c
4813464
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.api.generator; | ||
|
||
import com.google.api.AnnotationsProto; | ||
import com.google.api.ClientProto; | ||
import com.google.api.FieldBehaviorProto; | ||
import com.google.api.ResourceProto; | ||
import com.google.longrunning.OperationsProto; | ||
import com.google.protobuf.ExtensionRegistry; | ||
|
||
public class ProtoRegistry { | ||
/** Register all extensions needed to process API protofiles. */ | ||
public static void registerAllExtensions(ExtensionRegistry extensionRegistry) { | ||
OperationsProto.registerAllExtensions(extensionRegistry); | ||
AnnotationsProto.registerAllExtensions(extensionRegistry); | ||
ClientProto.registerAllExtensions(extensionRegistry); | ||
ResourceProto.registerAllExtensions(extensionRegistry); | ||
FieldBehaviorProto.registerAllExtensions(extensionRegistry); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@rules_java//java:defs.bzl", "java_library", "java_plugin") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
filegroup( | ||
name = "debug_files", | ||
srcs = glob(["*.java"]), | ||
) | ||
|
||
java_library( | ||
name = "debug", | ||
srcs = [ | ||
":debug_files", | ||
], | ||
deps = [ | ||
"//src/main/java/com/google/api/generator", | ||
"//src/main/java/com/google/api/generator/engine", | ||
"//src/main/java/com/google/api/generator/engine/ast", | ||
"//src/main/java/com/google/api/generator/gapic", | ||
"//src/main/java/com/google/api/generator/gapic/model", | ||
"//src/main/java/com/google/api/generator/util", | ||
"@com_google_googleapis//google/api:api_java_proto", | ||
"@com_google_googleapis//google/longrunning:longrunning_java_proto", | ||
"@com_google_guava_guava//jar", | ||
"@com_google_protobuf//:protobuf_java", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.api.generator.debug; | ||
|
||
import com.google.api.generator.ProtoRegistry; | ||
import com.google.protobuf.ExtensionRegistry; | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; | ||
import java.io.IOException; | ||
|
||
public class CodeGeneratorRequestDumper { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @miraleung (from #767): If we're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are different things basically. The MainFromFile is literally another variation of the Main class. This, on the other hand, is a very different class, doing different thing. That is why they are named differently. And strictly speaking, this file is really very-very non-main =) I.e. this class is not really related to Main, while the other one is. Either way, if you have preferrence how to name these classes, please let me know and I'll rename them. For now, those were the best names I could come up with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. MainStandalone could be something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed |
||
public static void main(String[] args) throws IOException { | ||
ExtensionRegistry registry = ExtensionRegistry.newInstance(); | ||
ProtoRegistry.registerAllExtensions(registry); | ||
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry); | ||
|
||
CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder(); | ||
response | ||
.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE) | ||
miraleung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.addFileBuilder() | ||
.setName("desc-dump.bin") | ||
.setContentBytes(request.toByteString()); | ||
response.build().writeTo(System.out); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2021 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.api.generator.debug; | ||
|
||
import com.google.api.generator.ProtoRegistry; | ||
import com.google.api.generator.gapic.Generator; | ||
import com.google.protobuf.ExtensionRegistry; | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; | ||
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class MainStandalone { | ||
public static void main(String[] args) throws IOException { | ||
ExtensionRegistry registry = ExtensionRegistry.newInstance(); | ||
ProtoRegistry.registerAllExtensions(registry); | ||
|
||
String inputFile = args[0]; | ||
String outputFile = args[1]; | ||
|
||
try (InputStream inputStream = new FileInputStream(inputFile); | ||
OutputStream outputStream = new FileOutputStream(outputFile)) { | ||
CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(inputStream, registry); | ||
CodeGeneratorResponse response = Generator.generateGapic(request); | ||
response.writeTo(outputStream); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@miraleung (from #767): Nit: Can we add a summary comment above these two rules, which also indicate these are debugging tools?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not rules, these are java_binaries used by one of the rules only. I clarified the purpose of the binaries in the comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding the comments. Could we copy-paste these into the Java src files as well? Up to you whether to replace these comments with a pointer to the Java source, or leave these as they are.
Could we also add a usage example? Up to you whether that goes here or in the Java source comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done