[llvm] r291284 - [cmake] Canonicalize CMake booleans to 0/1 for lit interop

Michal Gorny via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 6 13:33:48 PST 2017


Author: mgorny
Date: Fri Jan  6 15:33:48 2017
New Revision: 291284

URL: http://llvm.org/viewvc/llvm-project?rev=291284&view=rev
Log:
[cmake] Canonicalize CMake booleans to 0/1 for lit interop

Canonicalize all CMake booleans to 0/1 before passing them to lit, to
ensure that the Python side handles all of them consistently
and correctly. 0/1 is a safe choice of values that trigger the same
boolean interpretation in CMake, Python and C++.

Furthermore, using them without quotes improves the chance Python will
explicitly fail when an incorrect value (such as ON/OFF, TRUE/FALSE,
YES/NO) is accidentally passed, rather than silently misinterpreting
the value.

This replaces a lot of different logics spread around lit site files,
attempting to partially reproduce the boolean logic used in CMake
and usually silently failing when an uncommon value was used instead.
In fact, some of them were never working correctly since different
values were assigned in CMake and checked in Python.

The alternative solution could be to create a common parser for CMake
booleans in lit and use it consistently throughout the site files.
However, it does not seem like the best idea to create redundant
implementation of the same logic and have to follow upstream if it ever
is extended to handle more values.

Differential Revision: https://reviews.llvm.org/D28294

Modified:
    llvm/trunk/cmake/config-ix.cmake
    llvm/trunk/cmake/modules/AddLLVM.cmake
    llvm/trunk/test/Bindings/Go/lit.local.cfg
    llvm/trunk/test/Bindings/OCaml/lit.local.cfg
    llvm/trunk/test/CMakeLists.txt
    llvm/trunk/test/ExecutionEngine/Interpreter/lit.local.cfg
    llvm/trunk/test/JitListener/lit.local.cfg
    llvm/trunk/test/lit.cfg
    llvm/trunk/test/lit.site.cfg.in

Modified: llvm/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/cmake/config-ix.cmake (original)
+++ llvm/trunk/cmake/config-ix.cmake Fri Jan  6 15:33:48 2017
@@ -462,13 +462,6 @@ if( MSVC )
   if(LLVM_ENABLE_DIA_SDK AND NOT HAVE_DIA_SDK)
     message(FATAL_ERROR "DIA SDK not found. If you have both VS 2012 and 2013 installed, you may need to uninstall the former and re-install the latter afterwards.")
   endif()
