diff options
author | 2017-11-29 17:06:16 -0800 | |
---|---|---|
committer | 2017-12-14 18:11:25 -0800 | |
commit | 54a70409c0c4059c19c14ec759633637fd0656d8 (patch) | |
tree | 316ecff46d56cec2dcaa901f2143ff654ad7d30b /tools/run_tests/sanity/check_bazel_workspace.py | |
parent | 00a7d47e5b04fa508c1dc8edf52084f5736f7c3d (diff) |
Move more special cases in bazel build to the .bzl files
Diffstat (limited to 'tools/run_tests/sanity/check_bazel_workspace.py')
-rwxr-xr-x | tools/run_tests/sanity/check_bazel_workspace.py | 84 |
1 files changed, 75 insertions, 9 deletions
diff --git a/tools/run_tests/sanity/check_bazel_workspace.py b/tools/run_tests/sanity/check_bazel_workspace.py index b5a77f4479..62a6229c5d 100755 --- a/tools/run_tests/sanity/check_bazel_workspace.py +++ b/tools/run_tests/sanity/check_bazel_workspace.py @@ -34,21 +34,76 @@ git_submodule_hashes = { for s in git_submodules } -# Parse git hashes from Bazel WORKSPACE {new_}http_archive rules -with open('WORKSPACE', 'r') as f: - workspace_rules = [expr.value for expr in ast.parse(f.read()).body] +_BAZEL_TOOLCHAINS_DEP_NAME = 'com_github_bazelbuild_bazeltoolchains' -http_archive_rules = [ - rule for rule in workspace_rules if rule.func.id.endswith('http_archive') -] -archive_urls = [ - kw.value.s for rule in http_archive_rules for kw in rule.keywords - if kw.arg == 'url' +_GRPC_DEP_NAMES = [ + 'boringssl', + 'com_github_madler_zlib', + 'com_google_protobuf', + 'com_github_google_googletest', + 'com_github_gflags_gflags', + 'com_github_google_benchmark', + 'com_github_cares_cares', + 'com_google_absl', + _BAZEL_TOOLCHAINS_DEP_NAME, ] + + +class BazelEvalState(object): + + def __init__(self, names_and_urls, overridden_name=None): + self.names_and_urls = names_and_urls + self.overridden_name = overridden_name + + def http_archive(self, **args): + self.archive(**args) + + def new_http_archive(self, **args): + self.archive(**args) + + def bind(self, **args): + pass + + def existing_rules(self): + if self.overridden_name: + return [self.overridden_name] + return [] + + def archive(self, **args): + if args['name'] == _BAZEL_TOOLCHAINS_DEP_NAME: + self.names_and_urls[args['name']] = 'dont care' + return + self.names_and_urls[args['name']] = args['url'] + + +# Parse git hashes from bazel/grpc_deps.bzl {new_}http_archive rules +with open(os.path.join('bazel', 'grpc_deps.bzl'), 'r') as f: + names_and_urls = {} + eval_state = BazelEvalState(names_and_urls) + bazel_file = f.read() + +# grpc_deps.bzl only defines 'grpc_deps', add this to call it +bazel_file += '\ngrpc_deps()\n' +build_rules = { + 'native': eval_state, +} +exec bazel_file in build_rules +for name in _GRPC_DEP_NAMES: + assert name in names_and_urls.keys() +assert len(_GRPC_DEP_NAMES) == len(names_and_urls.keys()) + +# bazeltoolschains is an exception to this sanity check, +# we don't require that there is a corresponding git module. +names_without_bazeltoolchains = names_and_urls.keys() +names_without_bazeltoolchains.remove(_BAZEL_TOOLCHAINS_DEP_NAME) +archive_urls = [names_and_urls[name] for name in names_without_bazeltoolchains] workspace_git_hashes = { re.search(git_hash_pattern, url).group() for url in archive_urls } +if len(workspace_git_hashes) == 0: + print("(Likely) parse error, did not find any bazel git dependencies.") + sys.exit(1) # Validate the equivalence of the git submodules and Bazel git dependencies. The # condition we impose is that there is a git submodule for every dependency in @@ -60,4 +115,15 @@ if len(workspace_git_hashes - git_submodule_hashes) > 0: ) sys.exit(1) +# Also check that we can override each dependency +for name in _GRPC_DEP_NAMES: + names_and_urls_with_overridden_name = {} + state = BazelEvalState( + names_and_urls_with_overridden_name, overridden_name=name) + rules = { + 'native': state, + } + exec bazel_file in rules + assert name not in names_and_urls_with_overridden_name.keys() + sys.exit(0) |