Skip to content

Commit

Permalink
Merge branch 'blawrence/error-check-execute_process' into 'master'
Browse files Browse the repository at this point in the history
Check that subprocesses don't error out during cmake configure

See merge request machine-learning/dorado!1245
  • Loading branch information
blawrence-ont committed Oct 24, 2024
2 parents 7bca166 + 9bc600a commit 64b2a72
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 27 deletions.
13 changes: 11 additions & 2 deletions cmake/DoradoVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ set(DORADO_VERSION_REV 0)

find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h OUTPUT_VARIABLE DORADO_SHORT_HASH WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
execute_process(COMMAND ${GIT_EXECUTABLE} diff --quiet RESULT_VARIABLE IS_DIRTY WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
execute_process(
COMMAND ${GIT_EXECUTABLE} log -1 --pretty=format:%h
OUTPUT_VARIABLE DORADO_SHORT_HASH
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND ${GIT_EXECUTABLE} diff --quiet
RESULT_VARIABLE IS_DIRTY
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
if(IS_DIRTY)
string(APPEND DORADO_SHORT_HASH "+dirty")
endif()
Expand Down
21 changes: 13 additions & 8 deletions cmake/HDF5.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ elseif(WIN32)
# Need a zlib build for HDF to use
download_and_extract(https://github.com/madler/zlib/archive/refs/tags/v${ZLIB_VER}.tar.gz zlib-${ZLIB_VER})
set(HDF5_ZLIB_BUILD_DIR ${CMAKE_BINARY_DIR}/zlib-${ZLIB_VER}/build)
execute_process(COMMAND
cmake
-S ${DORADO_3RD_PARTY_DOWNLOAD}/zlib-${ZLIB_VER}/zlib-${ZLIB_VER}
-B ${HDF5_ZLIB_BUILD_DIR}
-A x64
-D CMAKE_INSTALL_PREFIX=${HDF5_ZLIB_INSTALL_DIR}
-D CMAKE_CONFIGURATION_TYPES=Release
execute_process(
COMMAND
cmake
-S ${DORADO_3RD_PARTY_DOWNLOAD}/zlib-${ZLIB_VER}/zlib-${ZLIB_VER}
-B ${HDF5_ZLIB_BUILD_DIR}
-A x64
-D CMAKE_INSTALL_PREFIX=${HDF5_ZLIB_INSTALL_DIR}
-D CMAKE_CONFIGURATION_TYPES=Release
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND cmake --build ${HDF5_ZLIB_BUILD_DIR} --config Release --target install
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(COMMAND cmake --build ${HDF5_ZLIB_BUILD_DIR} --config Release --target install)

# HDF5 itself
download_and_extract(https://cdn.oxfordnanoportal.com/software/analysis/${HDF_VER}-win.zip ${HDF_VER})
Expand Down
7 changes: 5 additions & 2 deletions cmake/Htslib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ if(NOT TARGET htslib) # lazy include guard
find_program(MAKE_COMMAND make REQUIRED)
find_program(AUTOCONF_COMMAND autoconf REQUIRED)
find_program(AUTOHEADER_COMMAND autoheader REQUIRED)
execute_process(COMMAND bash -c "${AUTOCONF_COMMAND} -V | sed 's/.* //; q'"
OUTPUT_VARIABLE AUTOCONF_VERS)
execute_process(
COMMAND bash -c "${AUTOCONF_COMMAND} -V | sed 's/.* //; q'"
OUTPUT_VARIABLE AUTOCONF_VERS
COMMAND_ERROR_IS_FATAL ANY
)
if (AUTOCONF_VERS VERSION_GREATER_EQUAL 2.70 AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
set(AUTOCONF_COMMAND autoreconf --install)
endif()
Expand Down
12 changes: 10 additions & 2 deletions cmake/InstallRedistLibs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,22 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
get_filename_component(target_name ${target} NAME)
get_filename_component(link_name ${link} NAME)
if (NOT target_name STREQUAL link_name)
execute_process(COMMAND ln -rfs ${target_name} ${link_name} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
execute_process(
COMMAND ln -rfs ${target_name} ${link_name}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${link_name} DESTINATION lib COMPONENT redist_libs)

# create links to the versioned links above
# e.g. libcublas.so => libcublas.so.11
string(REGEX REPLACE "[.]so[.0-9]*$" ".so" base_link ${link_name})
if (NOT base_link STREQUAL link_name)
execute_process(COMMAND ln -rfs ${link_name} ${base_link} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
execute_process(
COMMAND ln -rfs ${link_name} ${base_link}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${base_link} DESTINATION lib COMPONENT redist_libs)
endif()
endif()
Expand Down
22 changes: 18 additions & 4 deletions cmake/Koi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,27 @@ if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR WIN32)
if(NOT EXISTS ${KOI_DIR})
if(DEFINED GITLAB_CI_TOKEN)
message("Cloning Koi using CI token")
execute_process(COMMAND git clone https://gitlab-ci-token:${GITLAB_CI_TOKEN}@git.oxfordnanolabs.local/machine-learning/koi.git ${KOI_DIR})
execute_process(
COMMAND git clone https://gitlab-ci-token:${GITLAB_CI_TOKEN}@git.oxfordnanolabs.local/machine-learning/koi.git ${KOI_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
else()
message("Cloning Koi using ssh")
execute_process(COMMAND git clone git@git.oxfordnanolabs.local:machine-learning/koi.git ${KOI_DIR})
execute_process(
COMMAND git clone git@git.oxfordnanolabs.local:machine-learning/koi.git ${KOI_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
execute_process(COMMAND git checkout v${KOI_VERSION} WORKING_DIRECTORY ${KOI_DIR})
execute_process(COMMAND git submodule update --init --checkout WORKING_DIRECTORY ${KOI_DIR})
execute_process(
COMMAND git checkout v${KOI_VERSION}
WORKING_DIRECTORY ${KOI_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND git submodule update --init --checkout
WORKING_DIRECTORY ${KOI_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
add_subdirectory(${KOI_DIR}/koi/lib)

Expand Down
7 changes: 6 additions & 1 deletion cmake/Torch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ else()
file(STRINGS "${TORCH_LIB}/build-version" TORCH_BUILD_VERSION)
else()
set(PYTORCH_BUILD_VERSION "import torch; print('%s+cu%s' % (torch.__version__, torch.version.cuda.replace('.', '')), end='')")
execute_process(COMMAND python3 -c "${PYTORCH_BUILD_VERSION}" OUTPUT_VARIABLE TORCH_BUILD_VERSION WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
execute_process(
COMMAND python3 -c "${PYTORCH_BUILD_VERSION}"
OUTPUT_VARIABLE TORCH_BUILD_VERSION
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
endif()
message(STATUS "TORCH_BUILD_VERSION: ${TORCH_BUILD_VERSION}")
endif()
Expand Down
12 changes: 6 additions & 6 deletions cmake/UpdateSubmodules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ option(GIT_SUBMODULE "Check submodules during build" ON)
function(git_submodule_update)
find_package(Git QUIET)
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")

if(GIT_SUBMODULE)
message(STATUS "Submodule update")

file(LOCK ${CMAKE_SOURCE_DIR} DIRECTORY)
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_SUBMOD_RESULT
)
file(LOCK ${CMAKE_SOURCE_DIR} DIRECTORY RELEASE)

if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "git submodule update --init --recursive failed with ${GIT_SUBMOD_RESULT}, please checkout submodules")
endif()
Expand Down
12 changes: 10 additions & 2 deletions cmake/VbzPlugin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ function(add_hdf_vbz_plugin)
-B ${ZSTD_BUILD_DIR}
-A x64
-D CMAKE_CONFIGURATION_TYPES=Release
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND cmake --build ${ZSTD_BUILD_DIR} --config Release
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(COMMAND cmake --build ${ZSTD_BUILD_DIR} --config Release)

# On windows we need to tell hdf_plugins where we put the built zstd lib
set(CONAN_INCLUDE_DIRS_RELEASE ${DORADO_3RD_PARTY_SOURCE}/zstd/lib)
Expand All @@ -35,8 +39,12 @@ function(add_hdf_vbz_plugin)
-S ${DORADO_3RD_PARTY_SOURCE}/zstd/build/cmake
-B ${ZSTD_BUILD_DIR}
-D CMAKE_INSTALL_PREFIX=${ZSTD_INSTALL_DIR}
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(
COMMAND cmake --build ${ZSTD_BUILD_DIR} --target install
COMMAND_ERROR_IS_FATAL ANY
)
execute_process(COMMAND cmake --build ${ZSTD_BUILD_DIR} --target install)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/dorado/3rdparty/hdf_plugins/cmake")
# Findzstd.cmake uses conan variables to determine where things are.
Expand Down

0 comments on commit 64b2a72

Please sign in to comment.