-
Notifications
You must be signed in to change notification settings - Fork 5.5k
tools: Add protoxform tests #9241
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
Changes from 5 commits
7fa5ee1
46290c0
caca8d5
c4a7eef
db92556
660f1fe
dbd6f4b
6851f4e
266886f
bd44286
7366a4a
2667652
e2c07d6
9b42b16
ad60337
4df9c39
959e815
d8591eb
ff147d8
89ce863
f33d48d
fef4641
407ac8d
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 |
|---|---|---|
|
|
@@ -532,4 +532,4 @@ def Main(): | |
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| Main() | ||
| Main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #!/bin/bash | ||
|
|
||
| rm -rf bazel-bin/tools | ||
|
|
||
| declare -r PROTO_TARGETS=$(bazel query "labels(srcs, labels(deps, //tools/testdata/protoxform:protos))") | ||
|
|
||
| BAZEL_BUILD_OPTIONS+=" --remote_download_outputs=all --strategy=protoxform=sandboxed,local" | ||
|
|
||
| bazel build ${BAZEL_BUILD_OPTIONS} //tools/testdata/protoxform:protos --aspects \ | ||
|
Shikugawa marked this conversation as resolved.
Outdated
|
||
| tools/type_whisperer/type_whisperer.bzl%type_whisperer_aspect --output_groups=types_pb_text \ | ||
| --host_force_python=PY3 | ||
| declare -x -r TYPE_DB_PATH="${PWD}"/source/common/config/api_type_db.generated.pb_text | ||
| bazel run ${BAZEL_BUILD_OPTIONS} //tools/type_whisperer:typedb_gen -- \ | ||
| ${PWD} ${TYPE_DB_PATH} ${PROTO_TARGETS} | ||
|
|
||
| bazel build ${BAZEL_BUILD_OPTIONS} //tools/testdata/protoxform:protos --aspects \ | ||
| tools/protoxform/protoxform.bzl%protoxform_aspect --output_groups=proto --action_env=CPROFILE_ENABLED=1 \ | ||
| --action_env=TYPE_DB_PATH --host_force_python=PY3 | ||
|
|
||
| ./tools/protoxform_test_helper.py ${PROTO_TARGETS} | ||
|
Member
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. I wonder if @lizan has any Bazel Fu to make the tests work as Bazel aspects.
Member
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. Yes, you can write a rule that depends on aspect (like what |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| from run_command import runCommand | ||
|
|
||
| import logging | ||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
|
|
||
| def PathAndFilename(label): | ||
|
Shikugawa marked this conversation as resolved.
|
||
| if label.startswith('/'): | ||
| label = label.replace('//', '/', 1) | ||
| elif label.startswith('@'): | ||
| label = re.sub(r'@.*/', '/', label) | ||
| else: | ||
| return label | ||
| label = label.replace(":", "/") | ||
| splitted_label = label.split('/') | ||
| return ['/'.join(splitted_label[:len(splitted_label) - 1]), splitted_label[-1]] | ||
|
|
||
|
|
||
| def GoldenProtoFile(path, file, version): | ||
| base = "./" | ||
| base += path + "/" + file + "." + version + ".gold" | ||
| return os.path.abspath(base) | ||
|
|
||
|
|
||
| def ResultProtoFile(path, file, version): | ||
| base = "./bazel-bin" | ||
| base += path + "/protos" + path + "/" + filename + "." + version + ".proto" | ||
|
Shikugawa marked this conversation as resolved.
Outdated
|
||
| return os.path.abspath(base) | ||
|
|
||
|
|
||
| def Diff(result_file, golden_file): | ||
| command = 'diff -u ' | ||
| command += result_file + ' ' | ||
| command += golden_file + ' ' | ||
| status, stdout = runCommand(command) | ||
| return [status, stdout] | ||
|
|
||
|
|
||
| def RunV3Alpha(path, filename): | ||
| message = "" | ||
| golden_path_v3 = GoldenProtoFile(path, filename, 'v3alpha') | ||
| test_path_v3 = ResultProtoFile(path, filename, 'v3alpha') | ||
|
|
||
| status, msg = Diff(test_path_v3, golden_path_v3) | ||
|
|
||
| if status != 0: | ||
| message = '\n'.join([str(line) for line in msg]) | ||
|
|
||
| return message | ||
|
|
||
|
|
||
| def RunV2(path, filename): | ||
|
Shikugawa marked this conversation as resolved.
Outdated
|
||
| message = "" | ||
| golden_path_v2 = GoldenProtoFile(path, filename, 'v2') | ||
| test_path_v2 = ResultProtoFile(path, filename, 'v2') | ||
| status, msg = Diff(test_path_v2, golden_path_v2) | ||
|
|
||
| if status != 0: | ||
| message = '\n'.join([str(line) for line in msg]) | ||
|
|
||
| return message | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| messages = "" | ||
| logging.basicConfig(format='%(message)s') | ||
| path, filename = PathAndFilename(sys.argv[1]) | ||
| messages += RunV2(path, filename) | ||
| messages += RunV3Alpha(path, filename) | ||
|
|
||
| if len(messages) == 0: | ||
| logging.warning("PASS") | ||
|
Member
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. I think you are going to want to |
||
| else: | ||
| logging.error("FAILED:\n{}".format(messages)) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import logging | ||
|
Shikugawa marked this conversation as resolved.
Outdated
|
||
| import subprocess | ||
|
|
||
|
|
||
| # Echoes and runs an OS command, returning exit status and the captured | ||
| # stdout+stderr as a string array. | ||
| def runCommand(command): | ||
|
Shikugawa marked this conversation as resolved.
|
||
| stdout = [] | ||
| status = 0 | ||
| try: | ||
| out = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT).strip() | ||
| if out: | ||
| stdout = out.decode('utf-8').split("\n") | ||
| except subprocess.CalledProcessError as e: | ||
| status = e.returncode | ||
| for line in e.output.splitlines(): | ||
| stdout.append(line) | ||
| logging.info("%s" % command) | ||
|
Shikugawa marked this conversation as resolved.
Outdated
|
||
| return status, stdout | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| proto_library( | ||
| name = "protos", | ||
| visibility = ["//visibility:public"], | ||
| deps = [ | ||
| "//tools/testdata/protoxform/envoy/v2:protos", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| proto_library( | ||
| name = "protos", | ||
| srcs = [ | ||
| "sample.proto", | ||
| ], | ||
| visibility = ["//visibility:public"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.v2; | ||
|
|
||
| message Sample { | ||
| message Entry { | ||
| string key = 1; | ||
| string value = 2; | ||
| } | ||
|
|
||
| repeated Entry entries = 1; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.v2; | ||
|
|
||
| option java_outer_classname = "SampleProto"; | ||
| option java_multiple_files = true; | ||
|
Shikugawa marked this conversation as resolved.
|
||
| option java_package = "io.envoyproxy.envoy.v2"; | ||
|
|
||
| message Sample { | ||
| message Entry { | ||
| string key = 1; | ||
|
|
||
| string value = 2; | ||
| } | ||
|
|
||
| repeated Entry entries = 1; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.v3alpha; | ||
|
|
||
| option java_outer_classname = "SampleProto"; | ||
| option java_multiple_files = true; | ||
| option java_package = "io.envoyproxy.envoy.v3alpha"; | ||
|
|
||
| import "udpa/api/annotations/versioning.proto"; | ||
|
|
||
| message Sample { | ||
| option (udpa.api.annotations.versioning).previous_message_type = "envoy.v2.Sample"; | ||
|
|
||
| message Entry { | ||
| option (udpa.api.annotations.versioning).previous_message_type = "envoy.v2.Sample.Entry"; | ||
|
|
||
| string key = 1; | ||
|
|
||
| string value = 2; | ||
| } | ||
|
|
||
| repeated Entry entries = 1; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.