Skip to content
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
1 change: 1 addition & 0 deletions bazel/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def envoy_dependencies(skip_targets = []):
_repository_impl("bazel_toolchains")
_repository_impl("bazel_compdb")
_repository_impl("envoy_build_tools")
_repository_impl("rules_cc")

# Unconditional, since we use this only for compiler-agnostic fuzzing utils.
_org_llvm_releases_compiler_rt()
Expand Down
8 changes: 8 additions & 0 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,14 @@ DEPENDENCY_REPOSITORIES = dict(
urls = ["https://github.com/bazelbuild/rules_go/releases/download/v0.20.3/rules_go-v0.20.3.tar.gz"],
use_category = ["build"],
),
rules_cc = dict(
sha256 = "9d48151ea71b3e225adfb6867e6d2c7d0dce46cbdc8710d9a9a628574dfd40a0",
strip_prefix = "rules_cc-818289e5613731ae410efb54218a4077fb9dbb03",
# 2020-05-13
# TODO(lizan): pin to a point releases when there's a released version.
urls = ["https://github.com/bazelbuild/rules_cc/archive/818289e5613731ae410efb54218a4077fb9dbb03.tar.gz"],
use_category = ["build"],
),
rules_foreign_cc = dict(
sha256 = "3184c244b32e65637a74213fc448964b687390eeeca42a36286f874c046bba15",
strip_prefix = "rules_foreign_cc-7bc4be735b0560289f6b86ab6136ee25d20b65b7",
Expand Down
2 changes: 1 addition & 1 deletion tools/code_format/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def fixBuildPath(file_path):
if os.system("%s %s %s" % (ENVOY_BUILD_FIXER_PATH, file_path, file_path)) != 0:
error_messages += ["envoy_build_fixer rewrite failed for file: %s" % file_path]

if os.system("%s -mode=fix %s" % (BUILDIFIER_PATH, file_path)) != 0:
if os.system("%s -lint=fix -mode=fix %s" % (BUILDIFIER_PATH, file_path)) != 0:
error_messages += ["buildifier rewrite failed for file: %s" % file_path]
return error_messages

Expand Down
4 changes: 2 additions & 2 deletions tools/code_format/check_format_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ def fixFileExpectingSuccess(file, extra_input_files=None):
command, infile, outfile, status, stdout = fixFileHelper(file,
extra_input_files=extra_input_files)
if status != 0:
print("FAILED:")
print("FAILED:" + infile)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add a space after the :?

emitStdoutAsError(stdout)
return 1
status, stdout, stderr = runCommand('diff ' + outfile + ' ' + infile + '.gold')
if status != 0:
print("FAILED:")
print("FAILED:" + infile)
emitStdoutAsError(stdout + stderr)
return 1
return 0
Expand Down
23 changes: 13 additions & 10 deletions tools/code_format/envoy_build_fixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# Where does Buildozer live?
BUILDOZER_PATH = paths.getBuildozer()

# Where does Buildifier live?
BUILDIFIER_PATH = paths.getBuildifier()

# Canonical Envoy license.
LICENSE_STRING = 'licenses(["notice"]) # Apache 2\n\n'

Expand Down Expand Up @@ -89,14 +92,15 @@ def FixPackageAndLicense(contents):
return contents


# Remove trailing blank lines, unnecessary double blank lines.
def FixEmptyLines(contents):
return re.sub('\n\s*$', '\n', re.sub('\n\n\n', '\n\n', contents))


# Misc. Buildozer cleanups.
def FixBuildozerCleanups(contents):
return RunBuildozer([('fix unusedLoads', '__pkg__')], contents)
# Run Buildifier commands on a string with lint mode.
def BuildifierLint(contents):
r = subprocess.run([BUILDIFIER_PATH, '-lint=fix', '-mode=fix', '-type=build'],
input=contents.encode(),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
if r.returncode != 0:
raise EnvoyBuildFixerError('buildozer execution failed: %s' % r)
return r.stdout.decode('utf-8')


# Find all the API headers in a C++ source file.
Expand Down Expand Up @@ -170,9 +174,8 @@ def FixBuild(path):
contents = f.read()
xforms = [
FixPackageAndLicense,
FixEmptyLines,
functools.partial(FixApiDeps, path),
FixBuildozerCleanups,
BuildifierLint,
]
for xform in xforms:
contents = xform(contents)
Expand Down
4 changes: 2 additions & 2 deletions tools/proto_format/active_protos_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
BUILD_FILE_TEMPLATE = string.Template(
"""# DO NOT EDIT. This file is generated by tools/proto_format/active_protos_gen.py.

licenses(["notice"]) # Apache 2

load("@rules_proto//proto:defs.bzl", "proto_library")

licenses(["notice"]) # Apache 2

# This tracks active development versions of protos.
proto_library(
name = "active_protos",
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/add_envoy_package.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/bad_envoy_build_sys_ref.BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
licenses(["notice"]) # Apache 2

load(
"@envoy//bazel:envoy_build_system.bzl",
"envoy_cc_binary",
"envoy_package",
)

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
licenses(["notice"]) # Apache 2

load(
"//bazel:envoy_build_system.bzl",
"envoy_cc_binary",
"envoy_package",
)

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/canonical_api_deps.BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

# Deps can be inferred, irrelevant deps are removed.
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/canonical_api_deps.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_cc_library", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

# Deps can be inferred, irrelevant deps are removed.
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/canonical_spacing.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/remove_unused_loads.BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
licenses(["notice"]) # Apache 2

load("//foo.bzl", "bar")
load("//bazel:envoy_build_system.bzl", "envoy_package", "envoy_cc_library")

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/remove_unused_loads.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
licenses(["notice"]) # Apache 2

load("//bazel:envoy_build_system.bzl", "envoy_package")

licenses(["notice"]) # Apache 2

envoy_package()

envoy_cc_binary(
Expand Down
2 changes: 2 additions & 0 deletions tools/testdata/check_format/skip_envoy_package.BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")

licenses(["notice"]) # Apache 2

cc_binary(
Expand Down
2 changes: 2 additions & 0 deletions tools/testdata/check_format/skip_envoy_package.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_binary")

licenses(["notice"]) # Apache 2

cc_binary(
Expand Down
4 changes: 2 additions & 2 deletions tools/testdata/check_format/update_license.BUILD.gold
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
licenses(["notice"]) # Apache 2

load("//some:thing.bzl", "foo")

licenses(["notice"]) # Apache 2

foo()