mirror of
https://github.com/apache/impala.git
synced 2025-12-19 18:12:08 -05:00
IMPALA-9401: primitive include-what-you-use script and mappings
This is a cleaned up version of the script I used to run include-what-you-use on the Impala codebase. The helper script assumes you have built IWYU and have a Kudu source checkout, and can then run IWYU on the entire codebase. Some mappings files are used to improve the quality of the IWYU output. There are still incorrect recommendations made, but this is sufficient to fix many common issues. Change-Id: Iaf5f9ba865313afb0c581e6482514ef7f1c65367 Reviewed-on: http://gerrit.cloudera.org:8080/15552 Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
committed by
Impala Public Jenkins
parent
fc784f6e95
commit
2f53783b14
74
bin/iwyu/iwyu.sh
Executable file
74
bin/iwyu/iwyu.sh
Executable file
@@ -0,0 +1,74 @@
|
||||
#!/bin/bash
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
IMPALA_HOME=$(cd $(dirname "$0")/../.. && pwd)
|
||||
|
||||
usage() {
|
||||
echo "Usage: iwyu.sh"
|
||||
echo "This will run include-what-you-use on the Impala codebase."
|
||||
echo "Results are printed to stdout"
|
||||
echo "The following environment variables must be set:"
|
||||
echo " KUDU_SOURCE: the root directory of a Kudu source tree"
|
||||
echo " IWYU_BUILD_DIR: the root directory of a IWYU build tree"
|
||||
echo " IWYU_SOURCE: the root directory of a IWYU source tree"
|
||||
echo ""
|
||||
echo "See IMPALA-9371 for one way to build IWYU for toolchain clang."
|
||||
echo ""
|
||||
echo "Example Invocation:"
|
||||
echo " KUDU_SOURCE=~/kudu IWYU_SOURCE=~/include-what-you-use \\"
|
||||
echo " IWYU_BUILD_DIR=~/include-what-you-use/build \\"
|
||||
echo " \$IMPALA_HOME/bin/iwyu/iwyu.sh"
|
||||
}
|
||||
|
||||
if [[ ! -v KUDU_SOURCE || ! -d "$KUDU_SOURCE" ]]; then
|
||||
echo "KUDU_SOURCE must be set to a Kudu source directory"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -v IWYU_BUILD_DIR || ! -d "$IWYU_BUILD_DIR" ]]; then
|
||||
echo "IWYU_BUILD_DIR must be set to a IWYU build directory"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -v IWYU_SOURCE || ! -d "$IWYU_SOURCE" ]]; then
|
||||
echo "IWYU_SOURCE must be set to a IWYU source directory"
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$IMPALA_HOME/compile_commands.json" ]]; then
|
||||
echo "$IMPALA_HOME/compile_commands.json is required for IWYU."
|
||||
echo "Please run buildall.sh (or CMake directly) to generate it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
IWYU_ARGS="--mapping_file=iwyu_mappings.imp"
|
||||
|
||||
# Make use of Kudu's pre-existing mappings files that are relevant.
|
||||
# TODO: consider importing into Impala codebase.
|
||||
for FILE in gflags.imp gtest.imp kudu.imp libstdcpp.imp libunwind.imp system-linux.imp; do
|
||||
IWYU_ARGS+=" --mapping_file=$KUDU_SOURCE/build-support/iwyu/mappings/${FILE}"
|
||||
done
|
||||
|
||||
cd "$IMPALA_HOME"
|
||||
PATH=$IWYU_BUILD_DIR:$PATH $IWYU_SOURCE/iwyu_tool.py -p . -j $(nproc) -- $IWYU_ARGS
|
||||
43
bin/iwyu/iwyu_mappings.imp
Normal file
43
bin/iwyu/iwyu_mappings.imp
Normal file
@@ -0,0 +1,43 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you 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.
|
||||
|
||||
# Custom IWYU rules for the Impala codebase to reflect the codebase's preferred headers
|
||||
# and to work around any quirks of IWYU's recommendations.
|
||||
[
|
||||
{ include: ["<boost/smart_ptr/scoped_ptr.hpp>", private, "<boost/scoped_ptr.hpp>", public ] },
|
||||
{ include: ["<boost/smart_ptr/shared_ptr.hpp>", private, "<boost/shared_ptr.hpp>", public ] },
|
||||
{ include: ["<boost/unordered/unordered_set.hpp>", private, "<boost/unordered_set.hpp>", public ] },
|
||||
{ include: ["<boost/unordered/unordered_map.hpp>", private, "<boost/unordered_map.hpp>", public ] },
|
||||
{ include: ["<boost/bind/bind.hpp>", private, "<boost/bind.hpp>", public ] },
|
||||
{ include: ["<boost/bind/placeholders.hpp>", private, "<boost/bind.hpp>", public ] },
|
||||
{ include: ["<bits/stdint-intn.h>", private, "<cstdint>", public ] },
|
||||
{ include: ["<bits/stdint-uintn.h>", private, "<cstdint>", public ] },
|
||||
{ include: ["<glog/logging.h>", private, "\"common/logging.h\"", public ] },
|
||||
{ include: ["<hdfs.h>", private, "\"common/hdfs.h\"", public ] },
|
||||
{ symbol: ["string", private, "<string>", public] },
|
||||
{ symbol: ["ostream", private, "<ostream>", public] },
|
||||
{ symbol: [ "LOG", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "VLOG", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "CHECK_EQ", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "CHECK_NE", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "CHECK_LT", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "CHECK_GE", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "CHECK_GT", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "ErrnoLogMessage", private, "\"common/logging.h\"", public ] },
|
||||
{ symbol: [ "COMPACT_GOOGLE_LOG_0", private, "\"common/logging.h\"", public ] }
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user