Skip to content

Commit

Permalink
[vcpkg] Add commands to maintain and verify versions db integrity (mi…
Browse files Browse the repository at this point in the history
…crosoft#14999)

* [vcpkg] Add x-ci-verify-versions command

* Code cleanup

* Remove port version splitting from x-history

* Fix wrong message on success

* Parallelize versions file generator

* Use cpu_count()/2 to avoid crashes

* Check db SHA against local SHA

* Check baseline version with x-ci-verify-versions and make baseline generator much faster

* Implement x-add-version to update version db files

* Better checks for x-add-info and make x-ci-verify-versions silent on success

* Use find() instead of [] on maps

* Create version file if does not exist

* Allow redirection of ports/ and port_versions/

* add test ports

* WIP end-to-end tests

* Change pats in e2e tests

* Fix e2e args

* e2e once more

* Pass �ersions feature flag to e2e

* Exit with code 1 if there are errors

* Files to test for failure cases

* Update test files

* Add test for x-add-version

* fix redirected ports in last test

* Add CI check (use dummy data)

* Add feature-flags=versions

* Ignore subdirectories inside ports

* Add --verify-git-trees switch

* [vcpkg] Fix build breaks

* [x-ci-verify-versions] PR comments

* [x-add-version] PR comments

* Fix merge conflicts

* Modify tests and pipeline

* Baselines should only have version-string

* Refactor x-add-version

* [vcpkg] Fix help message

* [vcpkg] Fix minor warnings

* `x-add-version --all` doesn't stop on first failure and reduced default verbosity

* [vcpkg] Fix default-baseline

* Load file instead of using paths provider

* Format

* Remove ci test

* Add fish port for testing

* Update version files

* Update fish port to cause SHA discrepancy

* Test for discrepancy between local SHA and declared SHA

* Missing = operator

* Check for error message since x-add-version exits with code 0

* Make x-add-version fail with non-zero exit code if not run with --all

Co-authored-by: Robert Schumacher <[email protected]>
Co-authored-by: Robert Schumacher <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2021
1 parent d717d41 commit 2a42024
Show file tree
Hide file tree
Showing 49 changed files with 1,146 additions and 37 deletions.
75 changes: 75 additions & 0 deletions scripts/azure-pipelines/end-to-end-tests-dir/versions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

# Test verify versions
mkdir $VersionFilesRoot
Copy-Item -Recurse "scripts/testing/version-files/port_versions_incomplete" $VersionFilesRoot
$portsRedirectArgsOK = @(
"--feature-flags=versions",
"--x-builtin-ports-root=scripts/testing/version-files/ports",
"--x-builtin-port-versions-dir=scripts/testing/version-files/port_versions"
)
$portsRedirectArgsIncomplete = @(
"--feature-flags=versions",
"--x-builtin-ports-root=scripts/testing/version-files/ports_incomplete",
"--x-builtin-port-versions-dir=$VersionFilesRoot/port_versions_incomplete"
)
$CurrentTest = "x-verify-ci-versions (All files OK)"
Write-Host $CurrentTest
./vcpkg $portsRedirectArgsOK x-ci-verify-versions --verbose
Throw-IfFailed

$CurrentTest = "x-verify-ci-versions (Incomplete)"
./vcpkg $portsRedirectArgsIncomplete x-ci-verify-versions --verbose
Throw-IfNotFailed

$CurrentTest = "x-add-version cat"
# Do not fail if there's nothing to update
./vcpkg $portsRedirectArgsIncomplete x-add-version cat
Throw-IfFailed

$CurrentTest = "x-add-version dog"
# Local version is not in baseline and versions file
./vcpkg $portsRedirectArgsIncomplete x-add-version dog
Throw-IfFailed

$CurrentTest = "x-add-version duck"
# Missing versions file
./vcpkg $portsRedirectArgsIncomplete x-add-version duck
Throw-IfFailed

$CurrentTest = "x-add-version ferret"
# Missing versions file and missing baseline entry
./vcpkg $portsRedirectArgsIncomplete x-add-version ferret
Throw-IfFailed

$CurrentTest = "x-add-version fish (must fail)"
# Discrepancy between local SHA and SHA in fish.json. Requires --overwrite-version.
$out = ./vcpkg $portsRedirectArgsIncomplete x-add-version fish
Throw-IfNotFailed
$CurrentTest = "x-add-version fish --overwrite-version"
./vcpkg $portsRedirectArgsIncomplete x-add-version fish --overwrite-version
Throw-IfFailed

$CurrentTest = "x-add-version mouse"
# Missing baseline entry
./vcpkg $portsRedirectArgsIncomplete x-add-version mouse
Throw-IfFailed
# Validate changes
./vcpkg $portsRedirectArgsIncomplete x-ci-verify-versions --verbose
Throw-IfFailed

$CurrentTest = "default baseline"
$out = ./vcpkg $commonArgs "--feature-flags=versions" install --x-manifest-root=scripts/testing/version-files/default-baseline-1
Throw-IfNotFailed
# if ($out -notmatch "Error: while checking out baseline" -or $out -notmatch " does not exist in ")
# {
# $out
# throw "Expected to fail due to missing baseline"
# }

git fetch https://github.com/vicroms/test-registries
$CurrentTest = "default baseline"
./vcpkg $commonArgs "--feature-flags=versions" install `
"--x-manifest-root=scripts/testing/version-files/default-baseline-2" `
"--x-builtin-port-versions-dir=scripts/testing/version-files/default-baseline-2/port_versions"
Throw-IfFailed
8 changes: 8 additions & 0 deletions scripts/testing/version-files/default-baseline-1/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "default-baseline-test",
"version-string": "0",
"$x-default-baseline": "fca18ba3572f8aebe3b8158c359db62a7e26134e",
"dependencies": [
"zlib"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"versions": [
{
"git-tree": "7bb2b2f3783303a4dd41163553fe4cc103dc9262",
"version-string": "1.2.11",
"port-version": 9
},
{
"git-tree": "4927735fa9baca564ebddf6e6880de344b20d7a8",
"version-string": "1.2.11",
"port-version": 8
}
]
}
8 changes: 8 additions & 0 deletions scripts/testing/version-files/default-baseline-2/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "default-baseline-test",
"version-string": "0",
"$x-default-baseline": "cbd5a68012471f820b7cf28d618199b4a4d89c58",
"dependencies": [
"zlib"
]
}
20 changes: 20 additions & 0 deletions scripts/testing/version-files/port_versions/baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"default": {
"cat": {
"version-string": "1.0",
"port-version": 0
},
"dog": {
"version-string": "2001-01-01",
"port-version": 0
},
"duck": {
"version-string": "mallard",
"port-version": 0
},
"mouse": {
"version-string": "1.0.0",
"port-version": 0
}
}
}
9 changes: 9 additions & 0 deletions scripts/testing/version-files/port_versions/c-/cat.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "5dd257451526d5b9e560f5f35d7029ba40d88587",
"version": "1.0",
"port-version": 0
}
]
}
9 changes: 9 additions & 0 deletions scripts/testing/version-files/port_versions/d-/dog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "e170a2ed0da7ba5d434c4a0a98ffd7a3159e3200",
"version-date": "2001-01-01",
"port-version": 0
}
]
}
9 changes: 9 additions & 0 deletions scripts/testing/version-files/port_versions/d-/duck.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "0a52a9d722c75b3bfe47d5f5db6c9eb1a64af156",
"version-string": "mallard",
"port-version": 0
}
]
}
9 changes: 9 additions & 0 deletions scripts/testing/version-files/port_versions/m-/mouse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "55ed624191e0a1905bd97af29fdf6a1d7f4e6d7c",
"version-semver": "1.0.0",
"port-version": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"default": {
"cat": {
"version-string": "1.0",
"port-version": 0
},
"dog": {
"version-string": "2001-01-01",
"port-version": 0
},
"duck": {
"version-string": "mallard",
"port-version": 0
},
"fish": {
"version-string": "1.0.0",
"port-version": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "5dd257451526d5b9e560f5f35d7029ba40d88587",
"version": "1.0",
"port-version": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "e170a2ed0da7ba5d434c4a0a98ffd7a3159e3200",
"version-date": "2001-01-01",
"port-version": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "cf3be634f203c1b4152b65ec7700d5695a1fca5c",
"version-string": "1.0.0",
"port-version": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "55ed624191e0a1905bd97af29fdf6a1d7f4e6d7c",
"version-semver": "1.0.0",
"port-version": 0
}
]
}
1 change: 1 addition & 0 deletions scripts/testing/version-files/ports/cat/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 4 additions & 0 deletions scripts/testing/version-files/ports/cat/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "cat",
"version": "1.0"
}
1 change: 1 addition & 0 deletions scripts/testing/version-files/ports/dog/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 4 additions & 0 deletions scripts/testing/version-files/ports/dog/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "dog",
"version-date": "2001-01-01"
}
1 change: 1 addition & 0 deletions scripts/testing/version-files/ports/duck/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 4 additions & 0 deletions scripts/testing/version-files/ports/duck/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "duck",
"version-string": "mallard"
}
1 change: 1 addition & 0 deletions scripts/testing/version-files/ports/mouse/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 4 additions & 0 deletions scripts/testing/version-files/ports/mouse/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "mouse",
"version-semver": "1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
4 changes: 4 additions & 0 deletions scripts/testing/version-files/ports_incomplete/cat/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "cat",
"version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
5 changes: 5 additions & 0 deletions scripts/testing/version-files/ports_incomplete/dog/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "dog",
"version-date": "2001-01-01",
"port-version": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "duck",
"version-string": "mallard"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "ferret",
"version": "1"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "fish",
"version-string": "1.0.0",
"description": "This description causes an intentional discrepancy between the local SHA and the SHA in fish.json for version 1.0.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "mouse",
"version-semver": "1.0.0"
}
13 changes: 13 additions & 0 deletions toolsrc/include/vcpkg/commands.add-version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands::AddVersion
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct AddVersionCommand : PathsCommand
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
13 changes: 13 additions & 0 deletions toolsrc/include/vcpkg/commands.civerifyversions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <vcpkg/commands.interface.h>

