Skip to content

Commit

Permalink
[vcpkg] Add vcpkg_minimum_required as a replacement for VERSION.txt. (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyONeal authored Jan 20, 2021
1 parent 45fc558 commit 4d136ef
Show file tree
Hide file tree
Showing 69 changed files with 579 additions and 460 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,4 @@ prefab/
###################
pythonenv3.8/
.venv/

1 change: 1 addition & 0 deletions docs/maintainers/portfile-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@
- [vcpkg\_install\_nmake](vcpkg_install_nmake.md)
- [vcpkg\_install\_qmake](vcpkg_install_qmake.md)
- [vcpkg\_internal\_get\_cmake\_vars](vcpkg_internal_get_cmake_vars.md)
- [vcpkg\_minimum\_required](vcpkg_minimum_required.md)
- [vcpkg\_prettify\_command](vcpkg_prettify_command.md)
- [vcpkg\_replace\_string](vcpkg_replace_string.md)
15 changes: 15 additions & 0 deletions docs/maintainers/vcpkg_minimum_required.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# vcpkg_minimum_required

Asserts that the version of the vcpkg program being used to build a port is later than the supplied date, inclusive.

## Usage
```cmake
vcpkg_minimum_required(VERSION 2021-01-13)
```

## Parameters
### VERSION
The date-version to check against.

## Source
[scripts/cmake/vcpkg_minimum_required.cmake](https://github.com/Microsoft/vcpkg/blob/master/scripts/cmake/vcpkg_minimum_required.cmake)
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ foreach ($backcompatFeaturePort in $backcompatFeaturePorts) {
$succeedArgs = $commonArgs + @('install',$backcompatFeaturePort,'--no-binarycaching')
$failArgs = $succeedArgs + @('--x-prohibit-backcompat-features')
$CurrentTest = "Should fail: ./vcpkg $($failArgs -join ' ')"
Write-Host $CurrentTest
./vcpkg @failArgs
Run-Vcpkg @failArgs
if ($LastExitCode -ne 0) {
Write-Host "... failed (this is good!)"
Write-Host "... failed (this is good!)."
} else {
throw $CurrentTest
}

# Install failed when prohibiting backcompat features, so it should succeed if we allow them
$CurrentTest = "Should succeeed: ./vcpkg $($succeedArgs -join ' ')"
Write-Host $CurrentTest
./vcpkg @succeedArgs
Run-Vcpkg @succeedArgs
if ($LastExitCode -ne 0) {
throw $CurrentTest
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
if ($IsLinux) {
# The tests below need a mono installation not currently available on the Linux agents.
return
}

. $PSScriptRoot/../end-to-end-tests-prelude.ps1

# Test simple installation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

$successCases = @('vcpkg-requires-current-date', 'vcpkg-requires-old-date')
foreach ($successCase in $successCases) {
$CurrentTest = "Should succeeed: ./vcpkg install $successCase"
Write-Host $CurrentTest
Run-Vcpkg install $successCase @commonArgs
if ($LastExitCode -ne 0) {
throw $CurrentTest
} else {
Write-Host "... succeeded."
}
}

$CurrentTest = "Should fail: ./vcpkg install vcpkg-requires-future-date"
Write-Host $CurrentTest
Run-Vcpkg install vcpkg-requires-future-date @commonArgs
if ($LastExitCode -ne 0) {
Write-Host "... failed (this is good!)."
} else {
throw $CurrentTest
}
5 changes: 5 additions & 0 deletions scripts/azure-pipelines/end-to-end-tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Param(

$ErrorActionPreference = "Stop"

if (-Not (Test-Path $WorkingRoot)) {
New-Item -Path $WorkingRoot -ItemType Directory
}

$WorkingRoot = (Get-Item $WorkingRoot).FullName

$AllTests = Get-ChildItem $PSScriptRoot/end-to-end-tests-dir/*.ps1
Expand All @@ -47,4 +51,5 @@ $AllTests | % {
$n += 1
}

Write-Host "[end-to-end-tests.ps1] All tests passed."
$LASTEXITCODE = 0
7 changes: 7 additions & 0 deletions scripts/azure-pipelines/linux/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,19 @@ jobs:
arguments: '-buildTests'
- bash: toolsrc/build.rel/vcpkg-test
displayName: 'Run vcpkg tests'
- task: PowerShell@2
displayName: 'Run vcpkg end-to-end tests'
inputs:
filePath: 'scripts/azure-pipelines/end-to-end-tests.ps1'
arguments: '-Triplet x64-linux -WorkingRoot ${{ variables.WORKING_ROOT }}'
pwsh: true
- task: PowerShell@2
displayName: '*** Test Modified Ports and Prepare Test Logs ***'
inputs:
failOnStderr: true
filePath: 'scripts/azure-pipelines/test-modified-ports.ps1'
arguments: '-Triplet x64-linux -BuildReason $(Build.Reason) -UseEnvironmentSasToken -WorkingRoot ${{ variables.WORKING_ROOT }} -ArtifactStagingDirectory $(Build.ArtifactStagingDirectory)'
pwsh: true
- bash: |
df -h
displayName: 'Report on Disk Space After Build'
Expand Down
2 changes: 2 additions & 0 deletions scripts/azure-pipelines/osx/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ jobs:
inputs:
filePath: 'scripts/azure-pipelines/end-to-end-tests.ps1'
arguments: '-Triplet x64-osx -WorkingRoot ${{ variables.WORKING_ROOT }}'
pwsh: true
- task: PowerShell@2
displayName: '*** Test Modified Ports and Prepare Test Logs ***'
inputs:
failOnStderr: true
filePath: 'scripts/azure-pipelines/test-modified-ports.ps1'
arguments: '-Triplet x64-osx -BuildReason $(Build.Reason) -BinarySourceStub "$(BINARY_SOURCE_STUB)" -WorkingRoot ${{ variables.WORKING_ROOT }} -ArtifactStagingDirectory $(Build.ArtifactStagingDirectory)'
pwsh: true
- bash: |
df -h
displayName: 'Report on Disk Space After Build'
Expand Down
3 changes: 2 additions & 1 deletion scripts/bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ else
}

$arguments = (
"`"/p:VCPKG_VERSION=-unknownhash`"",
"`"/p:VCPKG_VERSION=unknownhash`"",
"`"/p:VCPKG_BASE_VERSION=2021-01-13`"", # Note: This duplicate date version will be short lived. See https://github.com/microsoft/vcpkg/pull/15474
"/p:Configuration=Release",
"/p:Platform=$platform",
"/p:PlatformToolset=$platformToolset",
Expand Down
49 changes: 49 additions & 0 deletions scripts/cmake/vcpkg_minimum_required.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#[===[.md:
# vcpkg_minimum_required
Asserts that the version of the vcpkg program being used to build a port is later than the supplied date, inclusive.
## Usage
```cmake
vcpkg_minimum_required(VERSION 2021-01-13)
```
## Parameters
### VERSION
The date-version to check against.
#]===]

function(vcpkg_minimum_required)
cmake_parse_arguments(PARSE_ARGV 0 _vcpkg "" "VERSION" "")
if (NOT DEFINED VCPKG_BASE_VERSION)
message(FATAL_ERROR
"Your vcpkg executable is outdated and is not compatible with the current CMake scripts. "
"Please re-acquire vcpkg by running bootstrap-vcpkg."
)
endif()

set(_vcpkg_date_regex "^[12][0-9][0-9][0-9]-[01][0-9]-[0-3][0-9]$")
if (NOT VCPKG_BASE_VERSION MATCHES "${_vcpkg_date_regex}")
message(FATAL_ERROR
"vcpkg internal failure; \${VCPKG_BASE_VERSION} (${VCPKG_BASE_VERSION}) was not a valid date."
)
endif()

if (NOT _vcpkg_VERSION MATCHES "${_vcpkg_date_regex}")
message(FATAL_ERROR
"VERSION parameter to vcpkg_minimum_required was not a valid date. "
"Comparing with vcpkg tool version ${_vcpkg_matched_base_version}"
)
endif()

string(REPLACE "-" "." _VCPKG_BASE_VERSION_as_dotted "${VCPKG_BASE_VERSION}")
string(REPLACE "-" "." _vcpkg_VERSION_as_dotted "${_vcpkg_VERSION}")

if (_VCPKG_BASE_VERSION_as_dotted VERSION_LESS _vcpkg_VERSION_as_dotted)
message(FATAL_ERROR
"Your vcpkg executable is from ${VCPKG_BASE_VERSION} which is older than required by the caller "
"of vcpkg_minimum_required (${_vcpkg_VERSION}). "
"Please re-acquire vcpkg by running bootstrap-vcpkg."
)
endif()
endfunction()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vcpkg_minimum_required(VERSION ${VCPKG_BASE_VERSION})
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "vcpkg-requires-current-date",
"version-string": "1.0.0",
"description": "A test port that verifies that vcpkg_minimum_required is inclusive by using the current base version value.",
"homepage": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vcpkg_minimum_required(VERSION 2999-12-31)
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "vcpkg-requires-future-date",
"version-string": "1.0.0",
"description": "A test port that requires a vcpkg version from an impossibly far future.",
"homepage": ""
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
vcpkg_minimum_required(VERSION 2020-01-12)
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
6 changes: 6 additions & 0 deletions scripts/e2e_ports/overlays/vcpkg-requires-old-date/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "vcpkg-requires-old-date",
"version-string": "1.0.0",
"description": "A test port that requires a vcpkg version from before vcpkg_minimum_required's introduction.",
"homepage": ""
}
14 changes: 3 additions & 11 deletions scripts/ports.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,13 @@ else()
set(_VCPKG_BACKCOMPAT_MESSAGE_LEVEL "WARNING")
endif()

if((NOT DEFINED VCPKG_ROOT_DIR)
OR (NOT DEFINED DOWNLOADS)
OR (NOT DEFINED _VCPKG_INSTALLED_DIR)
OR (NOT DEFINED PACKAGES_DIR)
OR (NOT DEFINED BUILDTREES_DIR))
message(FATAL_ERROR [[
Your vcpkg executable is outdated and is not compatible with the current CMake scripts.
Please re-build vcpkg by running bootstrap-vcpkg.
]])
endif()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(vcpkg_minimum_required)
vcpkg_minimum_required(VERSION 2021-01-13)

file(TO_CMAKE_PATH ${BUILDTREES_DIR} BUILDTREES_DIR)
file(TO_CMAKE_PATH ${PACKAGES_DIR} PACKAGES_DIR)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
set(CURRENT_INSTALLED_DIR ${_VCPKG_INSTALLED_DIR}/${TARGET_TRIPLET} CACHE PATH "Location to install final packages")
set(SCRIPTS ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Location to stored scripts")

Expand Down
10 changes: 7 additions & 3 deletions toolsrc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ if (VCPKG_EMBED_GIT_SHA)
endif()
endif()

if (VCPKG_VERSION STREQUAL "")
set(VCPKG_VERSION "nohash")
if (NOT DEFINED VCPKG_VERSION OR VCPKG_VERSION STREQUAL "")
set(VCPKG_VERSION "unknownhash")
endif()

set(VCPKG_BASE_VERSION "2021-01-13")

set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -115,7 +117,9 @@ target_include_directories(vcpkglib PUBLIC include)
vcpkg_target_add_warning_options(vcpkglib)
target_compile_definitions(vcpkglib PUBLIC
VCPKG_USE_STD_FILESYSTEM=$<BOOL:${VCPKG_USE_STD_FILESYSTEM}>
VCPKG_VERSION=${VCPKG_VERSION})
VCPKG_VERSION=${VCPKG_VERSION}
VCPKG_BASE_VERSION=${VCPKG_BASE_VERSION}
)

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
Expand Down
1 change: 0 additions & 1 deletion toolsrc/VERSION.txt

This file was deleted.

1 change: 1 addition & 0 deletions toolsrc/include/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <mutex>
Expand Down
41 changes: 41 additions & 0 deletions toolsrc/include/vcpkg/base/basic_checks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <vcpkg/base/lineinfo.h>
#include <vcpkg/base/stringview.h>

namespace vcpkg::Checks
{
void register_global_shutdown_handler(void (*func)());

// Note: for internal use
[[noreturn]] void final_cleanup_and_exit(const int exit_code);

// Indicate that an internal error has occurred and exit the tool. This should be used when invariants have been
// broken.
[[noreturn]] void unreachable(const LineInfo& line_info);

[[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code);

// Exit the tool without an error message.
[[noreturn]] void exit_fail(const LineInfo& line_info);

// Exit the tool successfully.
[[noreturn]] void exit_success(const LineInfo& line_info);

// Display an error message to the user and exit the tool.
[[noreturn]] void exit_with_message(const LineInfo& line_info, StringView error_message);

// If expression is false, call exit_fail.
void check_exit(const LineInfo& line_info, bool expression);

// if expression is false, call exit_with_message.
void check_exit(const LineInfo& line_info, bool expression, StringView error_message);

// Display a message indicating that vcpkg should be upgraded and exit.
[[noreturn]] void exit_maybe_upgrade(const LineInfo& line_info);
[[noreturn]] void exit_maybe_upgrade(const LineInfo& line_info, StringView error_message);

// Check the indicated condition and call exit_maybe_upgrade if it is false.
void check_maybe_upgrade(const LineInfo& line_info, bool condition);
void check_maybe_upgrade(const LineInfo& line_info, bool condition, StringView error_message);
}
51 changes: 27 additions & 24 deletions toolsrc/include/vcpkg/base/checks.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
#pragma once

#include <vcpkg/base/cstringview.h>
#include <vcpkg/base/basic_checks.h>
#include <vcpkg/base/strings.h>

namespace vcpkg::Checks
{
void register_global_shutdown_handler(void (*func)());

// Note: for internal use
[[noreturn]] void final_cleanup_and_exit(const int exit_code);

// Indicate that an internal error has occurred and exit the tool. This should be used when invariants have been
// broken.
[[noreturn]] void unreachable(const LineInfo& line_info);

[[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code);

// Exit the tool without an error message.
[[noreturn]] inline void exit_fail(const LineInfo& line_info) { exit_with_code(line_info, EXIT_FAILURE); }

// Exit the tool successfully.
[[noreturn]] inline void exit_success(const LineInfo& line_info) { exit_with_code(line_info, EXIT_SUCCESS); }

// Display an error message to the user and exit the tool.
[[noreturn]] void exit_with_message(const LineInfo& line_info, StringView error_message);
// Additional convenience overloads on top of basic_checks.h that do formatting.

template<class Arg1, class... Args>
// Display an error message to the user and exit the tool.
Expand All @@ -36,10 +18,6 @@ namespace vcpkg::Checks
Strings::format(error_message_template, error_message_arg1, error_message_args...));
}

void check_exit(const LineInfo& line_info, bool expression);

void check_exit(const LineInfo& line_info, bool expression, StringView error_message);

template<class Conditional, class Arg1, class... Args>
void check_exit(const LineInfo& line_info,
Conditional&& expression,
Expand All @@ -54,4 +32,29 @@ namespace vcpkg::Checks
Strings::format(error_message_template, error_message_arg1, error_message_args...));
}
}

template<class Arg1, class... Args>
[[noreturn]] void exit_maybe_upgrade(const LineInfo& line_info,
const char* error_message_template,
const Arg1& error_message_arg1,
const Args&... error_message_args)
{
exit_maybe_upgrade(line_info,
Strings::format(error_message_template, error_message_arg1, error_message_args...));
}

template<class Conditional, class Arg1, class... Args>
void check_maybe_upgrade(const LineInfo& line_info,
Conditional&& expression,
const char* error_message_template,
const Arg1& error_message_arg1,
const Args&... error_message_args)
{
if (!expression)
{
// Only create the string if the expression is false
exit_maybe_upgrade(line_info,
Strings::format(error_message_template, error_message_arg1, error_message_args...));
}
}
}
Loading

0 comments on commit 4d136ef

Please sign in to comment.