Skip to content

[lldb] Use add_custom_command for SBLanguages.h #91254

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

Merged
merged 1 commit into from
May 6, 2024

Conversation

JDevlieghere
Copy link
Member

Use add_custom_command instead of add_custom_target to generate SBLanguages.h.

Use add_custom_command instead of add_custom_target to generate
SBLanguages.h.
@llvmbot llvmbot added the lldb label May 6, 2024
@llvmbot
Copy link
Member

llvmbot commented May 6, 2024

@llvm/pr-subscribers-lldb

Author: Jonas Devlieghere (JDevlieghere)

Changes

Use add_custom_command instead of add_custom_target to generate SBLanguages.h.


Full diff: https://github.com/llvm/llvm-project/pull/91254.diff

1 Files Affected:

  • (modified) lldb/source/API/CMakeLists.txt (+5-7)
diff --git a/lldb/source/API/CMakeLists.txt b/lldb/source/API/CMakeLists.txt
index a64c0d4a333425..798a92874f13d1 100644
--- a/lldb/source/API/CMakeLists.txt
+++ b/lldb/source/API/CMakeLists.txt
@@ -23,13 +23,13 @@ endif()
 # Target to generate SBLanguages.h from Dwarf.def.
 set(sb_languages_file
   ${CMAKE_CURRENT_BINARY_DIR}/../../include/lldb/API/SBLanguages.h)
-add_custom_target(
-  lldb-sbapi-dwarf-enums
-  "${Python3_EXECUTABLE}"
+add_custom_command(
+  COMMENT "Generating SBLanguages.h from Dwarf.def"
+  COMMAND "${Python3_EXECUTABLE}"
       ${LLDB_SOURCE_DIR}/scripts/generate-sbapi-dwarf-enum.py
       ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
       -o ${sb_languages_file}
-  BYPRODUCTS ${sb_languages_file}
+  OUTPUT ${sb_languages_file}
   DEPENDS ${LLVM_MAIN_INCLUDE_DIR}/llvm/BinaryFormat/Dwarf.def
   WORKING_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
 )
@@ -113,9 +113,7 @@ add_lldb_library(liblldb SHARED ${option_framework}
   SystemInitializerFull.cpp
   ${lldb_python_wrapper}
   ${lldb_lua_wrapper}
-
-  DEPENDS
-    lldb-sbapi-dwarf-enums
+  ${sb_languages_file}
 
   LINK_LIBS
     lldbBreakpoint

@bulbazord
Copy link
Member

This should work if there is exactly one thing that depends on the output of this custom command. If multiple things start depending on the generated files, you may end up with weird results. See:

https://cmake.org/cmake/help/latest/command/add_custom_command.html

Do not list the output in more than one independent target that may build in parallel or the instances of the rule may conflict. Instead, use the add_custom_target() command to drive the command and make the other targets depend on that one. See the Example: Generating Files for Multiple Targets below.

@JDevlieghere
Copy link
Member Author

Good point. I can't imagine anything needing the SB header that doesn't need the rest of the framework, but if that's the case we go through a custom target.

@JDevlieghere JDevlieghere merged commit 3809e20 into llvm:main May 6, 2024
6 checks passed
@JDevlieghere JDevlieghere deleted the add_custom_command branch May 6, 2024 21:43
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request May 7, 2024
Use add_custom_command instead of add_custom_target to generate
SBLanguages.h.

(cherry picked from commit 3809e20)
@labath
Copy link
Collaborator

labath commented May 7, 2024

thanks

JDevlieghere added a commit that referenced this pull request May 7, 2024
Alex pointed out in #91254 that we only need the custom target if we had
more than one target depending on it. This isn't the case upstream, but
on our downstream fork, we have a second dependency. Reintroduce the
target so that everything can depend on that, without the
single-dependency foot-gun.
JDevlieghere added a commit to swiftlang/llvm-project that referenced this pull request May 7, 2024
Alex pointed out in llvm#91254 that we only need the custom target if we had
more than one target depending on it. This isn't the case upstream, but
on our downstream fork, we have a second dependency. Reintroduce the
target so that everything can depend on that, without the
single-dependency foot-gun.

(cherry picked from commit dad1109)
adrian-prantl added a commit to swiftlang/llvm-project that referenced this pull request May 8, 2024
[lldb] Use add_custom_command for SBLanguages.h (llvm#91254)
adrian-prantl pushed a commit to adrian-prantl/llvm-project that referenced this pull request Jun 12, 2024
Use add_custom_command instead of add_custom_target to generate
SBLanguages.h.

(cherry picked from commit 3809e20)
(cherry picked from commit 18013b9)
adrian-prantl pushed a commit to adrian-prantl/llvm-project that referenced this pull request Jun 12, 2024
Alex pointed out in llvm#91254 that we only need the custom target if we had
more than one target depending on it. This isn't the case upstream, but
on our downstream fork, we have a second dependency. Reintroduce the
target so that everything can depend on that, without the
single-dependency foot-gun.

(cherry picked from commit dad1109)
(cherry picked from commit 26f8029)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants