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

Move json data #1348

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
25 changes: 11 additions & 14 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ namespace
Json::Object serialize_baseline(const std::map<std::string, Version, std::less<>>& baseline)
{
Json::Object port_entries_obj;
for (auto&& kv_pair : baseline)
for (auto&& [key, value] : baseline)
{
Json::Object baseline_version_obj;
insert_version_to_json_object(baseline_version_obj, kv_pair.second, BASELINE);
port_entries_obj.insert(kv_pair.first, baseline_version_obj);
insert_version_to_json_object(baseline_version_obj, value, BASELINE);
port_entries_obj.insert(key, std::move(baseline_version_obj));
}

Json::Object baseline_obj;
baseline_obj.insert("default", port_entries_obj);
baseline_obj.insert("default", std::move(port_entries_obj));
return baseline_obj;
}

Expand All @@ -118,7 +118,7 @@ namespace
}

Json::Object output_object;
output_object.insert("versions", versions_array);
output_object.insert("versions", std::move(versions_array));
return output_object;
}

Expand All @@ -142,15 +142,13 @@ namespace
fs.rename(new_path, output_path, VCPKG_LINE_INFO);
}

UpdateResult update_baseline_version(const VcpkgPaths& paths,
UpdateResult update_baseline_version(const Filesystem& fs,
const std::string& port_name,
const Version& version,
const Path& baseline_path,
std::map<std::string, vcpkg::Version, std::less<>>& baseline_map,
bool print_success)
{
auto& fs = paths.get_filesystem();

auto it = baseline_map.find(port_name);
if (it != baseline_map.end())
{
Expand Down Expand Up @@ -376,11 +374,10 @@ namespace vcpkg
auto baseline_map = [&]() -> std::map<std::string, vcpkg::Version, std::less<>> {
if (!fs.exists(baseline_path, IgnoreErrors{}))
{
std::map<std::string, vcpkg::Version, std::less<>> ret;
return ret;
return std::map<std::string, vcpkg::Version, std::less<>>{};
}
auto maybe_baseline_map = vcpkg::get_builtin_baseline(paths);
return maybe_baseline_map.value_or_exit(VCPKG_LINE_INFO);
return std::move(maybe_baseline_map).value_or_exit(VCPKG_LINE_INFO);
}();

// Get tree-ish from local repository state.
Expand All @@ -393,7 +390,7 @@ namespace vcpkg
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
if (auto changes = maybe_changes.get())
{
changed_ports.insert(changes->begin(), changes->end());
changed_ports = std::move(*changes);
}
else if (verbose)
{
Expand Down Expand Up @@ -462,7 +459,7 @@ namespace vcpkg
}
const auto& git_tree = git_tree_it->second;

char prefix[] = {port_name[0], '-', '\0'};
const char prefix[] = {port_name[0], '-', '\0'};
auto port_versions_path = paths.builtin_registry_versions / prefix / Strings::concat(port_name, ".json");
auto updated_versions_file = update_version_db_file(paths,
port_name,
Expand All @@ -474,7 +471,7 @@ namespace vcpkg
add_all,
skip_version_format_check);
auto updated_baseline_file = update_baseline_version(
paths, port_name, schemed_version.version, baseline_path, baseline_map, verbose);
paths.get_filesystem(), port_name, schemed_version.version, baseline_path, baseline_map, verbose);
if (verbose && updated_versions_file == UpdateResult::NotUpdated &&
updated_baseline_file == UpdateResult::NotUpdated)
{
Expand Down
72 changes: 39 additions & 33 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,25 @@ namespace vcpkg
if (args.github_ref.has_value() && args.github_sha.has_value() && args.github_job.has_value() &&
args.github_workflow.has_value() && args.github_run_id.has_value())
{
Json::Object detector;
detector.insert("name", Json::Value::string("vcpkg"));
detector.insert("url", Json::Value::string("https://github.com/microsoft/vcpkg"));
detector.insert("version", Json::Value::string("1.0.0"));

Json::Object job;
job.insert("id", Json::Value::string(*args.github_run_id.get()));
job.insert("correlator", Json::Value::string(*args.github_workflow.get() + "-" + *args.github_job.get()));

Json::Object snapshot;
snapshot.insert("job", job);
snapshot.insert("version", Json::Value::integer(0));
snapshot.insert("sha", Json::Value::string(*args.github_sha.get()));
snapshot.insert("ref", Json::Value::string(*args.github_ref.get()));
snapshot.insert("scanned", Json::Value::string(CTime::now_string()));
snapshot.insert("detector", detector);

{
Json::Object detector;
detector.insert("name", Json::Value::string("vcpkg"));
detector.insert("url", Json::Value::string("https://github.com/microsoft/vcpkg"));
detector.insert("version", Json::Value::string("1.0.0"));

Json::Object job;
job.insert("id", Json::Value::string(*args.github_run_id.get()));
job.insert("correlator",
Json::Value::string(*args.github_workflow.get() + "-" + *args.github_job.get()));

snapshot.insert("job", std::move(job));
snapshot.insert("version", Json::Value::integer(0));
snapshot.insert("sha", Json::Value::string(*args.github_sha.get()));
snapshot.insert("ref", Json::Value::string(*args.github_ref.get()));
snapshot.insert("scanned", Json::Value::string(CTime::now_string()));
snapshot.insert("detector", std::move(detector));
}
Json::Object manifest;
manifest.insert("name", "vcpkg.json");

Expand All @@ -90,35 +92,39 @@ namespace vcpkg
auto version = scf.to_version().to_string();
auto s = action.spec.to_string();
auto pkg_url = Strings::concat("pkg:github/vcpkg/", s, "@", version);
map.insert({s, pkg_url});
map.emplace(std::move(s), std::move(pkg_url));
}

Json::Object resolved;
for (auto&& action : action_plan.install_actions)
{
Json::Object resolved_item;
if (map.find(action.spec.to_string()) != map.end())
const auto pkg_it = map.find(action.spec.to_string());
if (pkg_it == map.end())
{
continue;
}

const auto& pkg_url = pkg_it->second;
resolved_item.insert("package_url", pkg_url);
resolved_item.insert("relationship", Json::Value::string("direct"));
Json::Array deps_list;

for (auto&& dep : action.package_dependencies)
{
auto pkg_url = map.at(action.spec.to_string());
resolved_item.insert("package_url", pkg_url);
resolved_item.insert("relationship", Json::Value::string("direct"));
Json::Array deps_list;
for (auto&& dep : action.package_dependencies)
const auto dep_pkg_it = map.find(dep.to_string());
if (dep_pkg_it != map.end())
{
if (map.find(dep.to_string()) != map.end())
{
auto dep_pkg_url = map.at(dep.to_string());
deps_list.push_back(dep_pkg_url);
}
deps_list.push_back(dep_pkg_it->second);
}
resolved_item.insert("dependencies", deps_list);
resolved.insert(pkg_url, resolved_item);
}
resolved_item.insert("dependencies", std::move(deps_list));
resolved.insert(pkg_url, std::move(resolved_item));
}
manifest.insert("resolved", resolved);
manifest.insert("resolved", std::move(resolved));
Json::Object manifests;
manifests.insert("vcpkg.json", manifest);
snapshot.insert("manifests", manifests);
manifests.insert("vcpkg.json", std::move(manifest));
snapshot.insert("manifests", std::move(manifests));

Debug::print(Json::stringify(snapshot));
return snapshot;
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ namespace vcpkg
buildtime_times.push_back(Json::Value::number(buildtime.second));
}

properties.insert("buildnames_1", buildtime_names);
properties.insert("buildtimes", buildtime_times);
properties.insert("buildnames_1", std::move(buildtime_names));
properties.insert("buildtimes", std::move(buildtime_times));
}

Json::Object& measurements = base_data.insert("measurements", Json::Object());
Expand Down
Loading