2018-11-06 23:56:40 +02:00
## # 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>
2018-11-06 15:47:02 -08:00
## REF <59f7335e4d...>
## SHA512 <abcdef123...>
2018-11-06 23:56:40 +02:00
## [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.
##
2018-11-06 15:47:02 -08:00
## ### SHA512
## The SHA512 hash that should match the archive form of the commit.
##
## This is most easily determined by first setting it to `0`, then trying to build the port. The error message will contain the full hash, which can be copied back into the portfile.
##
2018-11-06 23:56:40 +02:00
## ### REF
2018-11-06 15:47:02 -08:00
## A stable git commit-ish (ideally a tag or commit) that will not change contents. **This should not be a branch.**
##
## For repositories without official releases, this can be set to the full commit id of the current latest master.
2018-11-06 23:56:40 +02:00
##
## ### PATCHES
## A list of patches to be applied to the extracted sources.
##
## Relative paths are based on the port directory.
##
## ## Notes:
2018-11-06 15:47:02 -08:00
## `OUT_SOURCE_PATH`, `REF`, `SHA512`, and `URL` must be specified.
2018-11-06 23:56:40 +02:00
##
## ## 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 ( )
2018-11-08 19:03:39 -08:00
# using .tar.gz instead of .zip because the hash of the latter is affected by timezone.
2018-11-06 23:56:40 +02:00
string ( REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}" )
2018-11-08 19:03:39 -08:00
set ( TEMP_ARCHIVE "${DOWNLOADS}/temp/${PORT}-${SANITIZED_REF}.tar.gz" )
set ( ARCHIVE "${DOWNLOADS}/${PORT}-${SANITIZED_REF}.tar.gz" )
2018-11-06 23:56:40 +02:00
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
" \ n F i l e d o e s n o t h a v e e x p e c t e d h a s h : \ n "
" F i l e p a t h : [ $ { F I L E _ P A T H } ] \ n "
" E x p e c t e d h a s h : [ $ { _ v d u d _ S H A 5 1 2 } ] \ n "
" A c t u a l h a s h : [ $ { F I L E _ H A S H } ] \ n "
" $ { C U S T O M _ E R R O R _ A D V I C E } \ 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 (
C O M M A N D $ { G I T } i n i t g i t - t m p
W O R K I N G _ D I R E C T O R Y $ { D O W N L O A D S }
L O G N A M E g i t - i n i t
)
vcpkg_execute_required_process (
C O M M A N D $ { G I T } f e t c h $ { _ v d u d _ U R L } $ { _ v d u d _ R E F } - - d e p t h 1 - n
W O R K I N G _ D I R E C T O R Y $ { D O W N L O A D S } / g i t - t m p
L O G N A M E g i t - f e t c h
)
file ( MAKE_DIRECTORY "${DOWNLOADS}/temp" )
vcpkg_execute_required_process (
C O M M A N D $ { G I T } a r c h i v e F E T C H _ H E A D - o " $ { T E M P _ A R C H I V E } "
W O R K I N G _ D I R E C T O R Y $ { D O W N L O A D S } / g i t - t m p
L O G N A M E g i t - a r c h i v e
)
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 (
O U T _ S O U R C E _ P A T H S O U R C E _ P A T H
A R C H I V E " $ { A R C H I V E } "
R E F " $ { S A N I T I Z E D _ R E F } "
P A T C H E S $ { _ v d u d _ P A T C H E S }
N O _ R E M O V E _ O N E _ L E V E L
)
set ( ${ _vdud_OUT_SOURCE_PATH } "${SOURCE_PATH}" PARENT_SCOPE )
endfunction ( )