Skip to content

Commit

Permalink
Format all Bazel files with buildifier
Browse files Browse the repository at this point in the history
  • Loading branch information
lidizheng committed Nov 5, 2019
1 parent 2990b48 commit c34bef4
Show file tree
Hide file tree
Showing 132 changed files with 1,263 additions and 1,204 deletions.
4 changes: 2 additions & 2 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ grpc_cc_library(
standalone = True,
deps = [
"grpc_common",
"grpc_lb_policy_cds",
"grpc_lb_policy_grpclb",
"grpc_lb_policy_xds",
"grpc_lb_policy_cds",
"grpc_resolver_xds",
],
)
Expand All @@ -336,9 +336,9 @@ grpc_cc_library(
standalone = True,
deps = [
"grpc_common",
"grpc_lb_policy_cds_secure",
"grpc_lb_policy_grpclb_secure",
"grpc_lb_policy_xds_secure",
"grpc_lb_policy_cds_secure",
"grpc_resolver_xds_secure",
"grpc_secure",
"grpc_transport_chttp2_client_secure",
Expand Down
4 changes: 3 additions & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ rbe_autoconfig(
),
)

load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import")
load("@io_bazel_rules_python//python:pip.bzl", "pip_import", "pip_repositories")

pip_import(
name = "grpc_python_dependencies",
requirements = "@com_github_grpc_grpc//:requirements.bazel.txt",
)

load("@grpc_python_dependencies//:requirements.bzl", "pip_install")

pip_repositories()

pip_install()
38 changes: 19 additions & 19 deletions bazel/cython_library.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Custom rules for gRPC Python"""


# Adapted with modifications from
# tensorflow/tensorflow/core/platform/default/build_config.bzl
# Native Bazel rules don't exist yet to compile Cython code, but rules have
# been written at cython/cython and tensorflow/tensorflow. We branch from
# Tensorflow's version as it is more actively maintained and works for gRPC
# Python's needs.
def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
def pyx_library(name, deps = [], py_deps = [], srcs = [], **kwargs):
"""Compiles a group of .pyx / .pxd / .py files.
First runs Cython to create .cpp files for each input .pyx or .py + .pxd
Expand All @@ -23,6 +22,7 @@ def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
srcs: .py, .pyx, or .pxd files to either compile or pass through.
**kwargs: Extra keyword arguments passed to the py_library.
"""

# First filter out files that should be run compiled vs. passed through.
py_srcs = []
pyx_srcs = []
Expand All @@ -41,34 +41,34 @@ def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs):
# Invoke cython to produce the shared object libraries.
for filename in pyx_srcs:
native.genrule(
name=filename + "_cython_translation",
srcs=[filename],
outs=[filename.split(".")[0] + ".cpp"],
name = filename + "_cython_translation",
srcs = [filename],
outs = [filename.split(".")[0] + ".cpp"],
# Optionally use PYTHON_BIN_PATH on Linux platforms so that python 3
# works. Windows has issues with cython_binary so skip PYTHON_BIN_PATH.
cmd=
"PYTHONHASHSEED=0 $(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)",
tools=["@cython//:cython_binary"] + pxd_srcs,
cmd =
"PYTHONHASHSEED=0 $(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)",
tools = ["@cython//:cython_binary"] + pxd_srcs,
)

shared_objects = []
for src in pyx_srcs:
stem = src.split(".")[0]
shared_object_name = stem + ".so"
native.cc_binary(
name=shared_object_name,
srcs=[stem + ".cpp"],
deps=deps + ["@local_config_python//:python_headers"],
linkshared=1,
name = shared_object_name,
srcs = [stem + ".cpp"],
deps = deps + ["@local_config_python//:python_headers"],
linkshared = 1,
)
shared_objects.append(shared_object_name)

# Now create a py_library with these shared objects as data.
native.py_library(
name=name,
srcs=py_srcs,
deps=py_deps,
srcs_version="PY2AND3",
data=shared_objects,
**kwargs)

name = name,
srcs = py_srcs,
deps = py_deps,
srcs_version = "PY2AND3",
data = shared_objects,
**kwargs
)
1 change: 1 addition & 0 deletions bazel/generate_cc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def generate_cc_impl(ctx):
"--proto_path={}".format(get_include_directory(i))
for i in includes
]

# Include the output directory so that protoc puts the generated code in the
# right directory.
arguments += ["--proto_path={0}{1}".format(dir_out, proto_root)]
Expand Down
30 changes: 17 additions & 13 deletions bazel/generate_objc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load(
"get_plugin_args",
"proto_path_to_generated_filename",
)
load(":grpc_util.bzl", "to_upper_camel_with_extension",)
load(":grpc_util.bzl", "to_upper_camel_with_extension")

_GRPC_PROTO_HEADER_FMT = "{}.pbrpc.h"
_GRPC_PROTO_SRC_FMT = "{}.pbrpc.m"
Expand Down Expand Up @@ -40,7 +40,9 @@ def _generate_objc_impl(ctx):

out_files = [ctx.actions.declare_file(out) for out in outs]
dir_out = _join_directories([
str(ctx.genfiles_dir.path), target_package, _GENERATED_PROTOS_DIR
str(ctx.genfiles_dir.path),
target_package,
_GENERATED_PROTOS_DIR,
])

arguments = []
Expand Down Expand Up @@ -70,6 +72,7 @@ def _generate_objc_impl(ctx):
well_known_proto_files = []
if ctx.attr.use_well_known_protos:
f = ctx.attr.well_known_protos.files.to_list()[0].dirname

# go two levels up so that #import "google/protobuf/..." is correct
arguments += ["-I{0}".format(f + "/../..")]
well_known_proto_files = ctx.attr.well_known_protos.files.to_list()
Expand All @@ -90,6 +93,7 @@ def _label_to_full_file_path(src, package):
# "a.proto" -> ":a.proto"
src = ":" + src
src = "//" + package + src

# Converts //path/to/package:File.ext to path/to/package/File.ext.
src = src.replace("//", "")
src = src.replace(":", "/")
Expand Down Expand Up @@ -119,6 +123,7 @@ def _get_directory_from_proto(proto):

def _get_full_path_from_file(file):
gen_dir_length = 0

# if file is generated, then prepare to remote its root
# (including CPU architecture...)
if not file.is_source:
Expand All @@ -130,7 +135,6 @@ def _join_directories(directories):
massaged_directories = [directory for directory in directories if len(directory) != 0]
return "/".join(massaged_directories)


generate_objc = rule(
attrs = {
"deps": attr.label_list(
Expand All @@ -146,14 +150,14 @@ generate_objc = rule(
),
"srcs": attr.string_list(
mandatory = False,
allow_empty = True
allow_empty = True,
),
"use_well_known_protos": attr.bool(
mandatory = False,
default = False
default = False,
),
"well_known_protos": attr.label(
default = "@com_google_protobuf//:well_known_protos"
default = "@com_google_protobuf//:well_known_protos",
),
"_protoc": attr.label(
default = Label("//external:protocol_compiler"),
Expand All @@ -162,7 +166,7 @@ generate_objc = rule(
),
},
output_to_genfiles = True,
implementation = _generate_objc_impl
implementation = _generate_objc_impl,
)

def _group_objc_files_impl(ctx):
Expand All @@ -189,9 +193,9 @@ generate_objc_hdrs = rule(
),
"gen_mode": attr.int(
default = _GENERATE_HDRS,
)
),
},
implementation = _group_objc_files_impl
implementation = _group_objc_files_impl,
)

generate_objc_srcs = rule(
Expand All @@ -201,9 +205,9 @@ generate_objc_srcs = rule(
),
"gen_mode": attr.int(
default = _GENERATE_SRCS,
)
),
},
implementation = _group_objc_files_impl
implementation = _group_objc_files_impl,
)

generate_objc_non_arc_srcs = rule(
Expand All @@ -213,7 +217,7 @@ generate_objc_non_arc_srcs = rule(
),
"gen_mode": attr.int(
default = _GENERATE_NON_ARC_SRCS,
)
),
},
implementation = _group_objc_files_impl
implementation = _group_objc_files_impl,
)
37 changes: 18 additions & 19 deletions bazel/grpc_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ load("//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load("@upb//bazel:upb_proto_library.bzl", "upb_proto_library")
load("@build_bazel_rules_apple//apple:ios.bzl", "ios_unit_test")


# The set of pollers to test against if a test exercises polling
POLLERS = ["epollex", "epoll1", "poll"]

# set exec_properties = LARGE_MACHINE, to run the test on a large machine
# see //third_party/toolchains/machine_size for details
LARGE_MACHINE = { "gceMachineType" : "n1-standard-8"}
LARGE_MACHINE = {"gceMachineType": "n1-standard-8"}

def if_not_windows(a):
return select({
Expand Down Expand Up @@ -110,8 +109,8 @@ def grpc_cc_library(
testonly = testonly,
linkopts = linkopts,
includes = [
"include",
"src/core/ext/upb-generated", # Once upb code-gen issue is resolved, remove this.
"include",
"src/core/ext/upb-generated", # Once upb code-gen issue is resolved, remove this.
],
alwayslink = alwayslink,
data = data,
Expand Down Expand Up @@ -142,11 +141,12 @@ def grpc_proto_library(
use_external = use_external,
generate_mocks = generate_mocks,
)

def ios_cc_test(
name,
tags = [],
**kwargs):
ios_test_adapter = "//third_party/objective_c/google_toolbox_for_mac:GTM_GoogleTestRunner_GTM_USING_XCTEST";
ios_test_adapter = "//third_party/objective_c/google_toolbox_for_mac:GTM_GoogleTestRunner_GTM_USING_XCTEST"

test_lib_ios = name + "_test_lib_ios"
ios_tags = tags + ["manual", "ios_cc_test"]
Expand Down Expand Up @@ -186,7 +186,7 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
"exec_properties": exec_properties,
}
if uses_polling:
# the vanilla version of the test should run on platforms that only
# the vanilla version of the test should run on platforms that only
# support a single poller
native.cc_test(
name = name,
Expand All @@ -196,6 +196,7 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
]),
**args
)

# on linux we run the same test multiple times, once for each poller
for poller in POLLERS:
native.sh_test(
Expand Down Expand Up @@ -223,7 +224,6 @@ def grpc_cc_test(name, srcs = [], deps = [], external_deps = [], args = [], data
**args
)


def grpc_cc_binary(name, srcs = [], deps = [], external_deps = [], args = [], data = [], language = "C++", testonly = False, linkshared = False, linkopts = [], tags = []):
copts = []
if language.upper() == "C":
Expand Down Expand Up @@ -266,14 +266,15 @@ def grpc_sh_binary(name, srcs, data = []):
data = data,
)

def grpc_py_binary(name,
srcs,
data = [],
deps = [],
external_deps = [],
testonly = False,
python_version = "PY2",
**kwargs):
def grpc_py_binary(
name,
srcs,
data = [],
deps = [],
external_deps = [],
testonly = False,
python_version = "PY2",
**kwargs):
native.py_binary(
name = name,
srcs = srcs,
Expand Down Expand Up @@ -323,7 +324,7 @@ def grpc_objc_library(
deps: dependencies
visibility: visibility, default to public
"""

native.objc_library(
name = name,
hdrs = hdrs,
Expand All @@ -335,14 +336,12 @@ def grpc_objc_library(
includes = includes,
visibility = visibility,
)

def grpc_upb_proto_library(name, deps):
upb_proto_library(name = name, deps = deps)


def python_config_settings():
native.config_setting(
name = "python3",
flag_values = {"@bazel_tools//tools/python:python_version": "PY3"},
)

1 change: 0 additions & 1 deletion bazel/grpc_python_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,3 @@ def grpc_python_deps():
"https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz",
],
)

3 changes: 1 addition & 2 deletions bazel/objc_grpc_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ load(
"//bazel:generate_objc.bzl",
"generate_objc",
"generate_objc_hdrs",
"generate_objc_non_arc_srcs",
"generate_objc_srcs",
"generate_objc_non_arc_srcs"
)
load("//bazel:protobuf.bzl", "well_known_proto_libs")

Expand Down Expand Up @@ -66,4 +66,3 @@ def objc_grpc_library(name, deps, srcs = [], use_well_known_protos = False, **kw
],
**kwargs
)

2 changes: 1 addition & 1 deletion bazel/protobuf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def get_plugin_args(
"--{plugin_name}_out={dir_out}".format(
plugin_name = plugin_name,
dir_out = augmented_dir_out,
)
),
]

def _get_staged_proto_file(context, source_file):
Expand Down
Loading

0 comments on commit c34bef4

Please sign in to comment.