提交 482a39f4 编写于 作者: S storypku

Format: buildify tools/cpplint.bzl and fix buildifier call

上级 52f3087b
......@@ -456,7 +456,7 @@ function clean() {
}
function buildify() {
find . -name '*BUILD' -or -name '*.bzl' -type f -exec buildifier -showlog -mode=fix {} +
find . -name '*BUILD' -or -name '*.bzl' -type f -exec buildifier -mode=fix {} +
if [ $? -eq 0 ]; then
success 'Buildify worked!'
else
......
......@@ -20,65 +20,72 @@ _EXTENSIONS_ARGS = ["--extensions=" + ",".join(
)]
def _extract_labels(srcs):
"""Convert a srcs= or hdrs= value to its set of labels."""
# Tuples are already labels.
if type(srcs) == type(()):
return list(srcs)
return []
"""Convert a srcs= or hdrs= value to its set of labels."""
def _is_source_label(label):
for extension in _SOURCE_EXTENSIONS:
if label.endswith(extension):
return True
return False
# Tuples are already labels.
if type(srcs) == type(()):
return list(srcs)
return []
def _add_linter_rules(source_labels, source_filenames, name, data=None):
# Common attributes for all of our py_test invocations.
data = (data or [])
size = "small"
tags = ["cpplint"]
def _is_source_label(label):
for extension in _SOURCE_EXTENSIONS:
if label.endswith(extension):
return True
return False
# Google cpplint.
cpplint_cfg = ["//:CPPLINT.cfg"] + native.glob(['CPPLINT.cfg'])
native.py_test(
name = name + "_cpplint",
srcs = ["@cpplint//:cpplint"],
data = data + cpplint_cfg + source_labels,
args = _EXTENSIONS_ARGS + source_filenames,
main = "cpplint.py",
size = size,
tags = tags,
)
def _add_linter_rules(source_labels, source_filenames, name, data = None):
# Common attributes for all of our py_test invocations.
data = (data or [])
size = "small"
tags = ["cpplint"]
def cpplint(data=None, extra_srcs=None):
"""For every rule in the BUILD file so far, adds a test rule that runs
cpplint over the C++ sources listed in that rule. Thus, BUILD file authors
should call this function at the *end* of every C++-related BUILD file.
By default, only the CPPLINT.cfg from the project root and the current
directory are used. Additional configs can be passed in as data labels.
Sources that are not discoverable through the "sources so far" heuristic can
be passed in as extra_srcs=[].
"""
# Iterate over all rules.
for rule in native.existing_rules().values():
# Extract the list of C++ source code labels and convert to filenames.
candidate_labels = (
_extract_labels(rule.get("srcs", ())) +
_extract_labels(rule.get("hdrs", ()))
# Google cpplint.
cpplint_cfg = ["//:CPPLINT.cfg"] + native.glob(["CPPLINT.cfg"])
native.py_test(
name = name + "_cpplint",
srcs = ["@cpplint//:cpplint"],
data = data + cpplint_cfg + source_labels,
args = _EXTENSIONS_ARGS + source_filenames,
main = "cpplint.py",
size = size,
tags = tags,
)
source_labels = [
label for label in candidate_labels
if _is_source_label(label)
]
source_filenames = ["$(location %s)" % x for x in source_labels]
# Run the cpplint checker as a unit test.
if len(source_filenames) > 0:
_add_linter_rules(source_labels, source_filenames, rule["name"], data)
def cpplint(data = None, extra_srcs = None):
"""For every rule in the BUILD file so far, adds a test rule that runs
cpplint over the C++ sources listed in that rule. Thus, BUILD file authors
should call this function at the *end* of every C++-related BUILD file.
By default, only the CPPLINT.cfg from the project root and the current
directory are used. Additional configs can be passed in as data labels.
Sources that are not discoverable through the "sources so far" heuristic can
be passed in as extra_srcs=[].
"""
# Iterate over all rules.
for rule in native.existing_rules().values():
# Extract the list of C++ source code labels and convert to filenames.
candidate_labels = (
_extract_labels(rule.get("srcs", ())) +
_extract_labels(rule.get("hdrs", ()))
)
source_labels = [
label
for label in candidate_labels
if _is_source_label(label)
]
source_filenames = ["$(location %s)" % x for x in source_labels]
# Run the cpplint checker as a unit test.
if len(source_filenames) > 0:
_add_linter_rules(source_labels, source_filenames, rule["name"], data)
# Lint all of the extra_srcs separately in a single rule.
if extra_srcs:
source_labels = extra_srcs
source_filenames = ["$(location %s)" % x for x in source_labels]
_add_linter_rules(source_labels, source_filenames,
"extra_srcs_cpplint", data)
# Lint all of the extra_srcs separately in a single rule.
if extra_srcs:
source_labels = extra_srcs
source_filenames = ["$(location %s)" % x for x in source_labels]
_add_linter_rules(
source_labels,
source_filenames,
"extra_srcs_cpplint",
data,
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册