This is an archive of the discontinued LLVM Phabricator instance.

[test] Fix LLDB tests with just-built libcxx when using a target directory.
ClosedPublic

Authored by rupprecht on Sep 15 2022, 1:56 PM.

Details

Summary

In certain configurations, libc++ headers all exist in the same directory, and libc++ binaries exist in the same directory as lldb libs. When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR is enabled (*and* the host is not Apple, which is why I assume this wasn't caught by others?), this is not the case: most headers will exist in the usual include/c++/v1 directory, but __config_site exists in include/$TRIPLE/c++/v1. Likewise, the libc++.so binary exists in lib/$TRIPLE/, not lib/ (where LLDB libraries reside).

This also adds the just-built-libcxx functionality to the lldb-dotest tool.

The LIBCXX_ cmake config is borrowed from libcxx/CMakeLists.txt. I could not figure out a way to share the cmake config; ideally we would reuse the same config instead of copy/paste.

Diff Detail

Event Timeline

rupprecht created this revision.Sep 15 2022, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 1:56 PM
Herald added a subscriber: mgorny. · View Herald Transcript
rupprecht requested review of this revision.Sep 15 2022, 1:56 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 15 2022, 1:56 PM
rupprecht edited the summary of this revision. (Show Details)Sep 15 2022, 1:59 PM

Do we need both LIBCPP_INCLUDE_DIR and LIBCPP_INCLUDE_TARGET_DIR? I see we pass another -cxx-isystem flag, does this result in another search path or does that replace the former? If we only need one, we could set LIBCPP_INCLUDE_DIR to libcxx_include_target_dir or libcxx_include_dir respectively.

Do we need both LIBCPP_INCLUDE_DIR and LIBCPP_INCLUDE_TARGET_DIR? I see we pass another -cxx-isystem flag, does this result in another search path or does that replace the former? If we only need one, we could set LIBCPP_INCLUDE_DIR to libcxx_include_target_dir or libcxx_include_dir respectively.

We need both. --libcxx_include_dir sets the regular include/c++/v1 dir, which contains almost all of libc++ headers. But __config_site is separately installed to include/$TRIPLE/c++/v1, so without it, all the build steps fail because it can't find #include <__config_site>. And include/$TRIPLE/c++/v1 only contains the __config_site file, so we can't use the target dir alone.

does this result in another search path or does that replace the former

I did some local testing and it seems to add another path.

fdeazeve added inline comments.Sep 16 2022, 7:26 AM
lldb/test/API/lit.cfg.py
176

Isn't this always going to return true? (same for is_configured (libcxx_include_target_dir)).

is_configured returns the empty string when the CMake variables are empty, and the empty string converts to True

rupprecht added inline comments.Sep 16 2022, 7:45 AM
lldb/test/API/lit.cfg.py
176

Since this is a python file, it should follow the python rules where an empty string is treated as false:

$ python3
Python 3.10.6 (main, Aug 10 2022, 11:19:32) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = ''
>>> 'foo' if x else 'bar'
'bar'
fdeazeve added inline comments.Sep 16 2022, 7:47 AM
lldb/test/API/lit.cfg.py
176

Oh, my bad. I had been bitten by if('0') in a similar context recently, so I was a bit paranoid here.

fdeazeve accepted this revision.Sep 16 2022, 10:44 AM

This LGTM and it worked without issues when I ran some tests on my machine, but please let @JDevlieghere have another look

This revision is now accepted and ready to land.Sep 16 2022, 10:44 AM
JDevlieghere accepted this revision.Sep 19 2022, 9:25 AM

LGTM

lldb/test/API/lit.cfg.py
178–179

Any reason you put this before adding config.libcxx_libs_dir below? Same question for lldb-dotest.

rupprecht added inline comments.Sep 20 2022, 9:53 AM
lldb/test/API/lit.cfg.py
178–179

I did this to group together the include-related args passed to dotest.py. It shouldn't be necessary, it just helps eyeballing the args to see if dotest.py is being invoked correctly.