Automated fix for refs/heads/master (#33576)

PanCakes to the rescue!

We noticed that our 'sanity' test was going to fail, but we think we can
fix that automatically, so we put together this PR to do just that!

If you'd like to opt-out of these PR's, add yourself to NO_AUTOFIX_USERS
in .github/workflows/pr-auto-fix.yaml

Co-authored-by: markdroth <markdroth@users.noreply.github.com>
pull/33579/head
github-actions[bot] 2 years ago committed by GitHub
parent 15db5cd16a
commit 88e269dc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      tools/codegen/core/experiments_compiler.py
  2. 11
      tools/codegen/core/gen_experiments.py

@ -105,7 +105,7 @@ def _EXPERIMENT_CHECK_TEXT(name):
"""
def ToCStr(s, encoding='ascii'):
def ToCStr(s, encoding="ascii"):
if isinstance(s, str):
s = s.encode(encoding)
result = ""
@ -325,9 +325,7 @@ class ExperimentsCompiler(object):
file_path_list = output_file.split("/")[0:-1]
file_name = output_file.split("/")[-1].split(".")[0]
include_guard = (
f"GRPC_{'_'.join(path.upper() for path in file_path_list)}_{file_name.upper()}_H"
)
include_guard = f"GRPC_{'_'.join(path.upper() for path in file_path_list)}_{file_name.upper()}_H"
print(f"#ifndef {include_guard}", file=H)
print(f"#define {include_guard}", file=H)
@ -365,7 +363,11 @@ class ExperimentsCompiler(object):
print(
"inline bool Is%sEnabled() { return"
" Is%sExperimentEnabled(%d); }"
% (SnakeToPascal(exp.name), "Test" if mode == "test" else "", i),
% (
SnakeToPascal(exp.name),
"Test" if mode == "test" else "",
i,
),
file=H,
)
print(file=H)
@ -404,7 +406,7 @@ class ExperimentsCompiler(object):
)
print("#include <grpc/support/port_platform.h>", file=C)
print(f"#include \"{header_file_path}\"", file=C)
print(f'#include "{header_file_path}"', file=C)
print(file=C)
print("#ifndef GRPC_EXPERIMENTS_ARE_FINAL", file=C)
print("namespace {", file=C)
@ -441,7 +443,8 @@ class ExperimentsCompiler(object):
else:
experiments_metadata_var_name = "g_experiment_metadata"
print(
f"const ExperimentMetadata {experiments_metadata_var_name}[] = {{", file=C
f"const ExperimentMetadata {experiments_metadata_var_name}[] = {{",
file=C,
)
for _, exp in self._experiment_definitions.items():
print(
@ -461,17 +464,19 @@ class ExperimentsCompiler(object):
print("#endif", file=C)
def GenTest(self, output_file):
with open(output_file, 'w') as C:
with open(output_file, "w") as C:
PutCopyright(C, "//")
PutBanner(
[C],
["Auto generated by tools/codegen/core/gen_experiments.py"],
"//")
"//",
)
defs = ""
test_body = ""
for _, exp in self._experiment_definitions.items():
defs += _EXPERIMENTS_EXPECTED_VALUE(
SnakeToPascal(exp.name), self._final_return[exp.default])
SnakeToPascal(exp.name), self._final_return[exp.default]
)
test_body += _EXPERIMENT_CHECK_TEXT(SnakeToPascal(exp.name))
print(_EXPERIMENTS_TEST_SKELETON(defs, test_body), file=C)

@ -82,7 +82,9 @@ args = ParseCommandLineArguments(sys.argv[1:])
def _GenerateExperimentFiles(args, mode):
if mode == "test":
_EXPERIMENTS_DEFS = "test/core/experiments/fixtures/test_experiments.yaml"
_EXPERIMENTS_DEFS = (
"test/core/experiments/fixtures/test_experiments.yaml"
)
_EXPERIMENTS_ROLLOUTS = (
"test/core/experiments/fixtures/test_experiments_rollout.yaml"
)
@ -125,14 +127,15 @@ def _GenerateExperimentFiles(args, mode):
print(f"Mode = {mode} Generating experiments headers")
compiler.GenerateExperimentsHdr(_EXPERIMENTS_HDR_FILE, mode)
print(f"Mode = {mode} Generating experiments srcs")
compiler.GenerateExperimentsSrc(
_EXPERIMENTS_SRC_FILE, _EXPERIMENTS_HDR_FILE, mode)
_EXPERIMENTS_SRC_FILE, _EXPERIMENTS_HDR_FILE, mode
)
if mode == "test":
print("Generating experiments tests")
compiler.GenTest('test/core/experiments/experiments_test.cc')
compiler.GenTest("test/core/experiments/experiments_test.cc")
else:
print("Generating experiments.bzl")
compiler.GenExperimentsBzl("bazel/experiments.bzl")

Loading…
Cancel
Save