Make gen_experiments.py runnable internally also

PiperOrigin-RevId: 591902705
pull/35186/head
Craig Tiller 1 year ago committed by Copybara-Service
parent 52719bee53
commit c93798b5c7
  1. 11
      tools/codegen/core/experiments_compiler.py
  2. 27
      tools/codegen/core/gen_experiments.py

@ -403,8 +403,9 @@ class ExperimentsCompiler(object):
if mode != "test":
include_guard = "GRPC_SRC_CORE_LIB_EXPERIMENTS_EXPERIMENTS_H"
else:
file_path_list = output_file.split("/")[0:-1]
file_name = output_file.split("/")[-1].split(".")[0]
real_output_file = output_file.replace(".github", "")
file_path_list = real_output_file.split("/")[0:-1]
file_name = real_output_file.split("/")[-1].split(".")[0]
include_guard = f"GRPC_{'_'.join(path.upper() for path in file_path_list)}_{file_name.upper()}_H"
@ -562,9 +563,13 @@ class ExperimentsCompiler(object):
break
print("#include <grpc/support/port_platform.h>", file=C)
print(file=C)
if any_requires:
print("#include <stdint.h>", file=C)
print(f'#include "{header_file_path}"', file=C)
print(file=C)
print(
f'#include "{header_file_path.replace(".github", "")}"', file=C
)
print(file=C)
print("#ifndef GRPC_EXPERIMENTS_ARE_FINAL", file=C)
idx = 0

@ -23,11 +23,18 @@ Experiment definitions are in src/core/lib/experiments/experiments.yaml
from __future__ import print_function
import argparse
import os
import sys
import experiments_compiler as exp
import yaml
REPO_ROOT = os.path.normpath(
os.path.join(os.path.dirname(__file__), "../../..")
)
print(REPO_ROOT)
os.chdir(REPO_ROOT)
DEFAULTS = {
"broken": "false",
False: "false",
@ -86,6 +93,11 @@ def ParseCommandLineArguments(args):
args = ParseCommandLineArguments(sys.argv[1:])
def _InjectGithubPath(path):
base, ext = os.path.splitext(path)
return base + ".github" + ext
def _GenerateExperimentFiles(args, mode):
if mode == "test":
_EXPERIMENTS_DEFS = (
@ -96,11 +108,18 @@ def _GenerateExperimentFiles(args, mode):
)
_EXPERIMENTS_HDR_FILE = "test/core/experiments/fixtures/experiments.h"
_EXPERIMENTS_SRC_FILE = "test/core/experiments/fixtures/experiments.cc"
_EXPERIMENTS_BZL_FILE = "bazel/test_experiments.bzl"
else:
_EXPERIMENTS_DEFS = "src/core/lib/experiments/experiments.yaml"
_EXPERIMENTS_ROLLOUTS = "src/core/lib/experiments/rollouts.yaml"
_EXPERIMENTS_HDR_FILE = "src/core/lib/experiments/experiments.h"
_EXPERIMENTS_SRC_FILE = "src/core/lib/experiments/experiments.cc"
_EXPERIMENTS_BZL_FILE = "bazel/experiments.bzl"
if "/google3/" in REPO_ROOT:
_EXPERIMENTS_ROLLOUTS = _InjectGithubPath(_EXPERIMENTS_ROLLOUTS)
_EXPERIMENTS_HDR_FILE = _InjectGithubPath(_EXPERIMENTS_HDR_FILE)
_EXPERIMENTS_SRC_FILE = _InjectGithubPath(_EXPERIMENTS_SRC_FILE)
_EXPERIMENTS_BZL_FILE = _InjectGithubPath(_EXPERIMENTS_BZL_FILE)
with open(_EXPERIMENTS_DEFS) as f:
attrs = yaml.safe_load(f.read())
@ -152,12 +171,12 @@ def _GenerateExperimentFiles(args, mode):
)
print("Generating experiments.bzl")
compiler.GenExperimentsBzl(mode, _EXPERIMENTS_BZL_FILE)
if mode == "test":
compiler.GenExperimentsBzl(mode, "bazel/test_experiments.bzl")
print("Generating experiments tests")
compiler.GenTest("test/core/experiments/experiments_test.cc")
else:
compiler.GenExperimentsBzl(mode, "bazel/experiments.bzl")
compiler.GenTest(
os.path.join(REPO_ROOT, "test/core/experiments/experiments_test.cc")
)
_GenerateExperimentFiles(args, "production")

Loading…
Cancel
Save