Skip to content

Commit

Permalink
[vcpkg] Change version field in baseline.json (microsoft#15633)
Browse files Browse the repository at this point in the history
* [vcpkg] Change version field in `baseline.json`

* Change name from `version-tag` to `baseline`

* [vcpkg] x-history serializes version scheme

* Update e2e tests

* Update baseline e2e test
  • Loading branch information
vicroms authored Jan 14, 2021
1 parent 3f3d9a6 commit fb21b70
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 97 deletions.
2 changes: 1 addition & 1 deletion scripts/e2e_ports/port_versions/baseline.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"vcpkg-internal-e2e-test-port": { "version-string": "1.0.0" }
"vcpkg-internal-e2e-test-port": { "baseline": "1.0.0" }
}
35 changes: 23 additions & 12 deletions scripts/generateBaseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@
VERSIONS_DB_DIRECTORY = os.path.join(SCRIPT_DIRECTORY, '../port_versions')


def get_version_tag(version):
if 'version' in version:
return version['version']
elif 'version-date' in version:
return version['version-date']
elif 'version-semver' in version:
return version['version-semver']
elif 'version-string' in version:
return version['version-string']
sys.exit(1)


def get_version_port_version(version):
if 'port-version' in version:
return version['port-version']
return 0


def generate_baseline():
start_time = time.time()

Expand All @@ -35,18 +53,11 @@ def generate_baseline():
try:
versions_object = json.load(db_file)
if versions_object['versions']:
last_version = versions_object['versions'][0]
version_obj = {}
if 'version' in last_version:
version_obj['version'] = last_version['version']
elif 'version-date' in last_version:
version_obj['version-date'] = last_version['version-date']
elif 'version-semver' in last_version:
version_obj['version-semver'] - last_version['version-semver']
else:
version_obj['version-string'] = last_version['version-string']
version_obj['port-version'] = last_version['port-version']
baseline_entries[port_name] = version_obj
last_version = versions_object['versions'][0]
baseline_entries[port_name] = {
'baseline': get_version_tag(last_version),
'port-version': get_version_port_version(last_version)
}
except json.JSONDecodeError as e:
print(f'Error: Decoding {port_file_path}\n{e}\n')
baseline_object = {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "default-baseline-test",
"version-string": "0",
"$x-default-baseline": "cbd5a68012471f820b7cf28d618199b4a4d89c58",
"$x-default-baseline": "16002d9c2318dec4c69e02d9af8c0e11dca0d4c6",
"dependencies": [
"zlib"
]
Expand Down
8 changes: 4 additions & 4 deletions scripts/testing/version-files/port_versions/baseline.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"default": {
"cat": {
"version-string": "1.0",
"baseline": "1.0",
"port-version": 0
},
"dog": {
"version-string": "2001-01-01",
"baseline": "2001-01-01",
"port-version": 0
},
"duck": {
"version-string": "mallard",
"baseline": "mallard",
"port-version": 0
},
"mouse": {
"version-string": "1.0.0",
"baseline": "1.0.0",
"port-version": 0
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"default": {
"cat": {
"version-string": "1.0",
"baseline": "1.0",
"port-version": 0
},
"dog": {
"version-string": "2001-01-01",
"baseline": "2001-01-01",
"port-version": 0
},
"duck": {
"version-string": "mallard",
"baseline": "mallard",
"port-version": 0
},
"fish": {
"version-string": "1.0.0",
"baseline": "1.0.0",
"port-version": 0
}
}
Expand Down
4 changes: 2 additions & 2 deletions toolsrc/include/vcpkg/registries.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ 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::vector<std::pair<SchemedVersion, 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);
}
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/sourceparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <vcpkg/packagespec.h>
#include <vcpkg/paragraphparser.h>
#include <vcpkg/platform-expression.h>
#include <vcpkg/versiondeserializers.h>
#include <vcpkg/versions.h>

namespace vcpkg
Expand Down Expand Up @@ -107,6 +108,10 @@ namespace vcpkg
const FeatureFlagSettings& flags) const;

VersionT to_versiont() const { return core_paragraph->to_versiont(); }
SchemedVersion to_schemed_version() const
{
return SchemedVersion{core_paragraph->version_scheme, core_paragraph->to_versiont()};
}

friend bool operator==(const SourceControlFile& lhs, const SourceControlFile& rhs);
friend bool operator!=(const SourceControlFile& lhs, const SourceControlFile& rhs) { return !(lhs == rhs); }
Expand Down
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/versiondeserializers.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace vcpkg
{
Json::IDeserializer<VersionT>& get_versiont_deserializer_instance();
Json::IDeserializer<VersionT>& get_versiontag_deserializer_instance();
std::unique_ptr<Json::IDeserializer<std::string>> make_version_deserializer(StringLiteral type_name);

struct SchemedVersion
Expand Down
65 changes: 48 additions & 17 deletions toolsrc/src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,51 @@ using namespace vcpkg;

namespace
{
using VersionGitTree = std::pair<VersionT, std::string>;
constexpr StringLiteral BASELINE = "baseline";
constexpr StringLiteral VERSION_RELAXED = "version";
constexpr StringLiteral VERSION_SEMVER = "version-semver";
constexpr StringLiteral VERSION_DATE = "version-date";
constexpr StringLiteral VERSION_STRING = "version-string";

void insert_version_to_json_object(Json::Object& obj, const VersionT& version)
using VersionGitTree = std::pair<SchemedVersion, std::string>;

void insert_version_to_json_object(Json::Object& obj, const VersionT& version, StringLiteral version_field)
{
obj.insert("version-string", Json::Value::string(version.text()));
obj.insert(version_field, Json::Value::string(version.text()));
obj.insert("port-version", Json::Value::integer(version.port_version()));
}

void insert_schemed_version_to_json_object(Json::Object& obj, const SchemedVersion& version)
{
if (version.scheme == Versions::Scheme::Relaxed)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_RELAXED);
}

if (version.scheme == Versions::Scheme::Semver)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_SEMVER);
}

