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

dependencies: associate extensions with deps, validate use_category. #13340

Merged
merged 7 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def _repository_locations():
cpe = mutable_location.pop("cpe")

# Starlark doesn't have regexes.
if cpe != "N/A" and (not cpe.startswith("cpe:2.3:a:") or not cpe.endswith(":*") and len(cpe.split(":")) != 6):
cpe_matches = (cpe != "N/A" and (not cpe.startswith("cpe:2.3:a:") or not cpe.endswith(":*") and len(cpe.split(":")) != 6))
if cpe_matches:
fail("CPE must match cpe:2.3:a:<facet>:<facet>:*: " + cpe)
elif not [category for category in USE_CATEGORIES_WITH_CPE_OPTIONAL if category in location["use_category"]]:
_fail_missing_attribute("cpe", key)
Expand Down
7 changes: 2 additions & 5 deletions docs/generate_external_dep_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ def RenderTitle(title):
last_updated = v['last_updated']
dep = Dep(name, project_name.lower(), version, cpe, last_updated)
for category in v['use_category']:
if 'extensions' in v:
for ext in v['extensions']:
use_categories[category][ext].append(dep)
else:
use_categories[category]['core'].append(dep)
for ext in v.get('extensions', ['core']):
use_categories[category][ext].append(dep)

def CsvRow(dep):
return [dep.name, dep.version, dep.last_updated, dep.cpe]
Expand Down
1 change: 0 additions & 1 deletion source/exe/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ envoy_cc_library(
hdrs = ["main_common.h"],
deps = [
":envoy_common_with_core_extensions_lib",
#":main_common_lib",
":platform_impl_lib",
":process_wide_lib",
"//source/common/api:os_sys_calls_lib",
Expand Down
23 changes: 11 additions & 12 deletions tools/dependency/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import subprocess
import sys

from importlib.util import spec_from_loader, module_from_spec
from importlib.machinery import SourceFileLoader
from importlib.util import spec_from_loader, module_from_spec

# bazel/repository_locations.bzl must have a .bzl suffix for Starlark import, so
# we are forced to do this workaround.
Expand Down Expand Up @@ -59,11 +59,8 @@ def DepsByUseCategory(self, use_category):
Returns:
Set of dependency identifiers that match use_category.
"""
deps = set([])
for name, metadata in repository_locations.DEPENDENCY_REPOSITORIES.items():
if use_category in metadata['use_category']:
deps.add(name)
return deps
return set(name for name, metadata in repository_locations.DEPENDENCY_REPOSITORIES.items()
if use_category in metadata['use_category'])

def GetMetadata(self, dependency):
"""Obtain repository metadata for a dependency.
Expand All @@ -75,7 +72,7 @@ def GetMetadata(self, dependency):
A dictionary with the repository metadata as defined in
bazel/repository_locations.bzl.
"""
return repository_locations.DEPENDENCY_REPOSITORIES.get(dependency, None)
return repository_locations.DEPENDENCY_REPOSITORIES.get(dependency)


class BuildGraph(object):
Expand All @@ -93,7 +90,7 @@ def QueryExternalDeps(self, *targets):
deps_query = ' union '.join(f'deps({l})' for l in targets)
deps = subprocess.check_output(['bazel', 'query', deps_query],
stderr=subprocess.PIPE).decode().splitlines()
ext_deps = set([])
ext_deps = set()
for d in deps:
match = BAZEL_QUERY_EXTERNAL_DEP_RE.match(d)
if match:
Expand Down Expand Up @@ -131,7 +128,7 @@ def ValidateBuildGraphStructure(self):
'//source/exe:envoy_main_common_with_core_extensions_lib', '//source/extensions/...')
queried_all_deps = self._build_graph.QueryExternalDeps('//source/...')
if queried_all_deps != queried_core_ext_deps:
raise DependencyError(f'Invalid build graph structure. deps(//source/...) != '
raise DependencyError('Invalid build graph structure. deps(//source/...) != '
'deps(//source/exe:envoy_main_common_with_core_extensions_lib) '
'union deps(//source/extensions/...)')

Expand Down Expand Up @@ -178,7 +175,8 @@ def ValidateDataPlaneCoreDeps(self):
def ValidateControlPlaneDeps(self):
"""Validate controlplane dependencies.

Check that we at least tag as controlplane dependencies that match some well-known targets for
Check that we at least tag as controlplane dependencies that match some
well-known targets for
the control-plane.

Raises:
Expand Down Expand Up @@ -221,8 +219,9 @@ def ValidateExtensionDeps(self, name, target):
metadata = self._dep_info.GetMetadata(d)
if metadata:
use_category = metadata['use_category']
if ('dataplane_ext' not in use_category and 'observability_ext' not in use_category and
'other' not in use_category):
valid_use_category = ('dataplane_ext' in use_category or
htuch marked this conversation as resolved.
Show resolved Hide resolved
'observability_ext' in use_category or 'other' in use_category)
if not valid_use_category:
raise DependencyError(
f'Extensions {name} depends on {d} with "use_category" not including '
'["dataplane_ext", "observability_ext", "other"]')
Expand Down
2 changes: 1 addition & 1 deletion tools/dependency/validate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def DepsByUseCategory(self, use_category):
return set(n for n, m in self._deps.items() if use_category in m['use_category'])

def GetMetadata(self, dependency):
return self._deps.get(dependency, None)
return self._deps.get(dependency)


class FakeBuildGraph(object):
Expand Down