[CMake] [Darwin] Add support for debugging tablegen dependencies
authorChris Bieneman <beanz@apple.com>
Thu, 17 Nov 2016 04:36:59 +0000 (04:36 +0000)
committerChris Bieneman <beanz@apple.com>
Thu, 17 Nov 2016 04:36:59 +0000 (04:36 +0000)
This patch adds an option to the build system LLVM_DEPENDENCY_DEBUGGING. Over time I plan to extend this to do more complex verifications, but the initial patch causes compile errors wherever there is missing a dependency on intrinsics_gen.

Because intrinsics_gen is a compile-time dependency not a link-time dependency, everything that relies on the headers generated in intrinsics_gen needs an explicit dependency.

llvm-svn: 287207

llvm/CMakeLists.txt
llvm/cmake/modules/AddLLVM.cmake

index f67fd23..1f301bd 100644 (file)
@@ -151,6 +151,20 @@ if(LLVM_CCACHE_BUILD)
   endif()
 endif()
 
+option(LLVM_DEPENDENCY_DEBUGGING "Dependency debugging mode to verify correctly expressed library dependencies (Darwin only)" OFF)
+
+# Some features of the LLVM build may be disallowed when dependency debugging is
+# enabled. In particular you cannot use ccache because we want to force compile
+# operations to always happen.
+if(LLVM_DEPENDENCY_DEBUGGING)
+  if(NOT CMAKE_HOST_APPLE)
+    message(FATAL_ERROR "Dependency debugging is only currently supported on Darwin hosts.")
+  endif()
+  if(LLVM_CCACHE_BUILD)
+    message(FATAL_ERROR "Cannot enable dependency debugging while using ccache.")
+  endif()
+endif()
+
 option(LLVM_BUILD_GLOBAL_ISEL "Experimental: Build GlobalISel" OFF)
 if(LLVM_BUILD_GLOBAL_ISEL)
   add_definitions(-DLLVM_BUILD_GLOBAL_ISEL)
index e8e119b..ef0dbf4 100644 (file)
@@ -377,6 +377,8 @@ function(llvm_add_library name)
     endif()
   endif()
 
+  setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
+
   # Generate objlib
   if((ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT)
     # Generate an obj library for both targets.
@@ -645,9 +647,11 @@ endmacro(add_llvm_loadable_module name)
 
 
 macro(add_llvm_executable name)
-  cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "" ${ARGN})
+  cmake_parse_arguments(ARG "DISABLE_LLVM_LINK_LLVM_DYLIB;IGNORE_EXTERNALIZE_DEBUGINFO;NO_INSTALL_RPATH" "" "DEPENDS" ${ARGN})
   llvm_process_sources( ALL_FILES ${ARG_UNPARSED_ARGUMENTS} )
 
+  list(APPEND LLVM_COMMON_DEPENDS ${ARG_DEPENDS})
+
   # Generate objlib
   if(LLVM_ENABLE_OBJLIB)
     # Generate an obj library for both targets.
@@ -669,6 +673,8 @@ macro(add_llvm_executable name)
     list(APPEND ALL_FILES "${LLVM_MAIN_SRC_DIR}/cmake/dummy.cpp")
   endif()
 
+  setup_dependency_debugging(${name} ${LLVM_COMMON_DEPENDS})
+  
   if( EXCLUDE_FROM_ALL )
     add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES})
   else()
@@ -1377,3 +1383,19 @@ function(llvm_setup_rpath name)
                         INSTALL_RPATH "${_install_rpath}"
                         ${_install_name_dir})
 endfunction()
+
+function(setup_dependency_debugging name)
+  if(NOT LLVM_DEPENDENCY_DEBUGGING)
+    return()
+  endif()
+
+  if("intrinsics_gen" IN_LIST ARGN)
+    return()
+  endif()
+
+  set(deny_attributes_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Attributes.gen\"))")
+  set(deny_intrinsics_gen "(deny file* (literal \"${LLVM_BINARY_DIR}/include/llvm/IR/Intrinsics.gen\"))")
+
+  set(sandbox_command "sandbox-exec -p '(version 1) (allow default) ${deny_attributes_gen} ${deny_intrinsics_gen}'")
+  set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE ${sandbox_command})
+endfunction()