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

thisisnic pushed a commit to branch maint-15.0.0-r
in repository https://gitbox.apache.org/repos/asf/arrow.git

commit 6bb2f2cebfb5c7ebf160dd79b16ecd5805f4d8c5
Author: Jonathan Keane <[email protected]>
AuthorDate: Wed Feb 28 17:24:32 2024 -0600

    GH-40248: [R] fallback to the correct libtool when we find a GNU one 
(#40259)
    
    ### Rationale for this change
    
    On the CRAN build machines the GNU libtool is on the path in front of the 
macOS libtool. Though these are named the same thing, they are actually very 
different and don't actually appear to be substitutes
    
    I checked on a non-developer's machine to see if `/usr/bin/libtool` exists, 
and it did. So I believe we _should_ be ok with this even if xcode / command 
line tools haven't been installed.
    
    One note: it's possible that we could get the GNU libtool in link mode to 
work with the right incantation (something like `libtool --mode=link --tag=CXX 
${cmake_compiler} -o ...` but when I tried this I kept getting symbol not found 
errors. Ultimately, I think any mac that we are on will have the apple-provided 
libtool, so decided to go the route of finding it.
    
    ### What changes are included in this PR?
    
    When we detect we are on a GNU libtool, we look to `/usr/bin/libtool` 
instead.
    
    ### Are these changes tested?
    
    Yes. See a broken config failing at 
https://github.com/apache/arrow/pull/40259#issuecomment-1967762074 and then the 
next one passes
    
    ### Are there any user-facing changes?
    
    We will remain on CRAN
    
    **This PR contains a "Critical Fix".**
    * GitHub Issue: #40248
    
    Lead-authored-by: Jonathan Keane <[email protected]>
    Co-authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Jonathan Keane <[email protected]>
---
 cpp/cmake_modules/BuildUtils.cmake       | 22 +++++++++++++++++++++-
 dev/tasks/r/github.macos-linux.local.yml | 12 ++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/cpp/cmake_modules/BuildUtils.cmake 
b/cpp/cmake_modules/BuildUtils.cmake
index 083ac2fe9a..7a45e9cca5 100644
--- a/cpp/cmake_modules/BuildUtils.cmake
+++ b/cpp/cmake_modules/BuildUtils.cmake
@@ -97,7 +97,27 @@ function(arrow_create_merged_static_lib output_target)
   endforeach()
 
   if(APPLE)
-    set(BUNDLE_COMMAND "libtool" "-no_warning_for_no_symbols" "-static" "-o"
+    # The apple-distributed libtool is what we want for bundling, but there is
+    # a GNU libtool that has a namecollision (and happens to be bundled with 
R, too).
+    # We are not compatible with GNU libtool, so we need to avoid it.
+
+    # check in the obvious places first to find Apple's libtool
+    # HINTS is used before system paths and before PATHS, so we use that
+    # even though hard coded paths should go in PATHS
+    # TODO: use a VALIDATOR when we require cmake >= 3.25
+    find_program(LIBTOOL_MACOS libtool HINTS /usr/bin
+                                             
/Library/Developer/CommandLineTools/usr/bin)
+
+    # confirm that the libtool we found is not GNU libtool
+    execute_process(COMMAND ${LIBTOOL_MACOS} -V
+                    OUTPUT_VARIABLE LIBTOOL_V_OUTPUT
+                    OUTPUT_STRIP_TRAILING_WHITESPACE)
+    if(NOT "${LIBTOOL_V_OUTPUT}" MATCHES ".*cctools-([0-9.]+).*")
+      message(FATAL_ERROR "libtool found appears to be the incompatible GNU 
libtool: ${LIBTOOL_MACOS}"
+      )
+    endif()
+
+    set(BUNDLE_COMMAND ${LIBTOOL_MACOS} "-no_warning_for_no_symbols" "-static" 
"-o"
                        ${output_lib_path} ${all_library_paths})
   elseif(CMAKE_CXX_COMPILER_ID MATCHES "^(Clang|GNU|Intel|IntelLLVM)$")
     set(ar_script_path ${CMAKE_BINARY_DIR}/${ARG_NAME}.ar)
diff --git a/dev/tasks/r/github.macos-linux.local.yml 
b/dev/tasks/r/github.macos-linux.local.yml
index 045c387b73..b221e8c5d8 100644
--- a/dev/tasks/r/github.macos-linux.local.yml
+++ b/dev/tasks/r/github.macos-linux.local.yml
@@ -58,6 +58,18 @@ jobs:
       - uses: r-lib/actions/setup-r@v2
         with:
           use-public-rspm: true
+      # CRAN builders have the entire bin here added to the path. This 
sometimes
+      # includes things like GNU libtool which name-collide with what we expect
+      - name: Add R.framework/Resources/bin to the path
+        if: contains(matrix.os, 'macOS')
+        run: echo "/Library/Frameworks/R.framework/Resources/bin" >> 
$GITHUB_PATH
+      - name : Check whether libtool in R is used
+        if: contains(matrix.os, 'macOS')
+        run: |
+          if [ "$(which libtool)" != 
"/Library/Frameworks/R.framework/Resources/bin/libtool" ]; then
+            echo "libtool provided by R isn't found: $(which libtool)"
+            exit 1
+          fi
       - name: Install dependencies
         uses: r-lib/actions/setup-r-dependencies@v2
         with:

Reply via email to