From c2d477a0df0295d95e18b15de1d8979bca1bf45f Mon Sep 17 00:00:00 2001 From: Elliott Slaughter Date: Thu, 4 May 2023 10:16:53 -0700 Subject: [PATCH] Check download status and fail build if download fails (#510) Also check SHA256 hashsum of downloaded files. --- cmake/Modules/GetLuaJIT.cmake | 15 ++++++++++++++- default.nix | 4 +--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmake/Modules/GetLuaJIT.cmake b/cmake/Modules/GetLuaJIT.cmake index 88785515..4883893e 100644 --- a/cmake/Modules/GetLuaJIT.cmake +++ b/cmake/Modules/GetLuaJIT.cmake @@ -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() @@ -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'") @@ -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}" @@ -293,4 +305,5 @@ mark_as_advanced( LUAJIT_OBJECT_DIR LUAJIT_LIBRARY LUAJIT_EXECUTABLE + TERRA_SKIP_LUA_DOWNLOAD ) diff --git a/default.nix b/default.nix index d0bebd3b..8abdfe19 100644 --- a/default.nix +++ b/default.nix @@ -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"; @@ -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 '';