Truly independent web browser
Meta: Serialize vcpkg tool acquisition
Ali Mohammad Pur6a488f6931ff
diff --git a/Meta/CMake/vcpkg/base-triplets/base.cmake b/Meta/CMake/vcpkg/base-triplets/base.cmakeindex 6e00403cfc9..ca96e93a8db 100644--- a/Meta/CMake/vcpkg/base-triplets/base.cmake+++ b/Meta/CMake/vcpkg/base-triplets/base.cmake@@ -1,2 +1,3 @@include(${CMAKE_CURRENT_LIST_DIR}/../user-variables.cmake OPTIONAL)include(${_VCPKG_INSTALLED_DIR}/../build-vcpkg-variables.cmake OPTIONAL)+include(${CMAKE_CURRENT_LIST_DIR}/serialize-tool-acquisition.cmake)diff --git a/Meta/CMake/vcpkg/base-triplets/serialize-tool-acquisition.cmake b/Meta/CMake/vcpkg/base-triplets/serialize-tool-acquisition.cmakenew file mode 100644index 00000000000..9e975425d42--- /dev/null+++ b/Meta/CMake/vcpkg/base-triplets/serialize-tool-acquisition.cmake@@ -0,0 +1,52 @@+# NOTE: This must not set any variables in the including scope, as the triplet's variables are part of every port's ABI.++if(NOT COMMAND vcpkg_find_acquire_program OR NOT COMMAND vcpkg_extract_archive)+ return()+endif()++if(COMMAND z_ladybird_tool_acquisition_is_serialized)+ return()+endif()+function(z_ladybird_tool_acquisition_is_serialized)+endfunction()++function(vcpkg_find_acquire_program program)+ # Acquiring some tools acquires others (e.g. meson needs python), and the lock is not reentrant.+ get_property(depth GLOBAL PROPERTY Z_LADYBIRD_TOOL_ACQUISITION_DEPTH)+ if("${depth}" STREQUAL "")+ set(depth 0)+ endif()+ if(depth EQUAL 0)+ file(MAKE_DIRECTORY "${DOWNLOADS}/tools")+ file(LOCK "${DOWNLOADS}/tools/.ladybird-acquire.lock" GUARD FUNCTION)+ endif()++ math(EXPR inner_depth "${depth} + 1")+ set_property(GLOBAL PROPERTY Z_LADYBIRD_TOOL_ACQUISITION_DEPTH "${inner_depth}")+ _vcpkg_find_acquire_program(${ARGV})+ set_property(GLOBAL PROPERTY Z_LADYBIRD_TOOL_ACQUISITION_DEPTH "${depth}")++ set("${program}" "${${program}}" PARENT_SCOPE)+endfunction()++function(vcpkg_extract_archive)+ get_property(depth GLOBAL PROPERTY Z_LADYBIRD_TOOL_ACQUISITION_DEPTH)+ if("${depth}" STREQUAL "" OR depth EQUAL 0)+ _vcpkg_extract_archive(${ARGV})+ return()+ endif()++ cmake_parse_arguments(PARSE_ARGV 0 arg "" "ARCHIVE;DESTINATION" "")++ # vcpkg only extracts a tool once it failed to find it, and we hold the lock, so anything already here is the+ # remains of an extraction (or post-install step) that never finished.+ if(EXISTS "${arg_DESTINATION}")+ message(STATUS "Removing incomplete tool directory ${arg_DESTINATION}")+ file(REMOVE_RECURSE "${arg_DESTINATION}")+ endif()++ set(partial_destination "${arg_DESTINATION}.partial")+ file(REMOVE_RECURSE "${partial_destination}")+ _vcpkg_extract_archive(ARCHIVE "${arg_ARCHIVE}" DESTINATION "${partial_destination}")+ file(RENAME "${partial_destination}" "${arg_DESTINATION}")+endfunction()