Merge "Add clang-tidy.sh to filter out troublesome flags."
am: a644fbfa2c
Change-Id: I79f64979576431e85d6196110615450da1c4eea3
This commit is contained in:
@@ -150,10 +150,12 @@ var (
|
|||||||
},
|
},
|
||||||
"crossCompile")
|
"crossCompile")
|
||||||
|
|
||||||
|
_ = pctx.SourcePathVariable("tidyPath", "build/soong/scripts/clang-tidy.sh")
|
||||||
|
|
||||||
clangTidy = pctx.AndroidStaticRule("clangTidy",
|
clangTidy = pctx.AndroidStaticRule("clangTidy",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: "rm -f $out && ${config.ClangBin}/clang-tidy $tidyFlags $in -- $cFlags && touch $out",
|
Command: "rm -f $out && CLANG_TIDY=${config.ClangBin}/clang-tidy $tidyPath $tidyFlags $in -- $cFlags && touch $out",
|
||||||
CommandDeps: []string{"${config.ClangBin}/clang-tidy"},
|
CommandDeps: []string{"${config.ClangBin}/clang-tidy", "$tidyPath"},
|
||||||
},
|
},
|
||||||
"cFlags", "tidyFlags")
|
"cFlags", "tidyFlags")
|
||||||
|
|
||||||
|
@@ -19,18 +19,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// clang-tidy doesn't recognize every flag that clang does. This is unlikely to
|
|
||||||
// be a complete list, but we can populate this with the ones we know to avoid
|
|
||||||
// issues with clang-diagnostic-unused-command-line-argument.
|
|
||||||
// b/111885396: -flto affected header include directory;
|
|
||||||
// -fsanitize and -fwhole-program-vtables need -flto.
|
|
||||||
var ClangTidyUnknownCflags = sorted([]string{
|
|
||||||
"-Wa,%",
|
|
||||||
"-flto",
|
|
||||||
"-fsanitize=%",
|
|
||||||
"-fwhole-program-vtables",
|
|
||||||
})
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// Most Android source files are not clang-tidy clean yet.
|
// Most Android source files are not clang-tidy clean yet.
|
||||||
// Global tidy checks include only google*, performance*,
|
// Global tidy checks include only google*, performance*,
|
||||||
@@ -42,6 +30,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
"-*",
|
"-*",
|
||||||
|
"clang-diagnostic-unused-command-line-argument",
|
||||||
"google*",
|
"google*",
|
||||||
"misc-macro-parentheses",
|
"misc-macro-parentheses",
|
||||||
"performance*",
|
"performance*",
|
||||||
@@ -58,6 +47,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
"-*",
|
"-*",
|
||||||
|
"clang-diagnostic-unused-command-line-argument",
|
||||||
"google*",
|
"google*",
|
||||||
"-google-build-using-namespace",
|
"-google-build-using-namespace",
|
||||||
"-google-default-arguments",
|
"-google-default-arguments",
|
||||||
|
@@ -75,7 +75,6 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
|||||||
ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
|
ctx.Strict("LLVM_OBJCOPY", "${config.ClangBin}/llvm-objcopy")
|
||||||
ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
|
ctx.Strict("LLVM_STRIP", "${config.ClangBin}/llvm-strip")
|
||||||
ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
|
ctx.Strict("PATH_TO_CLANG_TIDY", "${config.ClangBin}/clang-tidy")
|
||||||
ctx.Strict("CLANG_TIDY_UNKNOWN_CFLAGS", strings.Join(config.ClangTidyUnknownCflags, " "))
|
|
||||||
ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
|
ctx.StrictSorted("CLANG_CONFIG_UNKNOWN_CFLAGS", strings.Join(config.ClangUnknownCflags, " "))
|
||||||
|
|
||||||
ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
|
ctx.Strict("RS_LLVM_PREBUILTS_VERSION", "${config.RSClangVersion}")
|
||||||
|
37
scripts/clang-tidy.sh
Executable file
37
scripts/clang-tidy.sh
Executable file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash -e
|
||||||
|
|
||||||
|
# Copyright 2018 Google Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
# Wrapper script to remove clang compiler flags rejected by clang-tidy.
|
||||||
|
# Inputs:
|
||||||
|
# Environment:
|
||||||
|
# CLANG_TIDY: path to the real clang-tidy program
|
||||||
|
|
||||||
|
# clang-tidy doesn't recognize every flag that clang compiler does.
|
||||||
|
# It gives clang-diagnostic-unused-command-line-argument warnings
|
||||||
|
# to -Wa,* flags.
|
||||||
|
# The -flto flags caused clang-tidy to ignore the -I flags,
|
||||||
|
# see https://bugs.llvm.org/show_bug.cgi?id=38332.
|
||||||
|
# -fsanitize and -fwhole-program-vtables need -flto.
|
||||||
|
args=("${@}")
|
||||||
|
n=${#args[@]}
|
||||||
|
for ((i=0; i<$n; ++i)); do
|
||||||
|
case ${args[i]} in
|
||||||
|
-Wa,*|-flto|-flto=*|-fsanitize=*|-fsanitize-*|-fwhole-program-vtables)
|
||||||
|
unset args[i]
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
${CLANG_TIDY} "${args[@]}"
|
Reference in New Issue
Block a user