Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[git registry] Add "reference" key #155

Merged
merged 36 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4465f76
fetch from baseline
Aug 12, 2021
82f3465
add reference field
Aug 12, 2021
dd498b7
disable debugging
Aug 12, 2021
be9fc8b
remove unused variable
Aug 12, 2021
e8dc3b1
fix build
Aug 12, 2021
f0edb89
fix issue with getting reference
Aug 12, 2021
479a32b
add test
Aug 12, 2021
c383e4e
fix extracting repo/reference in ensure_up_to_date func
Aug 12, 2021
9fa97dc
Nicole's CR
strega-nil-ms Oct 1, 2021
2b33d51
Update src/vcpkg/registries.cpp
strega-nil-ms Oct 1, 2021
5009381
fix tests
strega-nil Oct 1, 2021
f123501
Merge remote-tracking branch 'upstream/main' into support-branch-base…
Oct 7, 2021
35cb95b
store reference and commit separately
Oct 7, 2021
9fd845b
fix gcc 6 build
Oct 7, 2021
2e7241c
add reference to valid fields of registries deserializer
Oct 7, 2021
9b61aab
fix format
Oct 7, 2021
6f41628
add tests
Oct 7, 2021
a5c61d2
add debug output in tests
Oct 7, 2021
68a1ac8
more dbg outputs
Oct 7, 2021
fb2e3a0
disable branch creation in tests
Oct 7, 2021
647a48d
switch to prev branch
Oct 7, 2021
e59d550
cleanup installRoot
Oct 7, 2021
35189fc
debug output
Oct 7, 2021
34e685d
fix test
Oct 7, 2021
1ab1e84
remove debug output
Oct 7, 2021
f1d42d7
Apply suggestions from code review
srgbtl Oct 7, 2021
26e8403
support repo duplication
Oct 29, 2021
1da3385
Merge remote-tracking branch 'origin/main' into support-branch-baseline
Oct 29, 2021
46c8786
Merge
Oct 29, 2021
d95b989
cleanup
Oct 29, 2021
ea06b3d
clang format
Oct 29, 2021
f6566ca
debug output
srgbtl Oct 30, 2021
ff5f87a
syntax fix
srgbtl Oct 30, 2021
d8e69ec
sort repo ref keys in json
Oct 30, 2021
78887f5
fix json comparison
Oct 30, 2021
fc328ae
Update src/vcpkg/registries.cpp
ras0219-msft Nov 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "vcpkg-internal-e2e-test-port2",
"version-string": "1.0.0"
}
167 changes: 137 additions & 30 deletions azure-pipelines/end-to-end-tests-dir/registries.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ try
'-c', 'core.autocrlf=false'
)

$gitMainBranch = 'main'
$gitSecondaryBranch = 'secondary'

$CurrentTest = 'git init .'
git @gitConfigOptions init .
Throw-IfFailed

# Create git registry with vcpkg-internal-e2e-test-port in the main branch
$CurrentTest = 'git switch --orphan'
git @gitConfigOptions switch --orphan $gitMainBranch
Throw-IfFailed

Copy-Item -Recurse -LiteralPath "$PSScriptRoot/../e2e_ports/vcpkg-internal-e2e-test-port" -Destination .
New-Item -Path './vcpkg-internal-e2e-test-port/foobar' -Value 'this is just to get a distinct git tree'

$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
Throw-IfFailed
$CurrentTest = 'git commit'
git @gitConfigOptions commit -m 'initial commit'
$CurrentTest = 'git commit -m'
git @gitConfigOptions commit -m 'add vcpkg-internal-e2e-test-port'
Throw-IfFailed

$vcpkgInternalE2eTestPortGitTree = git rev-parse 'HEAD:vcpkg-internal-e2e-test-port'
Expand Down Expand Up @@ -103,12 +112,65 @@ try
$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
Throw-IfFailed
$CurrentTest = 'git commit'
$CurrentTest = 'git commit --amend --no-edit'
git @gitConfigOptions commit --amend --no-edit
Throw-IfFailed

$gitMainBaselineCommit = git rev-parse HEAD
$gitMainRefVersionsObject = git rev-parse HEAD:versions

# Create git registry with vcpkg-internal-e2e-test-port2 in the secondary branch

$CurrentTest = 'git switch --orphan'
git @gitConfigOptions switch --orphan $gitSecondaryBranch
Throw-IfFailed

Copy-Item -Recurse -LiteralPath "$PSScriptRoot/../e2e_ports/vcpkg-internal-e2e-test-port2" -Destination .
New-Item -Path './vcpkg-internal-e2e-test-port2/foobaz' -Value 'this is just to get a distinct git tree'

$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
Throw-IfFailed
$CurrentTest = 'git commit -m'
git @gitConfigOptions commit -m 'add vcpkg-internal-e2e-test-port2'
Throw-IfFailed

