Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source-file-location fails on macOS, giving 'unknown' #291

Closed
claremacrae opened this issue Jan 14, 2020 · 19 comments
Closed

Source-file-location fails on macOS, giving 'unknown' #291

claremacrae opened this issue Jan 14, 2020 · 19 comments

Comments

@claremacrae
Copy link
Contributor

Expected Behavior

The ApprovalTests.cpp UT integration tests pass with the latest version of this project on macOS.

This combination passes:

Actual Behavior

On macOS, with both g++9 homebrew and clang-9 MacPorts, using 515c080, the UT tests all fail with:

*****************************************************************************
*                                                                           *
* Welcome to Approval Tests.
*
* There seems to be a problem with your build configuration.
* We cannot find the test source file at:
*   unknown
*
* For details on how to fix this, please visit:
* https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredBuild.md
*                                                                           *
*****************************************************************************

Steps to Reproduce the Problem

Specifications

It's failing for me with:

CMAKE_VERSION = 3.16.2
CMAKE_GENERATOR = Unix Makefiles
CMAKE_SOURCE_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp
CMAKE_CURRENT_SOURCE_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp
CMAKE_CURRENT_BINARY_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-debug-g-9-brew
CMAKE_CXX_COMPILER = /usr/local/Cellar/gcc/9.2.0_2/bin/g++-9
CMAKE_CXX_COMPILER_ID = GNU
CMAKE_CXX_COMPILER_VERSION = 9.2.0
CMAKE_UNITY_BUILD = 

and

CMAKE_VERSION = 3.16.2
CMAKE_GENERATOR = Unix Makefiles
CMAKE_SOURCE_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp
CMAKE_CURRENT_SOURCE_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp
CMAKE_CURRENT_BINARY_DIR = /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-debug-clang-mp-90-brew
CMAKE_CXX_COMPILER = /opt/local/bin/clang++-mp-9.0
CMAKE_CXX_COMPILER_ID = Clang
CMAKE_CXX_COMPILER_VERSION = 9.0.1
CMAKE_UNITY_BUILD = 

Likely cause

There are not many differences between 8004290 and 515c080

I suspect that the cause is this, as in both compiler cases, __APPLE__ is defined:

@@ -211,10 +211,10 @@ namespace reflection {
 class source_location {
  public:
   [[nodiscard]] static constexpr auto current(
-#if (__GNUC__ >= 9 or __clang_major__ >= 9)
+#if ((__GNUC__ >= 9 or __clang_major__ >= 9) and not defined(__APPLE__))
       const char* file = __builtin_FILE(), int line = __builtin_LINE()
 #else
-      const char* file = {}, int line = {}
+      const char* file = "unknown", int line = {}
 #endif
           ) noexcept {
     source_location sl{};
krzysztof-jusiak added a commit that referenced this issue Jan 20, 2020
Problem:
- On macOS, with both g++9 homebrew and clang-9 MacPorts the UT tests all fail with `unknown`.

Solution:
- Fix detection of `source location` builtins.
  Use `__has_builtin` for clang based compilers.
  Enable it by default for GCC >= 9 (GCC HEAD has support for it).
  Disable it for MSVC which doesn't support these builtins yet.
krzysztof-jusiak added a commit that referenced this issue Jan 20, 2020
Problem:
- On macOS, with both g++9 homebrew and clang-9 MacPorts the UT tests all fail with `unknown`.

Solution:
- Fix detection of `source location` builtins.
  Use `__has_builtin` for clang based compilers.
  Enable it by default for GCC >= 9 (GCC HEAD has support for it).
  Disable it for MSVC which doesn't support these builtins yet.
@krzysztof-jusiak
Copy link
Contributor

Thanks, @claremacrae. It should be fixed by #293, would you please be able to check it 🤔 Thanks again 👍

@claremacrae
Copy link
Contributor Author

Awesome! Thanks very much.

Leave it with me... I've updated I'm getting compiler errors in our code - I think possibly because of warnings that ut turns on, though I'm not sure - so it'll take me a little while to fix them so I can check it...

@claremacrae
Copy link
Contributor Author

Hi @kris-jusiak

Summary: It's improved, but not quite there yet! It gives filenames with clang now, but not quite yet with gcc.

ut git commit id = bd458f1

With this config, my tests pass

CMAKE_VERSION = 3.16.2
CMAKE_GENERATOR = Unix Makefiles
CMAKE_CXX_COMPILER = /opt/local/bin/clang++-mp-9.0
CMAKE_CXX_COMPILER_ID = Clang
CMAKE_CXX_COMPILER_VERSION = 9.0.1
CMAKE_UNITY_BUILD = 

With this config, I get filename = 'unknown'

CMAKE_VERSION = 3.16.2
CMAKE_GENERATOR = Unix Makefiles
CMAKE_CXX_COMPILER = /usr/local/Cellar/gcc/9.2.0_2/bin/g++-9
CMAKE_CXX_COMPILER_ID = GNU
CMAKE_CXX_COMPILER_VERSION = 9.2.0
CMAKE_UNITY_BUILD = 

@krzysztof-jusiak
Copy link
Contributor

hmm, the following should work now, I think 🤔

#if not defined(__has_builtin)
#if (__GNUC__ >= 9)
#define __has___builtin_FILE 1
#define __has___builtin_LINE 1
#endif
#define __has_builtin(...) __has_##__VA_ARGS__
#endif

@claremacrae, can you check __GNUC__ for /usr/local/Cellar/gcc/9.2.0_2/bin/g++-9 and/or it has __has_builtin defined? It seems unusal for some reason 🤔

@claremacrae
Copy link
Contributor Author

    std::cout << "__GNUC__ " << __GNUC__ << '\n';
#if defined(__has_builtin)
    std::cout << "has __has_builtin\n";
#else
    std::cout << "NO __has_builtin\n";
#endif

Writes out:

__GNUC__ 9
has __has_builtin

@claremacrae
Copy link
Contributor Author

@kris-jusiak Is that what you meant?

Thanks for looking at this... I need to head off now.

If it helps, I'd be happy to pair on it, sharing screens... Wednesday, about 7pm UK time?

@claremacrae
Copy link
Contributor Author

Hi @kris-jusiak I'm unexpectedly free to pair for the next little while, if it helps -
If it works for you, or to arrange another time, feel free to email github@cfmacrae.fastmail.co.uk

@claremacrae
Copy link
Contributor Author

Hi @krzysztof-jusiak

Thanks for looking in to this. I just checked again, and this config is still giving filename unknown:

With this config, I get filename = 'unknown'

CMAKE_VERSION = 3.16.2
CMAKE_GENERATOR = Unix Makefiles
CMAKE_CXX_COMPILER = /usr/local/Cellar/gcc/9.2.0_2/bin/g++-9
CMAKE_CXX_COMPILER_ID = GNU
CMAKE_CXX_COMPILER_VERSION = 9.2.0
CMAKE_UNITY_BUILD = 

Was this info I posted above any use? I'm happy to work together on it, if it would help - as what was recently a working set-up for me with Boost.UT now no longer works...

Until then, I think it would be worth re-opening this ticket, please.

krzysztof-jusiak added a commit that referenced this issue Jan 25, 2020
…291

Problem:
- `gcc-9.2.0_2` defines `__has_builtin` however `__has_builtin(__builtin_FILE)` returns 0.

Solution:
- Set `__has___builtin_FILE` and `__has___builtin_FILE` to 1 in case of GCC-9 although `__has_builtin` is defined.
@krzysztof-jusiak
Copy link
Contributor

Hi @claremacrae, sorry for the late response on this one. I believe that gcc 9.2.0_2 has a bug because both: gcc-9 (I guess versions after 9.2.0_2) and gcc-10 seem to work properly 🤔

Anyway, added a wknd for gcc-9 which should fix the issue 🙏

@claremacrae
Copy link
Contributor Author

Hi @krzysztof-jusiak thanks very much for looking at this again!

Really sorry to be the bearer of bad news, but I downloaded the bug-fix, and got this compiler output:

====================[ Build | UT_Tests | Debug-g++-9-brew ]=====================
/opt/local/bin/cmake --build /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew --target UT_Tests -- -j 4
/opt/local/bin/cmake -S/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp -B/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew --check-build-system CMakeFiles/Makefile.cmake 0
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew/googletest-download
[ 11%] Performing update step for 'googletest'
[ 22%] No configure step for 'googletest'
[ 33%] No build step for 'googletest'
[ 44%] No install step for 'googletest'
[ 55%] No test step for 'googletest'
[ 66%] Completed 'googletest'
[100%] Built target googletest
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 UT_Tests
/opt/local/bin/cmake -S/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp -B/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew --check-build-system CMakeFiles/Makefile.cmake 0
/opt/local/bin/cmake -E cmake_progress_start /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew/CMakeFiles 2
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 tests/UT_Tests/CMakeFiles/UT_Tests.dir/all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f tests/UT_Tests/CMakeFiles/UT_Tests.dir/build.make tests/UT_Tests/CMakeFiles/UT_Tests.dir/depend
cd /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew && /opt/local/bin/cmake -E cmake_depends "Unix Makefiles" /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew/tests/UT_Tests /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew/tests/UT_Tests/CMakeFiles/UT_Tests.dir/DependInfo.cmake --color=
Scanning dependencies of target UT_Tests
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f tests/UT_Tests/CMakeFiles/UT_Tests.dir/build.make tests/UT_Tests/CMakeFiles/UT_Tests.dir/build
[ 50%] Building CXX object tests/UT_Tests/CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o
cd /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-gcc9-brew/tests/UT_Tests && /usr/local/Cellar/gcc/9.2.0_2/bin/g++-9  -DDUMMY_TEST_DEFINE -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/.. -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/third_party/ut/include  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -Wall -Wextra -Wpedantic -Werror -std=gnu++2a -o CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o -c /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests/ApprovalTestTests.cpp
In file included from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/integrations/ut/UTApprovals.h:15,
                 from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/ApprovalTests.hpp:28,
                 from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests/ApprovalTestTests.cpp:3:
/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/third_party/ut/include/boost/ut.hpp:48: error: "__has_builtin" redefined [-Werror]
   48 | #define __has_builtin(...) __has_##__VA_ARGS__
      | 
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/_types.h:32,
                 from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/_types.h:27,
                 from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h:70,
                 from /usr/local/Cellar/gcc/9.2.0_2/include/c++/9.2.0/cwchar:44,
                 from /usr/local/Cellar/gcc/9.2.0_2/include/c++/9.2.0/bits/postypes.h:40,
                 from /usr/local/Cellar/gcc/9.2.0_2/include/c++/9.2.0/bits/char_traits.h:40,
                 from /usr/local/Cellar/gcc/9.2.0_2/include/c++/9.2.0/string:40,
                 from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/Approvals.h:4,
                 from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/ApprovalTests.hpp:11,
                 from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests/ApprovalTestTests.cpp:3:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/cdefs.h:89: note: this is the location of the previous definition
   89 | #define __has_builtin(x) 0
      | 
cc1plus: all warnings being treated as errors
make[3]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o] Error 1
make[2]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/all] Error 2
make[1]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/rule] Error 2
make: *** [UT_Tests] Error 2

