Jelajahi Sumber

Full build and testing directly from CMake (#6393)

Add a direct mode for CMake builds. Add a CMake variable to distinguish
between `build.sh` and direct command line use -- in direct mode the
build would try to pick up reasonable system defaults. Set that variable
to OFF by default and to ON in `build.sh`.

Add explicit option for Intl support for direct CMake use and set its
default to `ON`. Add another explicit option for ICU include path
(default to empty), also only under direct CMake. Make sure Intl setting
does not get overridden.

Expose some ICU build options - embedding (default to OFF), Intl
(default to ON), and ICU include path (default to empty).

Move DbgController.js.h generation to CMake, make that step conditional
on whether dependencies have changed.

Add testing under control of CMake. Invoking `check` target should
run entire test suite, producing log file in the build directory.
Exclude tests dependent on ICU for non-ICU builds.

Make some CMake error messages slightly more informative.

Nit: build.sh - "makefiles" is inaccurate, as it supports Ninja as well.

Closes #6417
Petr Penzin 5 tahun lalu
induk
melakukan
3682e7f057
6 mengubah file dengan 56 tambahan dan 24 penghapusan
  1. 0 1
      .gitignore
  2. 23 10
      CMakeLists.txt
  3. 9 0
      bin/ch/CMakeLists.txt
  4. 1 1
      bin/ch/jstoc.py
  5. 6 12
      build.sh
  6. 17 0
      test/CMakeLists.txt

+ 0 - 1
.gitignore

@@ -96,7 +96,6 @@ tags
 *.dylib
 Makefile
 pal/src/config.h
-DbgController.js.h
 lib/wabt/built/config.h
 
 # Generated by other tools

+ 23 - 10
CMakeLists.txt

@@ -3,6 +3,15 @@ project (CHAKRACORE)
 
 set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
 
+# Disable expected CMake workflow
+option(CHAKRACORE_BUILD_SH "Use build.sh")
+
+if(NOT CHAKRACORE_BUILD_SH)
+    option(INTL_ICU "Enable Intl" ON)
+    option(EMBED_ICU "Build ICU within ChakraCore build" OFF)
+    set(ICU_INCLUDE_PATH "" CACHE STRING "libicu iclude path")
+endif(NOT CHAKRACORE_BUILD_SH)
+
 # Keep CMake from caching static/shared library
 # option. Otherwise, CMake fails to update cached
 # references
@@ -27,7 +36,7 @@ if(LIBS_ONLY_BUILD_SH)
     set(CC_LIBS_ONLY_BUILD 1)
 endif()
 
-if(CC_USES_SYSTEM_ARCH_SH)
+if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
     if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
         set(CC_TARGETS_AMD64_SH 1)
     elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
@@ -46,7 +55,7 @@ elseif(CC_TARGETS_X86_SH)
     set(CC_TARGETS_X86 1)
     set(CMAKE_SYSTEM_PROCESSOR "i386")
 else()
-    message(FATAL_ERROR "Couldn't detect target processor, try `--arch` argument with build.sh")
+    message(FATAL_ERROR "Unsupported target processor: ${CMAKE_SYSTEM_PROCESSOR}")
 endif()
 
 unset(CC_TARGETS_ARM_SH CACHE)
@@ -128,13 +137,15 @@ if(SYSTEM_ICU_SH)
     unset(SYSTEM_ICU_SH CACHE)
 endif()
 
-if(INTL_ICU_SH)
-    unset(INTL_ICU_SH CACHE)
-    set(INTL_ICU 1)
-else()
-    unset(INTL_ICU_SH CACHE)
-    set(INTL_ICU 0)
-endif()
+if(CHAKRACORE_BUILD_SH)
+    if(INTL_ICU_SH)
+        unset(INTL_ICU_SH CACHE)
+        set(INTL_ICU 1)
+    else()
+        unset(INTL_ICU_SH CACHE)
+        set(INTL_ICU 0)
+    endif()
+endif(CHAKRACORE_BUILD_SH)
 
 if(EMBED_ICU_SH)
     set(EMBED_ICU 1)
@@ -296,7 +307,7 @@ elseif(CC_TARGET_OS_OSX)
       endif()
     endif()
 else()
-    message(FATAL_ERROR "This OS is not supported")
+    message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
 endif()
 
 if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
@@ -562,3 +573,5 @@ endif()
 add_subdirectory (lib)
 
 add_subdirectory (bin)
+
+add_subdirectory(test)

+ 9 - 0
bin/ch/CMakeLists.txt

@@ -1,3 +1,9 @@
+add_custom_target(dbg_controller_h
+  COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js controllerScript
+  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+  SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js
+  )
+
 set(ch_source_files
   ch.cpp
   ChakraRtInterface.cpp
@@ -17,6 +23,8 @@ endif()
 
 add_executable (ch ${ch_source_files})
 
+add_dependencies(ch dbg_controller_h)
+
 set_target_properties(ch
   PROPERTIES
   POSITION_INDEPENDENT_CODE True
@@ -30,6 +38,7 @@ endif()
 
 target_include_directories (ch
   PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}
   ../ChakraCore
   ../../lib/Common
   ../../lib/Jsrt

+ 1 - 1
bin/ch/jstoc.py

@@ -23,7 +23,7 @@ def convert():
     if os.path.isfile(js_file_name) == False:
         print_usage()
 
-    h_file_name = js_file_name + '.h'
+    h_file_name = os.path.basename(js_file_name) + '.h'
 
     js_file_time = os.path.getmtime(js_file_name)
     h_file_time = 0

+ 6 - 12
build.sh

@@ -608,13 +608,6 @@ if [[ $WB_CHECK || $WB_ANALYZE ]]; then
     fi
 fi
 
-# prepare DbgController.js.h
-CH_DIR="${CHAKRACORE_DIR}/bin/ch"
-"${CH_DIR}/jstoc.py" "${CH_DIR}/DbgController.js" controllerScript
-if [[ $? != 0 ]]; then
-    exit 1
-fi
-
 if [ ! -d "$BUILD_DIRECTORY" ]; then
     SAFE_RUN `mkdir -p $BUILD_DIRECTORY`
 fi
@@ -634,12 +627,13 @@ else
     echo "Compile Target : System Default"
 fi
 
-echo Generating $BUILD_TYPE makefiles
+echo Generating $BUILD_TYPE build
 echo $EXTRA_DEFINES
-cmake $CMAKE_GEN $CC_PREFIX $CMAKE_ICU $LTO $LTTNG $STATIC_LIBRARY $ARCH $TARGET_OS \
-    $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
-    $WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\
-    $VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
+cmake $CMAKE_GEN -DCHAKRACORE_BUILD_SH=ON $CC_PREFIX $CMAKE_ICU $LTO $LTTNG \
+    $STATIC_LIBRARY $ARCH $TARGET_OS \ $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES \
+    -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
+    $WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS \
+    $LIBS_ONLY_BUILD $VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
 
 _RET=$?
 if [[ $? == 0 ]]; then

+ 17 - 0
test/CMakeLists.txt

@@ -0,0 +1,17 @@
+if (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
+    set(TEST_BUILD_TYPE --test)
+elseif (CMAKE_BUILD_TYPE STREQUAL Debug)
+    set(TEST_BUILD_TYPE --debug)
+endif ()
+
+if (NO_ICU)
+    set(TEST_EXCLUDE --not-tag exclude_noicu)
+endif()
+
+add_custom_target(check
+    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtests.py ${TEST_BUILD_TYPE} ${TEST_EXCLUDE} --binary ${CMAKE_BINARY_DIR}/ch --logfile ${CMAKE_BINARY_DIR}/check.log
+    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+    USES_TERMINAL
+    DEPENDS ch
+    )
+