$vcpkgInternalE2eTestPort2GitTree = git rev-parse 'HEAD:vcpkg-internal-e2e-test-port2'
$vcpkgInternalE2eTestPortVersionsJson = @{
"versions" = @(
@{
"version-string" = "1.0.0";
"git-tree" = $vcpkgInternalE2eTestPort2GitTree
}
)
}
$vcpkgBaseline = @{
"default" = @{
"vcpkg-internal-e2e-test-port2" = @{
"baseline" = "1.0.0"
}
}
}

New-Item -Path './versions' -ItemType Directory
New-Item -Path './versions/v-' -ItemType Directory

New-Item -Path './versions/baseline.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgBaseline)
New-Item -Path './versions/v-/vcpkg-internal-e2e-test-port2.json' -Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgInternalE2eTestPortVersionsJson)

$CurrentTest = 'git add -A'
git @gitConfigOptions add -A
Throw-IfFailed
$CurrentTest = 'git commit --amend --no-edit'
git @gitConfigOptions commit --amend --no-edit
Throw-IfFailed

$gitBaselineCommit = git rev-parse HEAD
$gitRefVersionsObject = git rev-parse HEAD:versions
$gitSecondaryBaselineCommit = git rev-parse HEAD
$gitSecondaryRefVersionsObject = git rev-parse HEAD:versions

$CurrentTest = 'git switch'
git @gitConfigOptions switch $gitMainBranch
Throw-IfFailed
}
finally
{
Expand All @@ -117,18 +179,6 @@ finally

# actually test the registries
Write-Trace "actually test the registries"
$vcpkgJson = @{
"name" = "manifest-test";
"version-string" = "1.0.0";
"dependencies" = @(
"vcpkg-internal-e2e-test-port"
);
# Use versioning features without a builtin-baseline
"overrides" = @(@{
"name" = "unused";
"version" = "0";
})
}

# test the filesystem registry
Write-Trace "test the filesystem registry"
Expand All @@ -140,9 +190,18 @@ $manifestDir = (Get-Item $manifestDir).FullName
Push-Location $manifestDir
try
{
New-Item -Path 'vcpkg.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)

$vcpkgJson = @{
"name" = "manifest-test";
"version-string" = "1.0.0";
"dependencies" = @(
"vcpkg-internal-e2e-test-port"
);
# Use versioning features without a builtin-baseline
"overrides" = @(@{
"name" = "unused";
"version" = "0";
})
}
$vcpkgConfigurationJson = @{
"default-registry" = $null;
"registries" = @(
Expand All @@ -153,6 +212,8 @@ try
}
)
}
New-Item -Path 'vcpkg.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)
New-Item -Path 'vcpkg-configuration.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgConfigurationJson)

Expand All @@ -174,34 +235,64 @@ $manifestDir = (Get-Item $manifestDir).FullName
Push-Location $manifestDir
try
{
New-Item -Path 'vcpkg.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)
$vcpkgJson = @{
"name" = "manifest-test";
"version-string" = "1.0.0";
"dependencies" = @(
"vcpkg-internal-e2e-test-port",
"vcpkg-internal-e2e-test-port2"
);
# Use versioning features without a builtin-baseline
"overrides" = @(@{
"name" = "unused";
"version" = "0";
})
}

$vcpkgConfigurationJson = @{
"default-registry" = $null;
"registries" = @(
@{
"kind" = "git";
"repository" = $gitRegistryUpstream;
"baseline" = $gitBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port" )
"baseline" = $gitMainBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port" )
},
@{
"kind" = "git";
"repository" = $gitRegistryUpstream;
"reference" = $gitSecondaryBranch;
"baseline" = $gitSecondaryBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port2" )
}
)
}

New-Item -Path 'vcpkg.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgJson)

New-Item -Path 'vcpkg-configuration.json' -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgConfigurationJson)

Run-Vcpkg install @builtinRegistryArgs '--feature-flags=registries,manifests' --dry-run
Throw-IfFailed
Require-FileExists $env:X_VCPKG_REGISTRIES_CACHE/git-trees/$vcpkgInternalE2eTestPortGitTree
Require-FileExists $env:X_VCPKG_REGISTRIES_CACHE/git-trees/$vcpkgInternalE2eTestPort2GitTree
# This is both the selected baseline as well as the current HEAD
Require-FileExists $env:X_VCPKG_REGISTRIES_CACHE/git-trees/$gitRefVersionsObject
Require-FileExists $env:X_VCPKG_REGISTRIES_CACHE/git-trees/$gitMainRefVersionsObject
Require-FileExists $env:X_VCPKG_REGISTRIES_CACHE/git-trees/$gitSecondaryRefVersionsObject
# Dry run does not create a lockfile
Require-FileNotExists $installRoot/vcpkg/vcpkg-lock.json

Run-Vcpkg install @builtinRegistryArgs '--feature-flags=registries,manifests'
Throw-IfFailed
Require-FileEquals $installRoot/vcpkg/vcpkg-lock.json "{`n $(ConvertTo-Json $gitRegistryUpstream): `"$gitBaselineCommit`"`n}`n"

$expectedVcpkgLockJson = "{$(ConvertTo-Json $gitRegistryUpstream):{
`"HEAD`" : `"$gitMainBaselineCommit`",
`"$gitSecondaryBranch`" : `"$gitSecondaryBaselineCommit`"
}}"

Require-JsonFileEquals $installRoot/vcpkg/vcpkg-lock.json $expectedVcpkgLockJson

# Using the lock file means we can reinstall without pulling from the upstream registry
$vcpkgConfigurationJson = @{
Expand All @@ -210,18 +301,34 @@ try
@{
"kind" = "git";
"repository" = "/"; # An invalid repository
"baseline" = $gitBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port" )
"baseline" = $gitMainBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port" )
},
@{
"kind" = "git";
"repository" = "/"; # An invalid repository
"reference" = $gitSecondaryBranch;
"baseline" = $gitSecondaryBaselineCommit;
"packages" = @( "vcpkg-internal-e2e-test-port2" )
}
)
}

Set-Content -Path 'vcpkg-configuration.json' `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgConfigurationJson)

