Skip to content
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

formatting: reject incorrect protobuf namespaces #2969

Merged
merged 2 commits into from
Apr 3, 2018

Conversation

akonradi
Copy link
Contributor

@akonradi akonradi commented Apr 2, 2018

Add some checks to the formatting script so that protobuf-related type references use the correct namespaces. This should prevent the need for later fixups like #2963.

Risk Level: Low

Testing: checked out and ran format script on code from before #2963 and found errors as expected.

Release Notes: N/A

Add some checks to the formatting script so that protobuf-related type
references use the correct namespaces. This should prevent the need for
later fixups like envoyproxy#2963.

Signed-off-by: Alex Konradi <akonradi@google.com>
with open(file_path) as f:
text = f.read()
if '"google/protobuf' in text or "google::protobuf" in text:
printError(
"%s has unexpected direct dependency on google.protobuf, use "
"the definitions in common/protobuf/protobuf.h instead." % file_path)
return False
for error, replacement in protobuf_type_errors.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel that strongly about it, but can we do all of this on a per-line basis with all the other checks? The format script is getting pretty slow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved this to fixFileContents since the fixes can be performed automatically. I'm going to do a little digging and see if I can speed up the rest of the script.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #2974 to parallelize formatting. From profiling, it looks like the majority of the time is still spent running clang-format, with header order checking being the next most time-consuming.

Signed-off-by: Alex Konradi <akonradi@google.com>
@@ -23,6 +23,25 @@
HEADER_ORDER_PATH = os.path.join(
os.path.dirname(os.path.abspath(sys.argv[0])), "header_order.py")

PROTOBUF_TYPE_ERRORS = {
# Well-known types should be referenced from the ProtobufWkt namespace.
"Protobuf::Any": "ProtobufWkt::Any",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other alternative is to whitelist allowed proto WKT types, since these are bounded. This PR is a good improvement for now, so let's ship it, thanks!

@htuch htuch merged commit 8192f9f into envoyproxy:master Apr 3, 2018
@akonradi akonradi deleted the proto-fixup branch April 3, 2018 14:22

# Fix incorrect protobuf namespace references.
for error, replacement in PROTOBUF_TYPE_ERRORS.items():
line = line.replace(error, replacement)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the PROTOBUF_TYPE_ERRORS should also be iterated in the 'check' flow, not just the 'fix' flow This will get easier once #2921 is merged, as that introduces a line-by-line check algorithm analogous to the 'fix' algorithm. @akonradi can you add that once #2921 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will do.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 thanks, was just about to comment on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #2979 to add to the 'check' flow.

akonradi added a commit to akonradi/envoy that referenced this pull request Apr 3, 2018
tools/check_format.py was modified in envoyproxy#2969 to automatically fix
protobuf type namespace errors in 'fix' mode, but it did not complain
about them when run in 'check' mode. This commit fixes the lack of
complaints from 'check' mode.

Signed-off-by: Alex Konradi <akonradi@google.com>
mattklein123 pushed a commit that referenced this pull request Apr 3, 2018
tools/check_format.py was modified in #2969 to automatically fix
protobuf type namespace errors in 'fix' mode, but it did not complain
about them when run in 'check' mode. This commit fixes the lack of
complaints from 'check' mode.

Signed-off-by: Alex Konradi <akonradi@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants