apache / arrow

Apache Arrow is the universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics
https://arrow.apache.org/
Apache License 2.0
14.68k stars 3.56k forks source link

C++ tests don't build due to googletest header conflict #39646

Open indigophox opened 10 months ago

indigophox commented 10 months ago

Describe the bug, including details regarding any error messages, version, and platform.

C++ googletest headers don't compile properly when a system version of googletest is present and a different version from the bundled one. This can be bodged around by clobbering the system headers, e.g. cp -R _deps/googletest-src/googlemock/include /opt/homebrew/Cellar/googletest/1.14.0/

Error behaviour looks like:

$ cmake --build .
[1/611] Building CXX object _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o
FAILED: _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o 
/opt/homebrew/bin/ccache /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DARROW_EXTRA_ERROR_CONTEXT -DARROW_HAVE_NEON -DARROW_WITH_TIMING_TESTS -DGTEST_CREATE_SHARED_LIBRARY=1 -Dgmock_EXPORTS -I/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include -I/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock -isystem /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googletest/include -isystem /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googletest -Qunused-arguments -fcolor-diagnostics -Wno-unused-value -Wno-ignored-attributes -g -Werror -O0 -ggdb  -Wno-error -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk -fPIC -Wall -Wshadow -Werror -Wconversion -DGTEST_HAS_PTHREAD=1 -fexceptions -W -Wpointer-arith -Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wredundant-decls -std=c++17 -MD -MT _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o -MF _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o.d -o _deps/googletest-build/googlemock/CMakeFiles/gmock.dir/src/gmock-all.cc.o -c /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/src/gmock-all.cc
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/src/gmock-all.cc:39:
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock.h:59:
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:342:5: error: unknown type name 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
    GTEST_DISALLOW_COPY_AND_ASSIGN_(FixedValueProducer);
    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:353:5: error: unknown type name 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
    GTEST_DISALLOW_COPY_AND_ASSIGN_(FactoryValueProducer);
    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:427:3: error: unknown type name 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
  GTEST_DISALLOW_COPY_AND_ASSIGN_(ActionInterface);
  ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:687:27: error: expected parameter declarator
    GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value,
                          ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:687:27: error: expected ')'
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:687:26: note: to match this '('
    GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value,
                         ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:687:5: error: a type specifier is required for all declarations
    GTEST_COMPILE_ASSERT_(!std::is_reference<Result>::value,
    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:694:5: error: unknown type name 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
    GTEST_DISALLOW_COPY_AND_ASSIGN_(Impl);
    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:659:9: error: use of undeclared identifier 'use_ReturnRef_instead_of_Return_to_return_a_reference'
        use_ReturnRef_instead_of_Return_to_return_a_reference);
        ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:763:27: error: use of undeclared identifier 'use_Return_instead_of_ReturnRef_to_return_a_value'
                          use_Return_instead_of_ReturnRef_to_return_a_value);
                          ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-actions.h:806:9: error: use of undeclared identifier 'use_Return_instead_of_ReturnRefOfCopy_to_return_a_value'
        use_Return_instead_of_ReturnRefOfCopy_to_return_a_value);
        ^
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/src/gmock-all.cc:39:
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock.h:61:
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-function-mocker.h:42:
In file included from /Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-spec-builders.h:75:
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:316:3: error: unknown type name 'GTEST_DISALLOW_COPY_AND_ASSIGN_'
  GTEST_DISALLOW_COPY_AND_ASSIGN_(StringMatchResultListener);
  ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:538:7: error: use of undeclared identifier 'cannot_convert_non_reference_arg_to_reference'
      cannot_convert_non_reference_arg_to_reference);
      ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:548:7: error: use of undeclared identifier 'conversion_of_arithmetic_types_must_be_lossless'
      conversion_of_arithmetic_types_must_be_lossless);
      ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:683:25: error: use of undeclared identifier 'matcher_and_value_have_different_numbers_of_fields'
                        matcher_and_value_have_different_numbers_of_fields);
                        ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:1168:53: error: use of undeclared identifier 'AnyEq'
class Eq2Matcher : public PairMatchBase<Eq2Matcher, AnyEq> {
                                                    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:1172:53: error: use of undeclared identifier 'AnyNe'
class Ne2Matcher : public PairMatchBase<Ne2Matcher, AnyNe> {
                                                    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:1176:53: error: use of undeclared identifier 'AnyLt'
class Lt2Matcher : public PairMatchBase<Lt2Matcher, AnyLt> {
                                                    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:1180:53: error: use of undeclared identifier 'AnyGt'
class Gt2Matcher : public PairMatchBase<Gt2Matcher, AnyGt> {
                                                    ^
/Users/pauln/git/arrow/cpp/session-management-build-debug-flight-sql/_deps/googletest-src/googlemock/include/gmock/gmock-matchers.h:1184:53: error: use of undeclared identifier 'AnyLe'
class Le2Matcher : public PairMatchBase<Le2Matcher, AnyLe> {
                                                    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
[2/611] Performing build step for 'jemalloc_ep'
ninja: build stopped: subcommand failed.

It appears to include the correct parent search paths for the gtest/ and gmock/ so I'm not clear on what's going off the rails where to allow the system headers to break things as above.

Component(s)

C++

amoeba commented 10 months ago

Can you share your CMake configure command? I've run into issues in the past on a Mac w/ googletest installed from homebrew and gotten around it with -DGTest_SOURCE=BUNDLED.

indigophox commented 10 months ago

Can you share your CMake configure command? I've run into issues in the past on a Mac w/ googletest installed from homebrew and gotten around it with -DGTest_SOURCE=BUNDLED.

Literally just --preset ninja-debug-flight-sql. I can try with that as well, I did see despite it being in the _deps build subdir it has its "bundled" option set to OFF in the CMakeFIle...

indigophox commented 10 months ago

Wow, I renamed the homebrew googletest include dir back and now I can't repro. Probably going to have to start from a clean Arrow checkout...

amoeba commented 10 months ago

I was able to get a successful build from that preset with googletest installed via brew. This reminds me of https://github.com/apache/arrow/issues/34523 and https://github.com/apache/arrow/issues/32487. Let us know if you can reproduce. In the mean time, @kou or @assignUser may have some ideas here too.

kou commented 10 months ago

I think that other dependencies added -I/opt/homebrew/include/ before -I_deps/googletest-src/googlemock/include. Could you share cmake --preset ninja-debug-flight-sql output and ninja -v result for the failed build?