namespace vcpkg::Commands::CIVerifyVersions
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths);

struct CIVerifyVersionsCommand : PathsCommand
{
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) const override;
};
}
7 changes: 7 additions & 0 deletions toolsrc/include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/view.h>

#include <vcpkg/versiondeserializers.h>
#include <vcpkg/versiont.h>

#include <map>
#include <memory>
#include <string>
#include <system_error>
Expand Down Expand Up @@ -103,4 +105,9 @@ namespace vcpkg

std::unique_ptr<Json::IDeserializer<std::vector<Registry>>> get_registry_array_deserializer(
const fs::path& configuration_directory);

ExpectedS<std::vector<std::pair<VersionT, std::string>>> get_builtin_versions(const VcpkgPaths& paths,
StringView port_name);

ExpectedS<std::map<std::string, VersionT, std::less<>>> get_builtin_baseline(const VcpkgPaths& paths);
}
2 changes: 2 additions & 0 deletions toolsrc/include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ namespace vcpkg
fs::path git_checkout_port(Files::Filesystem& filesystem, StringView port_name, StringView git_tree) const;
ExpectedS<std::string> git_show(const std::string& treeish, const fs::path& dot_git_dir) const;

ExpectedS<std::map<std::string, std::string, std::less<>>> git_get_local_port_treeish_map() const;

Optional<const Json::Object&> get_manifest() const;
Optional<const fs::path&> get_manifest_path() const;
const Configuration& get_configuration() const;
Expand Down
Loading

0 comments on commit 2a42024

Please sign in to comment.