-
-  # Normalize to 0/1 for lit.site.cfg
-  if(LLVM_ENABLE_DIA_SDK)
-    set(LLVM_ENABLE_DIA_SDK 1)
-  else()
-    set(LLVM_ENABLE_DIA_SDK 0)
-  endif()
 else()
   set(LLVM_ENABLE_DIA_SDK 0)
 endif( MSVC )

Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Fri Jan  6 15:33:48 2017
@@ -1067,6 +1067,19 @@ function(llvm_add_go_executable binary p
   endif()
 endfunction()
 
+# This function canonicalize the CMake variables passed by names
+# from CMake boolean to 0/1 suitable for passing into Python or C++,
+# in place.
+function(llvm_canonicalize_cmake_booleans)
+  foreach(var ${ARGN})
+    if(${var})
+      set(${var} 1 PARENT_SCOPE)
+    else()
+      set(${var} 0 PARENT_SCOPE)
+    endif()
+  endforeach()
+endfunction(llvm_canonicalize_cmake_booleans)
+
 # This function provides an automatic way to 'configure'-like generate a file
 # based on a set of common and custom variables, specifically targeting the
 # variables needed for the 'lit.site.cfg' files. This function bundles the

Modified: llvm/trunk/test/Bindings/Go/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/Go/lit.local.cfg?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/Go/lit.local.cfg (original)
+++ llvm/trunk/test/Bindings/Go/lit.local.cfg Fri Jan  6 15:33:48 2017
@@ -6,7 +6,7 @@ import sys
 if not 'go' in config.root.llvm_bindings:
     config.unsupported = True
 
-if config.root.include_go_tests != 'ON':
+if not config.root.include_go_tests:
     config.unsupported = True
 
 def find_executable(executable, path=None):

Modified: llvm/trunk/test/Bindings/OCaml/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bindings/OCaml/lit.local.cfg?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/Bindings/OCaml/lit.local.cfg (original)
+++ llvm/trunk/test/Bindings/OCaml/lit.local.cfg Fri Jan  6 15:33:48 2017
@@ -3,5 +3,5 @@ config.suffixes = ['.ml']
 if not 'ocaml' in config.root.llvm_bindings:
     config.unsupported = True
 
-if config.root.have_ocaml_ounit not in ('1', 'TRUE'):
+if not config.root.have_ocaml_ounit:
     config.unsupported = True

Modified: llvm/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CMakeLists.txt?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/CMakeLists.txt (original)
+++ llvm/trunk/test/CMakeLists.txt Fri Jan  6 15:33:48 2017
@@ -1,3 +1,14 @@
+llvm_canonicalize_cmake_booleans(
+  LLVM_TOOL_LTO_BUILD
+  HAVE_OCAMLOPT
+  HAVE_OCAML_OUNIT
+  LLVM_INCLUDE_GO_TESTS
+  LLVM_USE_INTEL_JITEVENTS
+  HAVE_LIBZ
+  HAVE_LIBXAR
+  LLVM_ENABLE_DIA_SDK
+  LLVM_ENABLE_FFI)
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg

Modified: llvm/trunk/test/ExecutionEngine/Interpreter/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/Interpreter/lit.local.cfg?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/ExecutionEngine/Interpreter/lit.local.cfg (original)
+++ llvm/trunk/test/ExecutionEngine/Interpreter/lit.local.cfg Fri Jan  6 15:33:48 2017
@@ -1,3 +1,3 @@
 # These tests require foreign function calls
-if config.enable_ffi != "ON":
+if not config.enable_ffi:
     config.unsupported = True

Modified: llvm/trunk/test/JitListener/lit.local.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/JitListener/lit.local.cfg?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/JitListener/lit.local.cfg (original)
+++ llvm/trunk/test/JitListener/lit.local.cfg Fri Jan  6 15:33:48 2017
@@ -1,3 +1,3 @@
-if not config.root.llvm_use_intel_jitevents == "true":
+if not config.root.llvm_use_intel_jitevents:
     config.unsupported = True
 

Modified: llvm/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.cfg?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/lit.cfg (original)
+++ llvm/trunk/test/lit.cfg Fri Jan  6 15:33:48 2017
@@ -231,7 +231,7 @@ config.substitutions.append( ('%ld64', l
 config.substitutions.append( ('%ocamlc',
     "%s ocamlc -cclib -L%s %s" %
         (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) )
-if config.have_ocamlopt in ('1', 'TRUE'):
+if config.have_ocamlopt:
     config.substitutions.append( ('%ocamlopt',
         "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" %
             (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) )
@@ -399,7 +399,7 @@ if lit_config.params.get("run_long_tests
 if not 'hexagon' in config.target_triple:
     config.available_features.add("object-emission")
 
-if config.have_zlib == "1":
+if config.have_zlib:
     config.available_features.add("zlib")
 else:
     config.available_features.add("nozlib")
@@ -455,7 +455,7 @@ if have_ld_plugin_support():
     config.available_features.add('ld_plugin')
 
 def have_ld64_plugin_support():
-    if (config.llvm_tool_lto_build == 'OFF' or config.ld64_executable == ''):
+    if not config.llvm_tool_lto_build or config.ld64_executable == '':
         return False
 
     ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)

Modified: llvm/trunk/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/lit.site.cfg.in?rev=291284&r1=291283&r2=291284&view=diff
==============================================================================
--- llvm/trunk/test/lit.site.cfg.in (original)
+++ llvm/trunk/test/lit.site.cfg.in Fri Jan  6 15:33:48 2017
@@ -15,12 +15,12 @@ config.lit_tools_dir = "@LLVM_LIT_TOOLS_
 config.python_executable = "@PYTHON_EXECUTABLE@"
 config.gold_executable = "@GOLD_EXECUTABLE@"
 config.ld64_executable = "@LD64_EXECUTABLE@"
-config.llvm_tool_lto_build = "@LLVM_TOOL_LTO_BUILD@"
+config.llvm_tool_lto_build = @LLVM_TOOL_LTO_BUILD@
 config.ocamlfind_executable = "@OCAMLFIND@"
-config.have_ocamlopt = "@HAVE_OCAMLOPT@"
-config.have_ocaml_ounit = "@HAVE_OCAML_OUNIT@"
+config.have_ocamlopt = @HAVE_OCAMLOPT@
+config.have_ocaml_ounit = @HAVE_OCAML_OUNIT@
 config.ocaml_flags = "@OCAMLFLAGS@"
-config.include_go_tests = "@LLVM_INCLUDE_GO_TESTS@"
+config.include_go_tests = @LLVM_INCLUDE_GO_TESTS@
 config.go_executable = "@GO_EXECUTABLE@"
 config.enable_shared = @ENABLE_SHARED@
 config.enable_assertions = @ENABLE_ASSERTIONS@
@@ -32,12 +32,12 @@ config.host_arch = "@HOST_ARCH@"
 config.host_cc = "@HOST_CC@"
 config.host_cxx = "@HOST_CXX@"
 config.host_ldflags = "@HOST_LDFLAGS@"
-config.llvm_use_intel_jitevents = "@LLVM_USE_INTEL_JITEVENTS@"
+config.llvm_use_intel_jitevents = @LLVM_USE_INTEL_JITEVENTS@
 config.llvm_use_sanitizer = "@LLVM_USE_SANITIZER@"
-config.have_zlib = "@HAVE_LIBZ@"
-config.have_libxar = "@HAVE_LIBXAR@"
+config.have_zlib = @HAVE_LIBZ@
+config.have_libxar = @HAVE_LIBXAR@
 config.have_dia_sdk = @LLVM_ENABLE_DIA_SDK@
-config.enable_ffi = "@LLVM_ENABLE_FFI@"
+config.enable_ffi = @LLVM_ENABLE_FFI@
 
 # Support substitution of the tools_dir with user parameters. This is
 # used when we can't determine the tool dir at configuration time.




More information about the llvm-commits mailing list