You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2020/03/29 06:37:32 UTC

[impala] 02/02: IMPALA-9401: primitive include-what-you-use script and mappings

This is an automated email from the ASF dual-hosted git repository.

tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git

commit 2f53783b14ddf215a4c96bc52a511d3a83896128
Author: Tim Armstrong <ta...@cloudera.com>
AuthorDate: Wed Feb 26 19:46:18 2020 -0800

    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 <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 bin/iwyu/iwyu.sh           | 74 ++++++++++++++++++++++++++++++++++++++++++++++
 bin/iwyu/iwyu_mappings.imp | 43 +++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)

diff --git a/bin/iwyu/iwyu.sh b/bin/iwyu/iwyu.sh
new file mode 100755
index 0000000..f5cd4ea
--- /dev/null
+++ b/bin/iwyu/iwyu.sh
@@ -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
diff --git a/bin/iwyu/iwyu_mappings.imp b/bin/iwyu/iwyu_mappings.imp
new file mode 100644
index 0000000..e44d958
--- /dev/null
+++ b/bin/iwyu/iwyu_mappings.imp
@@ -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 ] }
+]
+