2020-12-02 05:37:26 +08:00
|
|
|
#[===[.md:
|
|
|
|
# vcpkg_from_github
|
|
|
|
|
|
|
|
Download and extract a project from GitHub. Enables support for `install --head`.
|
|
|
|
|
|
|
|
## Usage:
|
|
|
|
```cmake
|
|
|
|
vcpkg_from_github(
|
|
|
|
OUT_SOURCE_PATH <SOURCE_PATH>
|
|
|
|
REPO <Microsoft/cpprestsdk>
|
|
|
|
[REF <v2.0.0>]
|
|
|
|
[SHA512 <45d0d7f8cc350...>]
|
|
|
|
[HEAD_REF <master>]
|
|
|
|
[PATCHES <patch1.patch> <patch2.patch>...]
|
|
|
|
[GITHUB_HOST <https://github.com>]
|
|
|
|
[AUTHORIZATION_TOKEN <${SECRET_FROM_FILE}>]
|
2020-12-04 05:24:26 +08:00
|
|
|
[FILE_DISAMBIGUATOR <N>]
|
2020-12-02 05:37:26 +08:00
|
|
|
)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters:
|
|
|
|
### OUT_SOURCE_PATH
|
|
|
|
Specifies the out-variable that will contain the extracted location.
|
|
|
|
|
|
|
|
This should be set to `SOURCE_PATH` by convention.
|
|
|
|
|
|
|
|
### REPO
|
|
|
|
The organization or user and repository on GitHub.
|
|
|
|
|
|
|
|
### REF
|
|
|
|
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.
|
|
|
|
|
|
|
|
If `REF` is specified, `SHA512` must also be specified.
|
|
|
|
|
|
|
|
### SHA512
|
|
|
|
The SHA512 hash that should match the archive (https://github.com/${REPO}/archive/${REF}.tar.gz).
|
|
|
|
|
|
|
|
This is most easily determined by first setting it to `1`, then trying to build the port. The error message will contain the full hash, which can be copied back into the portfile.
|
|
|
|
|
|
|
|
### HEAD_REF
|
|
|
|
The unstable git commit-ish (ideally a branch) to pull for `--head` builds.
|
|
|
|
|
|
|
|
For most projects, this should be `master`. The chosen branch should be one that is expected to be always buildable on all supported platforms.
|
|
|
|
|
|
|
|
### PATCHES
|
|
|
|
A list of patches to be applied to the extracted sources.
|
|
|
|
|
|
|
|
Relative paths are based on the port directory.
|
|
|
|
|
|
|
|
### GITHUB_HOST
|
|
|
|
A replacement host for enterprise GitHub instances.
|
|
|
|
|
|
|
|
This field should contain the scheme, host, and port of the desired URL without a trailing slash.
|
|
|
|
|
|
|
|
### AUTHORIZATION_TOKEN
|
|
|
|
A token to be passed via the Authorization HTTP header as "token ${AUTHORIZATION_TOKEN}".
|
|
|
|
|
|
|
|
### FILE_DISAMBIGUATOR
|
|
|
|
A token to uniquely identify the resulting filename if the SHA512 changes even though a git ref does not, to avoid stepping on the same file name.
|
|
|
|
|
|
|
|
## Notes:
|
|
|
|
At least one of `REF` and `HEAD_REF` must be specified, however it is preferable for both to be present.
|
|
|
|
|
|
|
|
This exports the `VCPKG_HEAD_VERSION` variable during head builds.
|
|
|
|
|
|
|
|
## Examples:
|
|
|
|
|
|
|
|
* [cpprestsdk](https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake)
|
|
|
|
* [ms-gsl](https://github.com/Microsoft/vcpkg/blob/master/ports/ms-gsl/portfile.cmake)
|
2021-06-05 07:48:54 +08:00
|
|
|
* [boost-beast](https://github.com/Microsoft/vcpkg/blob/master/ports/boost-beast/portfile.cmake)
|
2020-12-02 05:37:26 +08:00
|
|
|
#]===]
|
|
|
|
|
2017-05-03 11:34:11 +08:00
|
|
|
function(vcpkg_from_github)
|
2020-11-06 09:25:46 +08:00
|
|
|
set(oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 HEAD_REF GITHUB_HOST AUTHORIZATION_TOKEN FILE_DISAMBIGUATOR)
|
2018-02-22 13:17:14 +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}")
|
2017-05-03 11:34:11 +08:00
|
|
|
|
2017-11-26 04:47:49 +08:00
|
|
|
if(NOT DEFINED _vdud_OUT_SOURCE_PATH)
|
2017-05-03 11:34:11 +08:00
|
|
|
message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.")
|
|
|
|
endif()
|
|
|
|
|
2017-11-26 04:47:49 +08:00
|
|
|
if((DEFINED _vdud_REF AND NOT DEFINED _vdud_SHA512) OR (NOT DEFINED _vdud_REF AND DEFINED _vdud_SHA512))
|
2017-05-03 11:34:11 +08:00
|
|
|
message(FATAL_ERROR "SHA512 must be specified if REF is specified.")
|
|
|
|
endif()
|
|
|
|
|
2017-11-26 04:47:49 +08:00
|
|
|
if(NOT DEFINED _vdud_REPO)
|
2017-05-03 11:34:11 +08:00
|
|
|
message(FATAL_ERROR "The GitHub repository must be specified.")
|
|
|
|
endif()
|
|
|
|
|
2017-11-26 04:47:49 +08:00
|
|
|
if(NOT DEFINED _vdud_REF AND NOT DEFINED _vdud_HEAD_REF)
|
2017-05-03 11:34:11 +08:00
|
|
|
message(FATAL_ERROR "At least one of REF and HEAD_REF must be specified.")
|
|
|
|
endif()
|
|
|
|
|
2019-11-23 02:05:39 +08:00
|
|
|
if(NOT DEFINED _vdud_GITHUB_HOST)
|
|
|
|
set(GITHUB_HOST https://github.com)
|
2019-03-19 02:32:22 +08:00
|
|
|
set(GITHUB_API_URL https://api.github.com)
|
|
|
|
else()
|
2020-11-06 09:25:46 +08:00
|
|
|
set(GITHUB_HOST "${_vdud_GITHUB_HOST}")
|
|
|
|
set(GITHUB_API_URL "${_vdud_GITHUB_HOST}/api/v3")
|
2019-03-19 02:32:22 +08:00
|
|
|
endif()
|
|
|
|
|
2019-11-23 02:05:39 +08:00
|
|
|
if(DEFINED _vdud_AUTHORIZATION_TOKEN)
|
|
|
|
set(HEADERS "HEADERS" "Authorization: token ${_vdud_AUTHORIZATION_TOKEN}")
|
|
|
|
else()
|
|
|
|
set(HEADERS)
|
2019-03-19 02:32:22 +08:00
|
|
|
endif()
|
|
|
|
|
2020-11-06 09:25:46 +08:00
|
|
|
string(REGEX REPLACE ".*/" "" REPO_NAME "${_vdud_REPO}")
|
|
|
|
string(REGEX REPLACE "/.*" "" ORG_NAME "${_vdud_REPO}")
|
2017-05-03 11:34:11 +08:00
|
|
|
|
2018-02-22 13:17:14 +08:00
|
|
|
macro(set_TEMP_SOURCE_PATH BASE BASEREF)
|
2018-09-05 07:20:46 +08:00
|
|
|
set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${BASEREF}")
|
2020-11-06 09:25:46 +08:00
|
|
|
if(NOT EXISTS "${TEMP_SOURCE_PATH}")
|
2018-09-05 07:20:46 +08:00
|
|
|
# Sometimes GitHub strips a leading 'v' off the REF.
|
2020-11-06 09:25:46 +08:00
|
|
|
string(REGEX REPLACE "^v" "" REF "${BASEREF}")
|
|
|
|
string(REPLACE "/" "-" REF "${REF}")
|
2018-09-05 07:20:46 +08:00
|
|
|
set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${REF}")
|
2020-11-06 09:25:46 +08:00
|
|
|
if(NOT EXISTS "${TEMP_SOURCE_PATH}")
|
2018-09-05 07:20:46 +08:00
|
|
|
message(FATAL_ERROR "Could not determine source path: '${BASE}/${REPO_NAME}-${BASEREF}' does not exist")
|
|
|
|
endif()
|
2017-05-03 11:34:11 +08:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2017-11-26 04:47:49 +08:00
|
|
|
if(VCPKG_USE_HEAD_VERSION AND NOT DEFINED _vdud_HEAD_REF)
|
2017-05-03 11:34:11 +08:00
|
|
|
message(STATUS "Package does not specify HEAD_REF. Falling back to non-HEAD version.")
|
|
|
|
set(VCPKG_USE_HEAD_VERSION OFF)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Handle --no-head scenarios
|
|
|
|
if(NOT VCPKG_USE_HEAD_VERSION)
|
|
|
|
if(NOT _vdud_REF)
|
|
|
|
message(FATAL_ERROR "Package does not specify REF. It must built using --head.")
|
|
|
|
endif()
|
|
|
|
|
2017-11-08 01:06:54 +08:00
|
|
|
string(REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}")
|
|
|
|
|
2020-11-06 09:25:46 +08:00
|
|
|
set(downloaded_file_name "${ORG_NAME}-${REPO_NAME}-${SANITIZED_REF}")
|
|
|
|
if (_vdud_FILE_DISAMBIGUATOR)
|
|
|
|
set(downloaded_file_name "${downloaded_file_name}-${_vdud_FILE_DISAMBIGUATOR}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(downloaded_file_name "${downloaded_file_name}.tar.gz")
|
|
|
|
|
2017-05-03 11:34:11 +08:00
|
|
|
vcpkg_download_distfile(ARCHIVE
|
2019-11-23 02:05:39 +08:00
|
|
|
URLS "${GITHUB_HOST}/${ORG_NAME}/${REPO_NAME}/archive/${_vdud_REF}.tar.gz"
|
2017-05-03 11:34:11 +08:00
|
|
|
SHA512 "${_vdud_SHA512}"
|
2020-11-06 09:25:46 +08:00
|
|
|
FILENAME "${downloaded_file_name}"
|
2019-03-19 02:32:22 +08:00
|
|
|
${HEADERS}
|
2017-05-03 11:34:11 +08:00
|
|
|
)
|
2018-02-22 13:17:14 +08:00
|
|
|
|
2018-09-05 07:20:46 +08:00
|
|
|
vcpkg_extract_source_archive_ex(
|
|
|
|
OUT_SOURCE_PATH SOURCE_PATH
|
|
|
|
ARCHIVE "${ARCHIVE}"
|
|
|
|
REF "${SANITIZED_REF}"
|
|
|
|
PATCHES ${_vdud_PATCHES}
|
|
|
|
)
|
2018-02-22 13:17:14 +08:00
|
|
|
|
|
|
|
set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)
|
2017-05-03 11:34:11 +08:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# The following is for --head scenarios
|
2019-11-23 02:05:39 +08:00
|
|
|
set(URL "${GITHUB_HOST}/${ORG_NAME}/${REPO_NAME}/archive/${_vdud_HEAD_REF}.tar.gz")
|
2017-11-08 01:06:54 +08:00
|
|
|
string(REPLACE "/" "-" SANITIZED_HEAD_REF "${_vdud_HEAD_REF}")
|
2020-11-06 09:25:46 +08:00
|
|
|
set(downloaded_file_name "${ORG_NAME}-${REPO_NAME}-${SANITIZED_HEAD_REF}")
|
|
|
|
if (_vdud_FILE_DISAMBIGUATOR)
|
|
|
|
set(downloaded_file_name "${downloaded_file_name}-${_vdud_FILE_DISAMBIGUATOR}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(downloaded_file_name "${downloaded_file_name}.tar.gz")
|
|
|
|
|
2017-11-04 05:34:08 +08:00
|
|
|
set(downloaded_file_path "${DOWNLOADS}/${downloaded_file_name}")
|
2017-05-03 11:34:11 +08:00
|
|
|
|
|
|
|
if(_VCPKG_NO_DOWNLOADS)
|
2020-11-06 09:25:46 +08:00
|
|
|
if(NOT EXISTS "${downloaded_file_path}" OR NOT EXISTS "${downloaded_file_path}.version")
|
2017-05-03 11:34:11 +08:00
|
|
|
message(FATAL_ERROR "Downloads are disabled, but '${downloaded_file_path}' does not exist.")
|
|
|
|
endif()
|
|
|
|
message(STATUS "Using cached ${downloaded_file_path}")
|
|
|
|
else()
|
2020-11-06 09:25:46 +08:00
|
|
|
if(EXISTS "${downloaded_file_path}")
|
2017-05-03 11:34:11 +08:00
|
|
|
message(STATUS "Purging cached ${downloaded_file_path} to fetch latest (use --no-downloads to suppress)")
|
2020-11-06 09:25:46 +08:00
|
|
|
file(REMOVE "${downloaded_file_path}")
|
2017-05-03 11:34:11 +08:00
|
|
|
endif()
|
2020-11-06 09:25:46 +08:00
|
|
|
if(EXISTS "${downloaded_file_path}.version")
|
|
|
|
file(REMOVE "${downloaded_file_path}.version")
|
2017-05-03 11:34:11 +08:00
|
|
|
endif()
|
2020-11-06 09:25:46 +08:00
|
|
|
if(EXISTS "${CURRENT_BUILDTREES_DIR}/src/head")
|
|
|
|
file(REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/src/head")
|
2017-05-03 11:34:11 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Try to download the file and version information from github.
|
2017-11-04 05:34:08 +08:00
|
|
|
vcpkg_download_distfile(ARCHIVE_VERSION
|
2019-03-19 02:32:22 +08:00
|
|
|
URLS "${GITHUB_API_URL}/repos/${ORG_NAME}/${REPO_NAME}/git/refs/heads/${_vdud_HEAD_REF}"
|
2020-11-06 09:25:46 +08:00
|
|
|
FILENAME "${downloaded_file_name}.version"
|
2017-12-30 06:21:18 +08:00
|
|
|
SKIP_SHA512
|
2019-03-19 02:32:22 +08:00
|
|
|
${HEADERS}
|
2017-05-03 11:34:11 +08:00
|
|
|
)
|
|
|
|
|
2017-11-04 05:34:08 +08:00
|
|
|
vcpkg_download_distfile(ARCHIVE
|
|
|
|
URLS ${URL}
|
2020-11-06 09:25:46 +08:00
|
|
|
FILENAME "${downloaded_file_name}"
|
2017-12-30 06:21:18 +08:00
|
|
|
SKIP_SHA512
|
2019-03-19 02:32:22 +08:00
|
|
|
${HEADERS}
|
2017-11-04 05:34:08 +08:00
|
|
|
)
|
2017-05-03 11:34:11 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Parse the github refs response with regex.
|
|
|
|
# TODO: use some JSON swiss-army-knife utility instead.
|
2019-06-06 05:23:09 +08:00
|
|
|
file(READ "${downloaded_file_path}.version" _contents)
|
2017-05-03 11:34:11 +08:00
|
|
|
string(REGEX MATCH "\"sha\": \"[a-f0-9]+\"" x "${_contents}")
|
|
|
|
string(REGEX REPLACE "\"sha\": \"([a-f0-9]+)\"" "\\1" _version ${x})
|
|
|
|
|
|
|
|
# exports VCPKG_HEAD_VERSION to the caller. This will get picked up by ports.cmake after the build.
|
2018-01-06 08:16:08 +08:00
|
|
|
# When multiple vcpkg_from_github's are used after each other, only use the version from the first (hopefully the primary one).
|
|
|
|
if(NOT DEFINED VCPKG_HEAD_VERSION)
|
2020-11-06 09:25:46 +08:00
|
|
|
set(VCPKG_HEAD_VERSION "${_version}" PARENT_SCOPE)
|
2018-01-06 08:16:08 +08:00
|
|
|
endif()
|
2017-05-03 11:34:11 +08:00
|
|
|
|
2018-09-05 07:20:46 +08:00
|
|
|
vcpkg_extract_source_archive_ex(
|
2019-10-08 01:35:13 +08:00
|
|
|
SKIP_PATCH_CHECK
|
2018-09-05 07:20:46 +08:00
|
|
|
OUT_SOURCE_PATH SOURCE_PATH
|
|
|
|
ARCHIVE "${downloaded_file_path}"
|
|
|
|
REF "${SANITIZED_HEAD_REF}"
|
2020-11-06 09:25:46 +08:00
|
|
|
WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/src/head"
|
2018-02-22 13:17:14 +08:00
|
|
|
PATCHES ${_vdud_PATCHES}
|
|
|
|
)
|
2018-09-05 07:20:46 +08:00
|
|
|
set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)
|
2017-05-03 11:34:11 +08:00
|
|
|
endfunction()
|