Skip to content

Commit

Permalink
format: run buildifier on WORKSPACE files. (envoyproxy#5259)
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora authored and zuercher committed Dec 10, 2018
1 parent 78fe31e commit 6ea4a03
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 6 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
workspace(name = "envoy")

load("//bazel:repositories.bzl", "envoy_dependencies", "GO_VERSION")
load("//bazel:repositories.bzl", "GO_VERSION", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

envoy_dependencies()

cc_configure()

load("@envoy_api//bazel:repositories.bzl", "api_dependencies")

api_dependencies()

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(go_version = GO_VERSION)
7 changes: 5 additions & 2 deletions ci/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
workspace(name = "ci")

load("//bazel:repositories.bzl", "envoy_dependencies", "GO_VERSION")
load("//bazel:repositories.bzl", "GO_VERSION", "envoy_dependencies")
load("//bazel:cc_configure.bzl", "cc_configure")

# We shouldn't need this, but it's a workaround for https://github.com/bazelbuild/bazel/issues/3580.
Expand All @@ -16,8 +16,11 @@ envoy_dependencies(
cc_configure()

load("@envoy_api//bazel:repositories.bzl", "api_dependencies")

api_dependencies()

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
load("@io_bazel_rules_go//go:def.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(go_version = GO_VERSION)
17 changes: 11 additions & 6 deletions tools/check_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"./bazel/external", "./.cache",
"./source/extensions/extensions_build_config.bzl",
"./tools/testdata/check_format/")
SUFFIXES = (".cc", ".h", "BUILD", ".bzl", ".md", ".rst", ".proto")
SUFFIXES = (".cc", ".h", "BUILD", "WORKSPACE", ".bzl", ".md", ".rst", ".proto")
DOCS_SUFFIX = (".md", ".rst")
PROTO_SUFFIX = (".proto")

Expand Down Expand Up @@ -181,6 +181,10 @@ def isSkylarkFile(file_path):
return file_path.endswith(".bzl")


def isWorkspaceFile(file_path):
return os.path.basename(file_path) == "WORKSPACE"


def hasInvalidAngleBracketDirectory(line):
if not line.startswith(INCLUDE_ANGLE):
return False
Expand Down Expand Up @@ -294,12 +298,13 @@ def checkBuildLine(line, file_path, reportError):
if not whitelistedForProtobufDeps(file_path) and '"protobuf"' in line:
reportError("unexpected direct external dependency on protobuf, use "
"//source/common/protobuf instead.")
if envoy_build_rule_check and not isSkylarkFile(file_path) and '@envoy//' in line:
if (envoy_build_rule_check and not isSkylarkFile(file_path) and not isWorkspaceFile(file_path) and
'@envoy//' in line):
reportError("Superfluous '@envoy//' prefix")


def fixBuildLine(line, file_path):
if envoy_build_rule_check and not isSkylarkFile(file_path):
if envoy_build_rule_check and not isSkylarkFile(file_path) and not isWorkspaceFile(file_path):
line = line.replace('@envoy//', '//')
return line

Expand All @@ -310,7 +315,7 @@ def fixBuildPath(file_path):

error_messages = []
# TODO(htuch): Add API specific BUILD fixer script.
if not isApiFile(file_path) and not isSkylarkFile(file_path):
if not isApiFile(file_path) and not isSkylarkFile(file_path) and not isWorkspaceFile(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]

Expand All @@ -321,7 +326,7 @@ def fixBuildPath(file_path):

def checkBuildPath(file_path):
error_messages = []
if not isApiFile(file_path) and not isSkylarkFile(file_path):
if not isApiFile(file_path) and not isSkylarkFile(file_path) and not isWorkspaceFile(file_path):
command = "%s %s | diff %s -" % (ENVOY_BUILD_FIXER_PATH, file_path, file_path)
error_messages += executeCommand(command, "envoy_build_fixer check failed", file_path)

Expand Down Expand Up @@ -406,7 +411,7 @@ def checkFormat(file_path):
# Apply fixes first, if asked, and then run checks. If we wind up attempting to fix
# an issue, but there's still an error, that's a problem.
try_to_fix = operation_type == "fix"
if isBuildFile(file_path) or isSkylarkFile(file_path):
if isBuildFile(file_path) or isSkylarkFile(file_path) or isWorkspaceFile(file_path):
if try_to_fix:
error_messages += fixBuildPath(file_path)
error_messages += checkBuildPath(file_path)
Expand Down

0 comments on commit 6ea4a03

Please sign in to comment.