From 2b29b5505243ce98397b6c5f8273b2f7ed26f517 Mon Sep 17 00:00:00 2001 From: Petr Penzin Date: Sun, 29 Mar 2020 22:34:47 -0700 Subject: [PATCH] Full build and testing directly from CMake 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. Make some CMake error messages slightly more informative. Nit: build.sh - "makefiles" is inaccurate, as it supports Ninja as well. Closes #6417 --- .gitignore | 1 - CMakeLists.txt | 33 +++++++++++++++++++++++---------- bin/ch/CMakeLists.txt | 9 +++++++++ bin/ch/jstoc.py | 2 +- build.sh | 18 ++++++------------ test/CMakeLists.txt | 13 +++++++++++++ 6 files changed, 52 insertions(+), 24 deletions(-) create mode 100644 test/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 07bcf1cc834..da133ae06dc 100644 --- a/.gitignore +++ b/.gitignore @@ -96,7 +96,6 @@ tags *.dylib Makefile pal/src/config.h -DbgController.js.h lib/wabt/built/config.h # Generated by other tools diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b9376613bc..8e9a67637b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,15 @@ project (CHAKRACORE) set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g") +# Disable exepected 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) diff --git a/bin/ch/CMakeLists.txt b/bin/ch/CMakeLists.txt index a8ca77953d5..86b0b6af13d 100644 --- a/bin/ch/CMakeLists.txt +++ b/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 diff --git a/bin/ch/jstoc.py b/bin/ch/jstoc.py index e0be592fb18..a9618054bc9 100755 --- a/bin/ch/jstoc.py +++ b/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 diff --git a/build.sh b/build.sh index efefa7de35b..c9b2686a384 100755 --- a/build.sh +++ b/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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 00000000000..e634e3914d3 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,13 @@ +if (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) + set(TEST_BUILD_TYPE --test) +elseif (CMAKE_BUILD_TYPE STREQUAL Debug) + set(TEST_BUILD_TYPE --debug) +endif () + +add_custom_target(check + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtests.py ${TEST_BUILD_TYPE} --binary ${CMAKE_BINARY_DIR}/ch --logfile ${CMAKE_BINARY_DIR}/check.log + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + USES_TERMINAL + DEPENDS ch + ) +