krzysztof-jusiak added a commit that referenced this issue Jan 25, 2020
…291

Problem:
- `gcc-9.2.0_2` defines `__has_builtin` however `__has_builtin(__builtin_FILE)` returns 0.

Solution:
- Set `__has___builtin_FILE` and `__has___builtin_FILE` to 1 in case of GCC-9 although `__has_builtin` is defined.
@claremacrae
Copy link
Contributor Author

In case it helps, this is the revision that worked: 8004290

When I ignore white-space changes, there aren't many differences between that and the latest one...

@krzysztof-jusiak
Copy link
Contributor

Thanks, @claremacrae, it's because APPLE defines

#define __has_builtin(x) 0

so __has_builtin is available but is always bogous 😞

Created another fix -> #296 🙏

@claremacrae
Copy link
Contributor Author

Oh no, sorry you are having to chase your tail on this...

That fixes gcc 9 - but I'm really very sad to report that it breaks clang 9:

[ 50%] Building CXX object tests/UT_Tests/CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o
cd /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/cmake-build-spaces/cmake-build-debug-clang-mp-90/tests/UT_Tests && /opt/local/bin/clang++-mp-9.0  -DDUMMY_TEST_DEFINE -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/.. -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests -I/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/third_party/ut/include  -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk   -Wall -Wextra -Wpedantic -Werror -Wno-c99-extensions -std=gnu++2a -o CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o -c /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests/ApprovalTestTests.cpp
In file included from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/tests/UT_Tests/ApprovalTestTests.cpp:3:
In file included from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/ApprovalTests.hpp:28:
In file included from /Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/ApprovalTests/../ApprovalTests/integrations/ut/UTApprovals.h:15:
/Users/clare/Documents/develop/ApprovalTests/ApprovalTests.cpp/third_party/ut/include/boost/ut.hpp:44:8: error: undefining builtin macro [-Werror,-Wbuiltin-macro-redefined]
#undef __has_builtin
       ^
1 error generated.
make[3]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/ApprovalTestTests.cpp.o] Error 1
make[2]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/all] Error 2
make[1]: *** [tests/UT_Tests/CMakeFiles/UT_Tests.dir/rule] Error 2
make: *** [UT_Tests] Error 2

@claremacrae
Copy link
Contributor Author

(my line numbers are 1 higher than yours, as I add a comment in with the git id of the version I've copied in...)

Do I need to just give up on the compiler versions I'm using and update them?

It feels like UT is living on the bleeding edge and maybe only those happy with using the very newest shiny things will tend to try it out - as it seems to be only me reporting problems with older compilers! 😢

@claremacrae
Copy link
Contributor Author

I've gotta go for today - thanks ever so much for your efforts! 😄

@krzysztof-jusiak
Copy link
Contributor

I'm committed to getting it working with gcc9 and apple.
I pushed another fix, hopefully, the last one, thanks for your help @claremacrae.

@claremacrae
Copy link
Contributor Author

Awesome - it works on my gcc 9.2.0 and clang 9.0.1! 🎉 😄

Huge thanks for persisting with this @krzysztof-jusiak 🙏

@claremacrae
Copy link
Contributor Author

This is the change I tested: 46a4f2e

@krzysztof-jusiak
Copy link
Contributor

Fantastic, thanks, @claremacrae 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants