You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2023/06/21 02:46:43 UTC

[arrow] branch main updated: GH-36157: [C++][Dev] Add support for using python3 to run IWYU (#36159)

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

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 35fd769578 GH-36157: [C++][Dev] Add support for using python3 to run IWYU (#36159)
35fd769578 is described below

commit 35fd76957871d6e647bdf4a36ce1ab8f2c8df9c2
Author: Sutou Kouhei <ko...@clear-code.com>
AuthorDate: Wed Jun 21 11:46:37 2023 +0900

    GH-36157: [C++][Dev] Add support for using python3 to run IWYU (#36159)
    
    ### Rationale for this change
    
    Python executable name is hard-corded in `cpp/build-support/iwyu/iwyu.sh`. If a developer uses `python3` for Python executable, the developer can't use the script.
    
    ### What changes are included in this PR?
    
    Add support for customizing Python executable name (and path) by `PYTHON` environment variable like other scripts.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * Closes: #36157
    
    Authored-by: Sutou Kouhei <ko...@clear-code.com>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 cpp/CMakeLists.txt             | 15 +++++++++++++--
 cpp/build-support/iwyu/iwyu.sh |  8 ++++----
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/cpp/CMakeLists.txt b/cpp/CMakeLists.txt
index c81427058c..bd2238789a 100644
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -344,8 +344,19 @@ if(${CLANG_TIDY_FOUND})
 endif()
 
 if(UNIX)
-  add_custom_target(iwyu ${BUILD_SUPPORT_DIR}/iwyu/iwyu.sh)
-  add_custom_target(iwyu-all ${BUILD_SUPPORT_DIR}/iwyu/iwyu.sh all)
+  add_custom_target(iwyu
+                    ${CMAKE_COMMAND}
+                    -E
+                    env
+                    "PYTHON=${PYTHON_EXECUTABLE}"
+                    ${BUILD_SUPPORT_DIR}/iwyu/iwyu.sh)
+  add_custom_target(iwyu-all
+                    ${CMAKE_COMMAND}
+                    -E
+                    env
+                    "PYTHON=${PYTHON_EXECUTABLE}"
+                    ${BUILD_SUPPORT_DIR}/iwyu/iwyu.sh
+                    all)
 endif(UNIX)
 
 # datetime code used by iOS requires zlib support
diff --git a/cpp/build-support/iwyu/iwyu.sh b/cpp/build-support/iwyu/iwyu.sh
index 55e39d772a..58ffce0c35 100755
--- a/cpp/build-support/iwyu/iwyu.sh
+++ b/cpp/build-support/iwyu/iwyu.sh
@@ -49,8 +49,8 @@ affected_files() {
 include-what-you-use --version
 
 if [[ "${1:-}" == "all" ]]; then
-    python $ROOT/cpp/build-support/iwyu/iwyu_tool.py -p ${IWYU_COMPILATION_DATABASE_PATH:-.} \
-        -- $IWYU_ARGS | awk -f $ROOT/cpp/build-support/iwyu/iwyu-filter.awk
+  ${PYTHON:-python3} $ROOT/cpp/build-support/iwyu/iwyu_tool.py -p ${IWYU_COMPILATION_DATABASE_PATH:-.} \
+      -- $IWYU_ARGS | awk -f $ROOT/cpp/build-support/iwyu/iwyu-filter.awk
 elif [[ "${1:-}" == "match" ]]; then
   ALL_FILES=
   IWYU_FILE_LIST=
@@ -61,7 +61,7 @@ elif [[ "${1:-}" == "match" ]]; then
   done
 
   echo "Running IWYU on $IWYU_FILE_LIST"
-  python $ROOT/cpp/build-support/iwyu/iwyu_tool.py \
+  ${PYTHON:-python3} $ROOT/cpp/build-support/iwyu/iwyu_tool.py \
       -p ${IWYU_COMPILATION_DATABASE_PATH:-.} $IWYU_FILE_LIST  -- \
        $IWYU_ARGS | awk -f $ROOT/cpp/build-support/iwyu/iwyu-filter.awk
 else
@@ -78,7 +78,7 @@ else
     IWYU_FILE_LIST="$IWYU_FILE_LIST $ROOT/$p"
   done
 
-  python $ROOT/cpp/build-support/iwyu/iwyu_tool.py \
+  ${PYTHON:-python3} $ROOT/cpp/build-support/iwyu/iwyu_tool.py \
       -p ${IWYU_COMPILATION_DATABASE_PATH:-.} $IWYU_FILE_LIST  -- \
        $IWYU_ARGS | awk -f $ROOT/cpp/build-support/iwyu/iwyu-filter.awk > $IWYU_LOG
 fi