[build] Run submodule update on every build, and npm install when the package.json changed

We're now running a submodule update as part of every build, and when the project files are generated. We also run an npm install whenever the package.json was updated, both during project generation and as part of every build.
This commit is contained in:
Konstantin Käfer
2017-01-18 11:57:27 +01:00
parent a2ceeb4a5b
commit dbd7186bc5
3 changed files with 61 additions and 21 deletions

View File

@@ -3,27 +3,6 @@ project(mbgl LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 14)
include(cmake/mbgl.cmake)
if(NOT EXISTS ".mason/mason.cmake")
execute_process(
COMMAND git submodule update --init .mason
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
if(NOT EXISTS "mapbox-gl-js/package.json")
execute_process(
COMMAND git submodule update --init mapbox-gl-js
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
# Symlink mapbox-gl-js/node_modules so that the modules that are
# about to be installed get cached between CI runs.
execute_process(
COMMAND ln -sF ../node_modules .
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/mapbox-gl-js)
execute_process(
COMMAND npm install
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/mapbox-gl-js)
endif()
include(.mason/mason.cmake)
option(WITH_CXX11ABI "Use cxx11abi mason packages" OFF)

View File

@@ -23,6 +23,66 @@ set(NodeJS_USE_CLANG_STDLIB OFF CACHE BOOL "Don't use libc++ by default" FORCE)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/node_modules/node-cmake)
find_package(NodeJS)
find_program(npm_EXECUTABLE
NAMES npm
PATHS ${NodeJS_ROOT_DIR})
if (NOT npm_EXECUTABLE)
message(FATAL_ERROR "Could not find npm")
endif()
function(_npm_install DIRECTORY NAME ADDITIONAL_DEPS)
SET(NPM_INSTALL_FAILED FALSE)
if("${DIRECTORY}/package.json" IS_NEWER_THAN "${DIRECTORY}/node_modules/.${NAME}.stamp")
message(STATUS "Running 'npm install' for ${NAME}...")
execute_process(
COMMAND ${NodeJS_EXECUTABLE} ${npm_EXECUTABLE} install --ignore-scripts
WORKING_DIRECTORY "${DIRECTORY}"
RESULT_VARIABLE NPM_INSTALL_FAILED)
if(NOT NPM_INSTALL_FAILED)
execute_process(COMMAND ${CMAKE_COMMAND} -E touch "${DIRECTORY}/node_modules/.${NAME}.stamp")
endif()
endif()
add_custom_command(
OUTPUT "${DIRECTORY}/node_modules/.${NAME}.stamp"
COMMAND ${NodeJS_EXECUTABLE} ${npm_EXECUTABLE} install --ignore-scripts
COMMAND ${CMAKE_COMMAND} -E touch "${DIRECTORY}/node_modules/.${NAME}.stamp"
WORKING_DIRECTORY "${DIRECTORY}"
DEPENDS ${ADDITIONAL_DEPS} "${DIRECTORY}/package.json"
COMMENT "Running 'npm install' for ${NAME}...")
endfunction()
# Run submodule update
message(STATUS "Updating submodules...")
execute_process(
COMMAND git submodule update --init .mason mapbox-gl-js
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/mapbox-gl-js/node_modules")
# Symlink mapbox-gl-js/node_modules so that the modules that are
# about to be installed get cached between CI runs.
execute_process(
COMMAND ln -sF ../node_modules .
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/mapbox-gl-js")
endif()
# Add target for running submodule update during builds
add_custom_target(
update-submodules ALL
COMMAND git submodule update --init .mason mapbox-gl-js
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Updating submodules..."
)
# Run npm install for both directories, and add custom commands, and a target that depends on them.
_npm_install("${CMAKE_SOURCE_DIR}" mapbox-gl-native update-submodules)
_npm_install("${CMAKE_SOURCE_DIR}/mapbox-gl-js" mapbox-gl-js "${CMAKE_SOURCE_DIR}/node_modules/.mapbox-gl-native.stamp")
add_custom_target(
npm-install ALL
DEPENDS "${CMAKE_SOURCE_DIR}/node_modules/.mapbox-gl-js.stamp"
)
# Generate source groups so the files are properly sorted in IDEs like Xcode.
function(create_source_groups target)
get_target_property(sources ${target} SOURCES)

View File

@@ -6,6 +6,7 @@ function(add_shader VAR name)
add_custom_command(
OUTPUT ${shader_source_prefix}/${name}.hpp
COMMAND ${shader_build_cmd} ${name} ${shader_file_prefix} ${shader_source_prefix}
DEPENDS npm-install
DEPENDS ${CMAKE_SOURCE_DIR}/scripts/build-shaders.js
DEPENDS ${shader_file_prefix}/${name}.vertex.glsl
DEPENDS ${shader_file_prefix}/${name}.fragment.glsl