if (version.scheme == Versions::Scheme::Date)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_DATE);
}

if (version.scheme == Versions::Scheme::String)
{
return insert_version_to_json_object(obj, version.versiont, VERSION_STRING);
}
Checks::unreachable(VCPKG_LINE_INFO);
}

static Json::Object serialize_baseline(const std::map<std::string, VersionT, std::less<>>& baseline)
{
Json::Object port_entries_obj;
for (auto&& kv_pair : baseline)
{
Json::Object baseline_version_obj;
insert_version_to_json_object(baseline_version_obj, kv_pair.second);
insert_version_to_json_object(baseline_version_obj, kv_pair.second, BASELINE);
port_entries_obj.insert(kv_pair.first, baseline_version_obj);
}

Expand All @@ -46,7 +76,7 @@ namespace
{
Json::Object version_obj;
version_obj.insert("git-tree", Json::Value::string(version.second));
insert_version_to_json_object(version_obj, version.first);
insert_schemed_version_to_json_object(version_obj, version.first);
versions_array.push_back(std::move(version_obj));
}

Expand Down Expand Up @@ -169,7 +199,7 @@ namespace

static void update_version_db_file(const VcpkgPaths& paths,
const std::string& port_name,
const VersionT& version,
const SchemedVersion& version,
const std::string& git_tree,
const fs::path& version_db_file_path,
bool overwrite_version,
Expand All @@ -185,7 +215,7 @@ namespace
{
System::printf(System::Color::success,
"Added version `%s` to `%s` (new file).\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand All @@ -200,13 +230,13 @@ namespace
versions->begin(), versions_end, [&](auto&& entry) -> bool { return entry.second == git_tree; });
if (found_same_sha != versions_end)
{
if (found_same_sha->first == version)
if (found_same_sha->first.versiont == version.versiont)
{
if (print_success)
{
System::printf(System::Color::success,
"Version `%s` is already in `%s`\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand All @@ -216,15 +246,16 @@ namespace
"-- SHA: %s\n"
"-- Did you remember to commit your changes?\n"
"***No files were updated.***\n",
found_same_sha->first.to_string(),
found_same_sha->first.versiont,
fs::u8string(version_db_file_path),
git_tree);
if (keep_going) return;
Checks::exit_fail(VCPKG_LINE_INFO);
}

auto it = std::find_if(
versions->begin(), versions_end, [&](auto&& entry) -> bool { return entry.first == version; });
auto it = std::find_if(versions->begin(), versions_end, [&](auto&& entry) -> bool {
return entry.first.versiont == version.versiont;
});

if (it != versions_end)
{
Expand All @@ -239,7 +270,7 @@ namespace
"-- Pass `--overwrite-version` to bypass this check.\n"
"***No files were updated.***\n",
port_name,
version.to_string(),
version.versiont,
it->second,
git_tree);
if (keep_going) return;
Expand All @@ -259,7 +290,7 @@ namespace
{
System::printf(System::Color::success,
"Added version `%s` to `%s`.\n",
version.to_string(),
version.versiont,
fs::u8string(version_db_file_path));
}
return;
Expand Down Expand Up @@ -352,7 +383,7 @@ namespace vcpkg::Commands::AddVersion
}

const auto& scf = maybe_scf.value_or_exit(VCPKG_LINE_INFO);
const auto& versiont = scf->to_versiont();
const auto& schemed_version = scf->to_schemed_version();

auto git_tree_it = git_tree_map.find(port_name);
if (git_tree_it == git_tree_map.end())
Expand All @@ -370,8 +401,8 @@ namespace vcpkg::Commands::AddVersion
auto port_versions_path =
paths.builtin_port_versions / Strings::concat(port_name[0], '-') / Strings::concat(port_name, ".json");
update_version_db_file(
paths, port_name, versiont, git_tree, port_versions_path, overwrite_version, verbose, add_all);
update_baseline_version(paths, port_name, versiont, baseline_path, verbose);
paths, port_name, schemed_version, git_tree, port_versions_path, overwrite_version, verbose, add_all);
update_baseline_version(paths, port_name, schemed_version.versiont, baseline_path, verbose);
}
Checks::exit_success(VCPKG_LINE_INFO);
}
Expand Down
Loading

0 comments on commit fb21b70

Please sign in to comment.