Skip to content

Commit

Permalink
Check download status and fail build if download fails (#510)
Browse files Browse the repository at this point in the history
Also check SHA256 hashsum of downloaded files.
  • Loading branch information
elliottslaughter authored May 4, 2023
1 parent 7f7864a commit c2d477a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 14 additions & 1 deletion cmake/Modules/GetLuaJIT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if(TERRA_LUA STREQUAL "luajit")
set(LUAJIT_VERSION_PATCH 0)
set(LUAJIT_VERSION_EXTRA -beta3)
set(LUAJIT_COMMIT "50936d784474747b4569d988767f1b5bab8bb6d0")
set(LUAJIT_HASH_SHA256 "4d44e4709130b031c1c2c81cf5c102dfce877bf454409dabba03249e18870e66")
if(NOT LUAJIT_VERSION_COMMIT STREQUAL "")
set(LUAJIT_URL_PREFIX "https://github.com/LuaJIT/LuaJIT/archive/")
else()
Expand All @@ -30,6 +31,7 @@ elseif(TERRA_LUA STREQUAL "moonjit")
set(LUAJIT_VERSION_PATCH 0)
set(LUAJIT_VERSION_EXTRA -dev)
set(LUAJIT_COMMIT "eb7168839138591e0d2a1751122966603a8b87c8")
set(LUAJIT_HASH_SHA256 "6086a84b9666233808dd8b19b9085ce7f68419e26cc266c6511eb96f8d7a5ce2")
set(LUAJIT_URL_PREFIX "https://github.com/moonjit/moonjit/archive/")
else()
message(FATAL_ERROR "TERRA_LUA must be one of 'luajit', 'moonjit'")
Expand Down Expand Up @@ -76,7 +78,17 @@ string(CONCAT
"${CMAKE_SHARED_LIBRARY_SUFFIX}"
)

file(DOWNLOAD "${LUAJIT_URL}" "${LUAJIT_TAR}")
option(TERRA_SKIP_LUA_DOWNLOAD "do not download LuaJIT (used in Nix build because Nix pre-downloads LuaJIT)" OFF)
if(NOT TERRA_SKIP_LUA_DOWNLOAD)
file(DOWNLOAD "${LUAJIT_URL}" "${LUAJIT_TAR}"
EXPECTED_HASH SHA256=${LUAJIT_HASH_SHA256}
STATUS LUAJIT_TAR_STATUS)
list(GET LUAJIT_TAR_STATUS 0 LUAJIT_TAR_STATUS_CODE)
if(NOT LUAJIT_TAR_STATUS_CODE EQUAL 0)
list(GET LUAJIT_TAR_STATUS 1 LUAJIT_TAR_STATUS_MESSAGE)
message(FATAL_ERROR "Failed to download LuaJIT release ${LUAJIT_URL}: ${LUAJIT_TAR_STATUS_MESSAGE}")
endif()
endif()

execute_process(
COMMAND "${CMAKE_COMMAND}" -E tar xzf "${LUAJIT_TAR}"
Expand Down Expand Up @@ -293,4 +305,5 @@ mark_as_advanced(
LUAJIT_OBJECT_DIR
LUAJIT_LIBRARY
LUAJIT_EXECUTABLE
TERRA_SKIP_LUA_DOWNLOAD
)
4 changes: 1 addition & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ in stdenv.mkDerivation rec {
"-DHAS_TERRA_VERSION=0"
"-DTERRA_VERSION=${version}"
"-DTERRA_LUA=luajit"
"-DTERRA_SKIP_LUA_DOWNLOAD=ON"
"-DCLANG_RESOURCE_DIR=${llvmMerged}/lib/clang/${clangVersion}"
] ++ lib.optional enableCUDA "-DTERRA_ENABLE_CUDA=ON";

Expand All @@ -65,9 +66,6 @@ in stdenv.mkDerivation rec {
patches = [ ./nix/cflags.patch ];

postPatch = ''
sed -i '/file(DOWNLOAD "''${LUAJIT_URL}" "''${LUAJIT_TAR}")/d' \
cmake/Modules/GetLuaJIT.cmake
substituteInPlace src/terralib.lua \
--subst-var-by NIX_LIBC_INCLUDE ${lib.getDev stdenv.cc.libc}/include
'';
Expand Down

0 comments on commit c2d477a

Please sign in to comment.