aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authoratkawa7 <atkawa7@yahoo.com>2018-11-06 23:56:40 +0200
committerRobert Schumacher <roschuma@microsoft.com>2018-11-06 13:56:40 -0800
commit087691c94a45bbfb636c9bc4ebb63906ac012edf (patch)
treecfd8d6f89fd0b90ff427e93e87f77fbd6494f025 /scripts
parent1c01a56dc8aa66c3769c29fce09dbcf8938cc17a (diff)
downloadvcpkg-087691c94a45bbfb636c9bc4ebb63906ac012edf.tar.gz
vcpkg-087691c94a45bbfb636c9bc4ebb63906ac012edf.zip
fdlibm init (#4165)
* fdlibm init * fix links * Fix different hashes creation with google host * Move functions to script * Fix documentation * [vcpkg_from_git] Add SHA512 argument, switch to zip to better support Windows. * [fdlibm] Trigger rebuild * [vcpkg_from_git] Use FETCH_HEAD reference to support tags
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cmake/vcpkg_common_functions.cmake1
-rw-r--r--scripts/cmake/vcpkg_from_git.cmake118
2 files changed, 119 insertions, 0 deletions
diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake
index 595ebb00e..c8b8fa977 100644
--- a/scripts/cmake/vcpkg_common_functions.cmake
+++ b/scripts/cmake/vcpkg_common_functions.cmake
@@ -27,4 +27,5 @@ include(vcpkg_get_program_files_32_bit)
include(vcpkg_get_program_files_platform_bitness)
include(vcpkg_get_windows_sdk)
include(vcpkg_replace_string)
+include(vcpkg_from_git)
include(vcpkg_test_cmake)
diff --git a/scripts/cmake/vcpkg_from_git.cmake b/scripts/cmake/vcpkg_from_git.cmake
new file mode 100644
index 000000000..c2965292d
--- /dev/null
+++ b/scripts/cmake/vcpkg_from_git.cmake
@@ -0,0 +1,118 @@
+## # vcpkg_from_git
+##
+## Download and extract a project from git
+##
+## ## Usage:
+## ```cmake
+## vcpkg_from_git(
+## OUT_SOURCE_PATH <SOURCE_PATH>
+## URL <https://android.googlesource.com/platform/external/fdlibm>
+## [REF <59f7335e4d...>]
+## [PATCHES <patch1.patch> <patch2.patch>...]
+## )
+## ```
+##
+## ## Parameters:
+## ### OUT_SOURCE_PATH
+## Specifies the out-variable that will contain the extracted location.
+##
+## This should be set to `SOURCE_PATH` by convention.
+##
+## ### URL
+## The url of the git repository.
+##
+## ### REF
+## The full commit id of the current latest master.
+##
+## ### PATCHES
+## A list of patches to be applied to the extracted sources.
+##
+## Relative paths are based on the port directory.
+##
+## ## Notes:
+## `REF` and `URL` must be specified.
+##
+## ## Examples:
+##
+## * [fdlibm](https://github.com/Microsoft/vcpkg/blob/master/ports/fdlibm/portfile.cmake)
+
+function(vcpkg_from_git)
+ set(oneValueArgs OUT_SOURCE_PATH URL REF SHA512)
+ set(multipleValuesArgs PATCHES)
+ cmake_parse_arguments(_vdud "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN})
+
+ if(NOT DEFINED _vdud_OUT_SOURCE_PATH)
+ message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.")
+ endif()
+
+ if(NOT DEFINED _vdud_URL)
+ message(FATAL_ERROR "The git url must be specified")
+ endif()
+
+ if(NOT DEFINED _vdud_REF)
+ message(FATAL_ERROR "The git ref must be specified.")
+ endif()
+
+ if(NOT DEFINED _vdud_SHA512)
+ message(FATAL_ERROR "vcpkg_from_git requires a SHA512 argument. If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.")
+ endif()
+
+ string(REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}")
+ set(TEMP_ARCHIVE "${DOWNLOADS}/temp/${PORT}-${SANITIZED_REF}.zip")
+ set(ARCHIVE "${DOWNLOADS}/${PORT}-${SANITIZED_REF}.zip")
+ set(TEMP_SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/${SANITIZED_REF}")
+
+ function(test_hash FILE_PATH FILE_KIND CUSTOM_ERROR_ADVICE)
+ file(SHA512 ${FILE_PATH} FILE_HASH)
+ if(NOT FILE_HASH STREQUAL _vdud_SHA512)
+ message(FATAL_ERROR
+ "\nFile does not have expected hash:\n"
+ " File path: [ ${FILE_PATH} ]\n"
+ " Expected hash: [ ${_vdud_SHA512} ]\n"
+ " Actual hash: [ ${FILE_HASH} ]\n"
+ "${CUSTOM_ERROR_ADVICE}\n")
+ endif()
+ endfunction()
+
+ if(NOT EXISTS "${ARCHIVE}")
+ if(_VCPKG_NO_DOWNLOADS)
+ message(FATAL_ERROR "Downloads are disabled, but '${ARCHIVE}' does not exist.")
+ endif()
+ message(STATUS "Fetching ${_vdud_URL}...")
+ find_program(GIT NAMES git git.cmd)
+ # Note: git init is safe to run multiple times
+ vcpkg_execute_required_process(
+ COMMAND ${GIT} init git-tmp
+ WORKING_DIRECTORY ${DOWNLOADS}
+ LOGNAME git-init
+ )
+ vcpkg_execute_required_process(
+ COMMAND ${GIT} fetch ${_vdud_URL} ${_vdud_REF} --depth 1 -n
+ WORKING_DIRECTORY ${DOWNLOADS}/git-tmp
+ LOGNAME git-fetch
+ )
+ file(MAKE_DIRECTORY "${DOWNLOADS}/temp")
+ vcpkg_execute_required_process(
+ COMMAND ${GIT} archive FETCH_HEAD -o "${TEMP_ARCHIVE}"
+ WORKING_DIRECTORY ${DOWNLOADS}/git-tmp
+ LOGNAME git-archive
+ )
+ test_hash("${TEMP_ARCHIVE}" "downloaded repo" "")
+ get_filename_component(downloaded_file_dir "${ARCHIVE}" DIRECTORY)
+ file(MAKE_DIRECTORY "${downloaded_file_dir}")
+ file(RENAME "${TEMP_ARCHIVE}" "${ARCHIVE}")
+ else()
+ message(STATUS "Using cached ${ARCHIVE}")
+ test_hash("${ARCHIVE}" "cached file" "Please delete the file and retry if this file should be downloaded again.")
+ endif()
+
+ vcpkg_extract_source_archive_ex(
+ OUT_SOURCE_PATH SOURCE_PATH
+ ARCHIVE "${ARCHIVE}"
+ REF "${SANITIZED_REF}"
+ PATCHES ${_vdud_PATCHES}
+ NO_REMOVE_ONE_LEVEL
+ )
+
+ set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)
+endfunction()