Skip to content

Commit 3682e7f

Browse files
authored
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
1 parent c72b4b7 commit 3682e7f

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ tags
9696
*.dylib
9797
Makefile
9898
pal/src/config.h
99-
DbgController.js.h
10099
lib/wabt/built/config.h
101100

102101
# Generated by other tools

CMakeLists.txt

+23-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ project (CHAKRACORE)
33

44
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
55

6+
# Disable expected CMake workflow
7+
option(CHAKRACORE_BUILD_SH "Use build.sh")
8+
9+
if(NOT CHAKRACORE_BUILD_SH)
10+
option(INTL_ICU "Enable Intl" ON)
11+
option(EMBED_ICU "Build ICU within ChakraCore build" OFF)
12+
set(ICU_INCLUDE_PATH "" CACHE STRING "libicu iclude path")
13+
endif(NOT CHAKRACORE_BUILD_SH)
14+
615
# Keep CMake from caching static/shared library
716
# option. Otherwise, CMake fails to update cached
817
# references
@@ -27,7 +36,7 @@ if(LIBS_ONLY_BUILD_SH)
2736
set(CC_LIBS_ONLY_BUILD 1)
2837
endif()
2938

30-
if(CC_USES_SYSTEM_ARCH_SH)
39+
if(CC_USES_SYSTEM_ARCH_SH OR NOT CHAKRACORE_BUILD_SH)
3140
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
3241
set(CC_TARGETS_AMD64_SH 1)
3342
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7l")
@@ -46,7 +55,7 @@ elseif(CC_TARGETS_X86_SH)
4655
set(CC_TARGETS_X86 1)
4756
set(CMAKE_SYSTEM_PROCESSOR "i386")
4857
else()
49-
message(FATAL_ERROR "Couldn't detect target processor, try `--arch` argument with build.sh")
58+
message(FATAL_ERROR "Unsupported target processor: ${CMAKE_SYSTEM_PROCESSOR}")
5059
endif()
5160

5261
unset(CC_TARGETS_ARM_SH CACHE)
@@ -128,13 +137,15 @@ if(SYSTEM_ICU_SH)
128137
unset(SYSTEM_ICU_SH CACHE)
129138
endif()
130139

131-
if(INTL_ICU_SH)
132-
unset(INTL_ICU_SH CACHE)
133-
set(INTL_ICU 1)
134-
else()
135-
unset(INTL_ICU_SH CACHE)
136-
set(INTL_ICU 0)
137-
endif()
140+
if(CHAKRACORE_BUILD_SH)
141+
if(INTL_ICU_SH)
142+
unset(INTL_ICU_SH CACHE)
143+
set(INTL_ICU 1)
144+
else()
145+
unset(INTL_ICU_SH CACHE)
146+
set(INTL_ICU 0)
147+
endif()
148+
endif(CHAKRACORE_BUILD_SH)
138149

139150
if(EMBED_ICU_SH)
140151
set(EMBED_ICU 1)
@@ -296,7 +307,7 @@ elseif(CC_TARGET_OS_OSX)
296307
endif()
297308
endif()
298309
else()
299-
message(FATAL_ERROR "This OS is not supported")
310+
message(FATAL_ERROR "Unsupported OS: ${CMAKE_SYSTEM_NAME}")
300311
endif()
301312

302313
if (CMAKE_CXX_COMPILER_ID STREQUAL AppleClang
@@ -562,3 +573,5 @@ endif()
562573
add_subdirectory (lib)
563574

564575
add_subdirectory (bin)
576+
577+
add_subdirectory(test)

bin/ch/CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
add_custom_target(dbg_controller_h
2+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js controllerScript
3+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
4+
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js
5+
)
6+
17
set(ch_source_files
28
ch.cpp
39
ChakraRtInterface.cpp
@@ -17,6 +23,8 @@ endif()
1723

1824
add_executable (ch ${ch_source_files})
1925

26+
add_dependencies(ch dbg_controller_h)
27+
2028
set_target_properties(ch
2129
PROPERTIES
2230
POSITION_INDEPENDENT_CODE True
@@ -30,6 +38,7 @@ endif()
3038

3139
target_include_directories (ch
3240
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
41+
${CMAKE_CURRENT_BINARY_DIR}
3342
../ChakraCore
3443
../../lib/Common
3544
../../lib/Jsrt

bin/ch/jstoc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def convert():
2323
if os.path.isfile(js_file_name) == False:
2424
print_usage()
2525

26-
h_file_name = js_file_name + '.h'
26+
h_file_name = os.path.basename(js_file_name) + '.h'
2727

2828
js_file_time = os.path.getmtime(js_file_name)
2929
h_file_time = 0

build.sh

+6-12
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,6 @@ if [[ $WB_CHECK || $WB_ANALYZE ]]; then
608608
fi
609609
fi
610610

611-
# prepare DbgController.js.h
612-
CH_DIR="${CHAKRACORE_DIR}/bin/ch"
613-
"${CH_DIR}/jstoc.py" "${CH_DIR}/DbgController.js" controllerScript
614-
if [[ $? != 0 ]]; then
615-
exit 1
616-
fi
617-
618611
if [ ! -d "$BUILD_DIRECTORY" ]; then
619612
SAFE_RUN `mkdir -p $BUILD_DIRECTORY`
620613
fi
@@ -634,12 +627,13 @@ else
634627
echo "Compile Target : System Default"
635628
fi
636629

637-
echo Generating $BUILD_TYPE makefiles
630+
echo Generating $BUILD_TYPE build
638631
echo $EXTRA_DEFINES
639-
cmake $CMAKE_GEN $CC_PREFIX $CMAKE_ICU $LTO $LTTNG $STATIC_LIBRARY $ARCH $TARGET_OS \
640-
$ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES -DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
641-
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS $LIBS_ONLY_BUILD\
642-
$VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
632+
cmake $CMAKE_GEN -DCHAKRACORE_BUILD_SH=ON $CC_PREFIX $CMAKE_ICU $LTO $LTTNG \
633+
$STATIC_LIBRARY $ARCH $TARGET_OS \ $ENABLE_CC_XPLAT_TRACE $EXTRA_DEFINES \
634+
-DCMAKE_BUILD_TYPE=$BUILD_TYPE $SANITIZE $NO_JIT $CMAKE_INTL \
635+
$WITHOUT_FEATURES $WB_FLAG $WB_ARGS $CMAKE_EXPORT_COMPILE_COMMANDS \
636+
$LIBS_ONLY_BUILD $VALGRIND $BUILD_RELATIVE_DIRECTORY $CCACHE_NAME
643637

644638
_RET=$?
645639
if [[ $? == 0 ]]; then

test/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if (CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
2+
set(TEST_BUILD_TYPE --test)
3+
elseif (CMAKE_BUILD_TYPE STREQUAL Debug)
4+
set(TEST_BUILD_TYPE --debug)
5+
endif ()
6+
7+
if (NO_ICU)
8+
set(TEST_EXCLUDE --not-tag exclude_noicu)
9+
endif()
10+
11+
add_custom_target(check
12+
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/runtests.py ${TEST_BUILD_TYPE} ${TEST_EXCLUDE} --binary ${CMAKE_BINARY_DIR}/ch --logfile ${CMAKE_BINARY_DIR}/check.log
13+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
14+
USES_TERMINAL
15+
DEPENDS ch
16+
)
17+

0 commit comments

Comments
 (0)