api: add java proto options to avoid risk of future breakage#5764
api: add java proto options to avoid risk of future breakage#5764htuch merged 13 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
snowp
left a comment
There was a problem hiding this comment.
Thanks! Left a few comments to get you started
tools/check_format.py
Outdated
|
|
||
| def checkJavaMultipleFilesProtoOption(file_path): | ||
| for line in fileinput.FileInput(file_path): | ||
| if "option java_multiple_files = " in line: |
There was a problem hiding this comment.
Maybe check that this is set to true? Or are there cases where you wouldn't want that?
There was a problem hiding this comment.
This only checks if the developer forgot to set it. If the developer sets it to false, that is unusual, might imply that they purposely want it to be false.
tools/check_format.py
Outdated
|
|
||
| def checkJavaOuterClassnameProtoOption(file_path): | ||
| for line in fileinput.FileInput(file_path): | ||
| if "option java_outer_classname = " in line: |
There was a problem hiding this comment.
Should this be checking for the generated name? Does that matter?
There was a problem hiding this comment.
This allows purposely setting custom outer classname for some particular proto file. There's PRO and CON, but may not matter too much yet.
tools/check_format.py
Outdated
|
|
||
| def fixJavaMultipleFilesProtoOption(file_path): | ||
| for line in fileinput.FileInput(file_path): | ||
| if "option java_multiple_files = " in line: |
There was a problem hiding this comment.
Same here, should this check for true?
There was a problem hiding this comment.
Same here, allow purposely setting it to false for some particular proto file.
tools/check_format.py
Outdated
| if "option java_outer_classname = " in line: | ||
| return [] | ||
|
|
||
| to_add = "option java_outer_classname = \"" + ''.join( |
There was a problem hiding this comment.
nit: maybe split this line into two lines to make it easier to read?
tools/check_format.py
Outdated
|
|
||
|
|
||
| def checkJavaProtoOptions(file_path): | ||
| # Add 'option java_outclass_name = FooBarProto' for foo_bar.proto |
There was a problem hiding this comment.
nit: typo outclass -> outer_classname
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
htuch
left a comment
There was a problem hiding this comment.
Nice, solutions that automatically catch/fix breakages like this are the best.
| syntax = "proto3"; | ||
|
|
||
| package envoy.config.accesslog.v2; | ||
| option java_outer_classname = "FileProto"; |
There was a problem hiding this comment.
Nit: I think a blank line between package and the option block would make sense here and elsewhere.
tools/check_format.py
Outdated
| if "option java_outer_classname = " in line: | ||
| return [] | ||
|
|
||
| to_add = "option java_outer_classname = \"" \ |
There was a problem hiding this comment.
Nit: mixture of " and ` style for Python strings, please stick with the dominate convention in the file.
There was a problem hiding this comment.
I'm not sure which style dominates in the file, seems both are widely used, but I changed to use only one style in my diff.
tools/check_format.py
Outdated
| if "-" in file_name or "." in file_name or not file_name.islower(): | ||
| return ["Unable to decide java_outer_classname for proto file: %s" % file_path] | ||
|
|
||
| for line in fileinput.FileInput(file_path): |
There was a problem hiding this comment.
You don't need to iterate, just read in the file and do an in operation.
tools/check_format.py
Outdated
| + ''.join(x.title() for x in file_name.split('_')) \ | ||
| + "Proto\";\n" | ||
|
|
||
| for line in fileinput.FileInput(file_path, inplace=True): |
There was a problem hiding this comment.
Don't need to iterate, can just do a re.sub here or similar on the entire file contents.
| return [] | ||
|
|
||
|
|
||
| def fixJavaMultipleFilesProtoOption(file_path): |
There was a problem hiding this comment.
This is similar logic to the above function, can just refactor and parameterize on the string.
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
…erclass Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
This reverts commit 4b7bf26. Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
htuch
left a comment
There was a problem hiding this comment.
Thanks, looks better, a few comments.
tools/check_format.py
Outdated
| f.seek(0) | ||
| f.write(new_text) | ||
| f.truncate() | ||
| sys.stdout.write(new_text) |
tools/check_format.py
Outdated
| new_text = re.sub(PROTO_PACKAGE_REGEX, repl, text) | ||
| f.seek(0) | ||
| f.write(new_text) | ||
| f.truncate() |
tools/check_format.py
Outdated
| if package_name is None: | ||
| return ["Unable to find package name for proto file: %s" % file_path] | ||
| new_text = re.sub(PROTO_PACKAGE_REGEX, repl, text) | ||
| f.seek(0) |
There was a problem hiding this comment.
I think you could do this as two separate with blocks, one with mode r and the other with w. This would be conceptually cleaner.
tools/check_format.py
Outdated
| error_message = [] | ||
| with open(file_path) as f: | ||
| result = PROTO_PACKAGE_REGEX.search(f.read()) | ||
| if not result is None and len(result.groups()) == 1: |
tools/check_format.py
Outdated
| if pattern in f.read(): | ||
| return [] | ||
| return [file_path + ": " + error_message] | ||
| # return [] if pattern in f.read() else [file_path + ": " + error_message] |
tools/check_format.py
Outdated
| if "-" in file_name or "." in file_name or not file_name.islower(): | ||
| return ["Unable to decide java_outer_classname for proto file: %s" % file_path] | ||
|
|
||
| to_add = "option java_outer_classname = \"" \ |
There was a problem hiding this comment.
FWIW, I think if you make some of these strings like option java_outer_classname = \" file-level constants, it could make it easier to keep the fix/check synced.
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
…erclass Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
|
@htuch Thanks for the additional comments. PTALA. |
| if "option java_package = \"io.envoyproxy.envoy" in line: | ||
| return [] | ||
| if not substring in text: | ||
|
|
There was a problem hiding this comment.
Actually this superfluous line was suggested by check_format
$ ENVOY_DOCKER_BUILD_DIR=~/build ./ci/run_envoy_docker.sh './ci/do_ci.sh check_format'
Running Python format check...
--- /source/tools/check_format.py (original)
+++ /source/tools/check_format.py (reformatted)
@@ -157,6 +157,7 @@
text = f.read()
if not substring in text:
+
def repl(m):
return m.group(0).rstrip() + "\n\n" + to_add + "\n"
|
Please merge master to pick up #5827. |
…erclass Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com>
…roxy#5764) As discussed with @snowp in [envoyproxy/java-control-plane#87 (comment)](envoyproxy/java-control-plane#87 (comment)) and [envoyproxy/java-control-plane#87 (comment)](envoyproxy/java-control-plane#87 (comment)), adding these options will avoid the risk of having API breaking changes on the generated java code as the proto files evolve. Risk Level_: Medium Note that e.g. [envoyproxy/java-control-plane](https://github.com/envoyproxy/java-control-plane) will have to do a refactoring when they sync the proto files next time. Signed-off-by: Penn (Dapeng) Zhang <zdapeng@google.com> Signed-off-by: Fred Douglas <fredlas@google.com>
Description: As discussed with @snowp in envoyproxy/java-control-plane#87 (comment) and envoyproxy/java-control-plane#87 (comment), adding these options will avoid the risk of having API breaking changes on the generated java code as the proto files evolve.
Risk Level: Medium
Note that e.g. envoyproxy/java-control-plane will have to do a refactoring when they sync the proto files next time.
Testing:
Docs Changes:
Release Notes:
[Optional Fixes #Issue] envoyproxy/java-control-plane#87
[Optional Deprecated:]