Remove-Item -Recurse -Force $installRoot -ErrorAction SilentlyContinue
Require-FileNotExists $installRoot
New-Item -Path $installRoot/vcpkg -ItemType Directory
# We pre-seed the install root with a lockfile for the invalid repository, so it isn't actually fetched from
New-Item -Path $installRoot/vcpkg/vcpkg-lock.json -ItemType File `
-Value "{`n `"/`": `"$gitBaselineCommit`"`n}`n"
$vcpkgLockJson = @{
"/" = @{
"HEAD" = $gitMainBaselineCommit;
$gitSecondaryBranch = $gitSecondaryBaselineCommit
}
}
New-Item -Path $installRoot/vcpkg/vcpkg-lock.json -ItemType File `
-Value (ConvertTo-Json -Depth 5 -InputObject $vcpkgLockJson)
Run-Vcpkg install @builtinRegistryArgs '--feature-flags=registries,manifests'
Throw-IfFailed
}
Expand Down
13 changes: 9 additions & 4 deletions azure-pipelines/end-to-end-tests-prelude.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ function Require-FileExists {
}
}

function Require-FileEquals {
function Require-JsonFileEquals {
[CmdletBinding()]
Param(
[string]$File,
[string]$Content
[string]$Json
)
Require-FileExists $File
if ((Get-Content $File -Raw) -ne $Content) {
$ExpectedJson = $Json | ConvertFrom-Json | ConvertTo-Json -Compress
$ActualJson = Get-Content $File | ConvertFrom-Json | ConvertTo-Json -Compress

if ($ActualJson -ne $ExpectedJson) {
Write-Stack
throw "'$Script:CurrentTest' file '$File' did not have the correct contents"
throw "'$Script:CurrentTest' file '$File' did not have the correct contents`n
Expected: $ExpectedJson`n
Actual: $ActualJson"
}
}

Expand Down
Empty file modified azure-pipelines/end-to-end-tests.ps1
100644 → 100755
Empty file.
14 changes: 9 additions & 5 deletions include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,28 @@ namespace vcpkg
{
struct EntryData
{
std::string value;
std::string reference;
std::string commit_id;
bool stale;
};

using LockDataType = std::multimap<std::string, EntryData, std::less<>>;
struct Entry
{
LockFile* lockfile;
std::map<std::string, EntryData, std::less<>>::iterator data;
LockDataType::iterator data;

const std::string& value() const { return data->second.value; }
const std::string& reference() const { return data->second.reference; }
const std::string& commit_id() const { return data->second.commit_id; }
bool stale() const { return data->second.stale; }
const std::string& uri() const { return data->first; }

void ensure_up_to_date(const VcpkgPaths& paths) const;
};

Entry get_or_fetch(const VcpkgPaths& paths, StringView key);
Entry get_or_fetch(const VcpkgPaths& paths, StringView repo, StringView reference);

std::map<std::string, EntryData, std::less<>> lockdata;
LockDataType lockdata;
bool modified = false;
};

Expand Down
17 changes: 17 additions & 0 deletions src/vcpkg-test/registries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,23 @@ TEST_CASE ("registry_parsing", "[registries]")
CHECK(!r.errors().empty());
}

test_json = parse_json(R"json(
{
"kind": "git",
"repository": "abc",
"baseline": "123",
"reference": "abc/def"
}
)json");
{
Json::Reader r;
auto registry_impl = r.visit(test_json, *registry_impl_des);
REQUIRE(registry_impl);
CHECK(*registry_impl.get());
INFO(Strings::join("\n", r.errors()));
CHECK(r.errors().empty());
}

test_json = parse_json(R"json(
{
"kind": "git",
Expand Down
Loading