2020-12-02 05:37:26 +08:00
|
|
|
#[===[.md:
|
|
|
|
# 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...>
|
2021-01-11 16:27:56 +08:00
|
|
|
[TAG <v1.0.2>]
|
2020-12-02 05:37:26 +08: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.
|
|
|
|
|
|
|
|
### REF
|
|
|
|
The git sha of the commit to download.
|
|
|
|
|
2021-01-11 16:27:56 +08:00
|
|
|
### TAG
|
|
|
|
An optional git tag to be verified against the `REF`. If the remote repository's tag does not match the specified `REF`, the build will fail.
|
|
|
|
|
2020-12-02 05:37:26 +08:00
|
|
|
### PATCHES
|
|
|
|
A list of patches to be applied to the extracted sources.
|
|
|
|
|
|
|
|
Relative paths are based on the port directory.
|
|
|
|
|
2021-01-11 16:27:56 +08:00
|
|
|
### X_OUT_REF (internal only)
|
|
|
|
This parameter is used for automatic REF updates for certain ports in the central vcpkg catalog. It should not be used by any ports outside the central catalog and within the central catalog it should not be used on any user path. This parameter may change behavior incompatibly or be removed at any time.
|
|
|
|
|
2020-12-02 05:37:26 +08:00
|
|
|
## Notes:
|
|
|
|
`OUT_SOURCE_PATH`, `REF`, and `URL` must be specified.
|
|
|
|
|
|
|
|
## Examples:
|
|
|
|
|
|
|
|
* [fdlibm](https://github.com/Microsoft/vcpkg/blob/master/ports/fdlibm/portfile.cmake)
|
|
|
|
#]===]
|
2018-11-07 05:56:40 +08:00
|
|
|
|
2020-09-10 01:36:58 +08:00
|
|
|
include(vcpkg_execute_in_download_mode)
|
|
|
|
|
2018-11-07 05:56:40 +08:00
|
|
|
function(vcpkg_from_git)
|
2021-01-11 16:27:56 +08:00
|
|
|
set(oneValueArgs OUT_SOURCE_PATH URL REF TAG X_OUT_REF)
|
2018-11-07 05:56:40 +08:00
|
|
|
set(multipleValuesArgs PATCHES)
|
2020-10-27 10:30:27 +08:00
|
|
|
# parse parameters such that semicolons in options arguments to COMMAND don't get erased
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 _vdud "" "${oneValueArgs}" "${multipleValuesArgs}")
|
2018-11-07 05:56:40 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2019-07-02 13:39:51 +08:00
|
|
|
if(NOT DEFINED _vdud_REF)
|
|
|
|
message(FATAL_ERROR "The git ref must be specified.")
|
2018-11-07 05:56:40 +08:00
|
|
|
endif()
|
|
|
|
|
2021-01-11 16:27:56 +08:00
|
|
|
if(NOT DEFINED _vdud_TAG)
|
|
|
|
set(_vdud_TAG ${_vdud_REF})
|
|
|
|
endif()
|
|
|
|
|
2018-11-09 11:03:39 +08:00
|
|
|
# using .tar.gz instead of .zip because the hash of the latter is affected by timezone.
|
2021-01-11 16:27:56 +08:00
|
|
|
string(REPLACE "/" "-" SANITIZED_REF "${_vdud_TAG}")
|
2018-11-09 11:03:39 +08:00
|
|
|
set(TEMP_ARCHIVE "${DOWNLOADS}/temp/${PORT}-${SANITIZED_REF}.tar.gz")
|
|
|
|
set(ARCHIVE "${DOWNLOADS}/${PORT}-${SANITIZED_REF}.tar.gz")
|
2018-11-07 05:56:40 +08:00
|
|
|
set(TEMP_SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/${SANITIZED_REF}")
|
|
|
|
|
|
|
|
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(
|
2019-08-29 04:49:29 +08:00
|
|
|
ALLOW_IN_DOWNLOAD_MODE
|
2018-11-07 05:56:40 +08:00
|
|
|
COMMAND ${GIT} init git-tmp
|
|
|
|
WORKING_DIRECTORY ${DOWNLOADS}
|
2019-07-02 13:39:51 +08:00
|
|
|
LOGNAME git-init-${TARGET_TRIPLET}
|
2018-11-07 05:56:40 +08:00
|
|
|
)
|
|
|
|
vcpkg_execute_required_process(
|
2019-08-29 04:49:29 +08:00
|
|
|
ALLOW_IN_DOWNLOAD_MODE
|
2021-01-11 16:27:56 +08:00
|
|
|
COMMAND ${GIT} fetch ${_vdud_URL} ${_vdud_TAG} --depth 1 -n
|
2018-11-07 05:56:40 +08:00
|
|
|
WORKING_DIRECTORY ${DOWNLOADS}/git-tmp
|
2019-07-02 13:39:51 +08:00
|
|
|
LOGNAME git-fetch-${TARGET_TRIPLET}
|
|
|
|
)
|
2020-09-10 01:36:58 +08:00
|
|
|
vcpkg_execute_in_download_mode(
|
2019-07-02 13:39:51 +08:00
|
|
|
COMMAND ${GIT} rev-parse FETCH_HEAD
|
|
|
|
OUTPUT_VARIABLE REV_PARSE_HEAD
|
|
|
|
ERROR_VARIABLE REV_PARSE_HEAD
|
|
|
|
RESULT_VARIABLE error_code
|
|
|
|
WORKING_DIRECTORY ${DOWNLOADS}/git-tmp
|
2018-11-07 05:56:40 +08:00
|
|
|
)
|
2019-07-02 13:39:51 +08:00
|
|
|
if(error_code)
|
|
|
|
message(FATAL_ERROR "unable to determine FETCH_HEAD after fetching git repository")
|
|
|
|
endif()
|
|
|
|
string(REGEX REPLACE "\n$" "" REV_PARSE_HEAD "${REV_PARSE_HEAD}")
|
2021-01-11 16:27:56 +08:00
|
|
|
if(NOT REV_PARSE_HEAD STREQUAL _vdud_REF AND NOT DEFINED _vdud_X_OUT_REF)
|
|
|
|
message(STATUS "[Expected : ( ${_vdud_REF} )]")
|
|
|
|
message(STATUS "[ Actual : ( ${REV_PARSE_HEAD} )]")
|
2019-07-02 13:39:51 +08:00
|
|
|
message(FATAL_ERROR "REF (${_vdud_REF}) does not match FETCH_HEAD (${REV_PARSE_HEAD})")
|
2021-01-11 16:27:56 +08:00
|
|
|
elseif(DEFINED _vdud_X_OUT_REF)
|
|
|
|
set(${_vdud_X_OUT_REF} ${REV_PARSE_HEAD} PARENT_SCOPE)
|
|
|
|
return()
|
2019-07-02 13:39:51 +08:00
|
|
|
endif()
|
|
|
|
|
2018-11-07 05:56:40 +08:00
|
|
|
file(MAKE_DIRECTORY "${DOWNLOADS}/temp")
|
|
|
|
vcpkg_execute_required_process(
|
2019-08-29 04:49:29 +08:00
|
|
|
ALLOW_IN_DOWNLOAD_MODE
|
2018-11-07 05:56:40 +08:00
|
|
|
COMMAND ${GIT} archive FETCH_HEAD -o "${TEMP_ARCHIVE}"
|
|
|
|
WORKING_DIRECTORY ${DOWNLOADS}/git-tmp
|
|
|
|
LOGNAME git-archive
|
|
|
|
)
|
2019-07-02 13:39:51 +08:00
|
|
|
|
2018-11-07 05:56:40 +08:00
|
|
|
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}")
|
|
|
|
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()
|