This is an archive of the discontinued LLVM Phabricator instance.

clang/cmake: Fix incorrectly disabling tests when LLVM_EXTERNAL_LIT is used
Needs RevisionPublic

Authored by tstellar on Nov 17 2022, 9:39 PM.

Details

Summary

This fixes a bug where tests would be disabled when LLVM_EXTERNAL_LIT
was set if lit couldn't be found in any of the standard search paths.

Diff Detail

Event Timeline

tstellar created this revision.Nov 17 2022, 9:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 9:39 PM
tstellar requested review of this revision.Nov 17 2022, 9:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 17 2022, 9:39 PM
phosek accepted this revision.Nov 17 2022, 11:55 PM

LGTM

This revision is now accepted and ready to land.Nov 17 2022, 11:55 PM
mgorny added inline comments.Nov 17 2022, 11:56 PM
clang/CMakeLists.txt
97

I don't think you need to do this if you rename the var, find_program() doesn't seem to do any searching when the var is already set.

I've tested with a dummy CMakeLists:

set(FOO /bin/true)
find_program(FOO NAMES foo)
message(FATAL_ERROR ${FOO})

gives /bin/true for me.

kwk requested changes to this revision.EditedNov 18 2022, 1:58 AM
kwk added a subscriber: kwk.

As much as I would like this to be fixed. I vote against this patch because in lld/CMakeLists.txt there's an almost (if not entirely) identical piece of code that screams to be outsourced into a /cmake/Modules/FindLit.cmake (to be created). I'll have a look at this and see if I can come up with a patch for this. Afterall /cmake is the central place to distribute shared CMake code between subprojects, right @phosek (didn't you create /cmake in the first place)?

Alternatively, we can copy the code from lld/CMakeLists.txt and outsource it afterwards so that the shared code becomes more obvious.

If there're any objections regarding outsourcing to FindLit.cmake, then I would only ask to copy the code from lld/CMakeLists.txt. There the find_program part sits below the if block.

clang/CMakeLists.txt
97

I don't think you need to do this if you rename the var, find_program() doesn't seem to do any searching when the var is already set.

This might be true but it is counter intuitive to assume that find_program does nothing. So for readability I'd keep the if (NOT LLVM_EXTERNAL_LIT). I know it is not needed but with the if it won't look like find_program(LLVM_EXTERNAL_LIT is the only/central place to set the variable LLVM_EXTERNAL_LIT. With the guard around it, it becomes more obvious that this is more of a fallback.

This revision now requires changes to proceed.Nov 18 2022, 1:58 AM

As much as I would like this to be fixed. I vote against this patch because in lld/CMakeLists.txt there's an almost (if not entirely) identical piece of code that screams to be outsourced into a /cmake/Modules/FindLit.cmake (to be created). I'll have a look at this and see if I can come up with a patch for this. Afterall /cmake is the central place to distribute shared CMake code between subprojects, right @phosek (didn't you create /cmake in the first place)?

My eventual goal is to move this out into a separate CMake file, but I was hoping to simplify the code first before doing this.

tstellar added inline comments.Nov 18 2022, 9:31 AM
clang/CMakeLists.txt
97

@mgorny The documentation confirms this too:

"Once one of the calls succeeds the result variable will be set and stored in the cache so that no call will search again."