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
24 changes: 11 additions & 13 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,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, JsonIdBaseline);
port_entries_obj.insert(kv_pair.first, baseline_version_obj);
insert_version_to_json_object(baseline_version_obj, value, JsonIdBaseline);
port_entries_obj.insert(key, std::move(baseline_version_obj));
}

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

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

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

Expand All @@ -128,15 +128,13 @@ namespace
write_json_file(fs, serialize_versions(versions), output_path);
}

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 @@ -452,12 +450,11 @@ 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 @@ -470,7 +467,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 @@ -546,6 +543,7 @@ namespace vcpkg
}

const auto& git_tree = git_tree_it->second;

auto updated_versions_file = update_version_db_file(paths,
port_name,
schemed_version,
Expand All @@ -555,7 +553,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
103 changes: 56 additions & 47 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,74 +55,83 @@ namespace vcpkg
const auto github_job = args.github_job.get();
const auto github_workflow = args.github_workflow.get();
const auto github_run_id = args.github_run_id.get();
if (github_ref && github_sha && github_job && github_workflow && github_run_id)
if (!github_ref || !github_sha || !github_job || !github_workflow || !github_run_id)
{
Json::Object detector;
detector.insert(JsonIdName, Json::Value::string("vcpkg"));
detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg"));
detector.insert(JsonIdVersion, Json::Value::string("1.0.0"));
return nullopt;
}

Json::Object snapshot;
{
Json::Object job;
job.insert(JsonIdId, Json::Value::string(*github_run_id));
job.insert(JsonIdCorrelator, Json::Value::string(fmt::format("{}-{}", *github_workflow, *github_run_id)));
snapshot.insert(JsonIdJob, std::move(job));
} // destroy job

Json::Object snapshot;
snapshot.insert(JsonIdJob, job);
snapshot.insert(JsonIdVersion, Json::Value::integer(0));
snapshot.insert(JsonIdSha, Json::Value::string(*github_sha));
snapshot.insert(JsonIdRef, Json::Value::string(*github_ref));
snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string()));
snapshot.insert(JsonIdDetector, detector);
snapshot.insert(JsonIdVersion, Json::Value::integer(0));
snapshot.insert(JsonIdSha, Json::Value::string(*github_sha));
snapshot.insert(JsonIdRef, Json::Value::string(*github_ref));
snapshot.insert(JsonIdScanned, Json::Value::string(CTime::now_string()));

Json::Object manifest;
manifest.insert(JsonIdName, FileVcpkgDotJson);
{
Json::Object detector;
detector.insert(JsonIdName, Json::Value::string("vcpkg"));
detector.insert(JsonIdUrl, Json::Value::string("https://github.com/microsoft/vcpkg"));
detector.insert(JsonIdVersion, Json::Value::string("1.0.0"));
snapshot.insert(JsonIdDetector, std::move(detector));
} // destroy detector

std::unordered_map<std::string, std::string> map;
for (auto&& action : action_plan.install_actions)
std::unordered_map<std::string, std::string> map;
for (auto&& action : action_plan.install_actions)
{
const auto scfl = action.source_control_file_and_location.get();
if (!scfl)
{
const auto scfl = action.source_control_file_and_location.get();
if (!scfl)
{
return nullopt;
}
auto spec = action.spec.to_string();
map.insert(
{spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version())});
return nullopt;
}
auto spec = action.spec.to_string();
map.emplace(spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version()));
}

Json::Object manifest;
manifest.insert(JsonIdName, FileVcpkgDotJson);

{
Json::Object resolved;
for (auto&& action : action_plan.install_actions)
{
Json::Object resolved_item;
auto spec = action.spec.to_string();
const auto found = map.find(spec);
if (found != map.end())
const auto pkg_it = map.find(action.spec.to_string());
if (pkg_it == map.end())
{
const auto& pkg_url = found->second;
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect));
Json::Array deps_list;
for (auto&& dep : action.package_dependencies)
continue;
}

const auto& pkg_url = pkg_it->second;
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
resolved_item.insert(JsonIdRelationship, 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())
{
const auto found_dep = map.find(dep.to_string());
if (found_dep != map.end())
{
deps_list.push_back(found_dep->second);
}
deps_list.push_back(dep_pkg_it->second);
}
resolved_item.insert(JsonIdDependencies, deps_list);
resolved.insert(pkg_url, resolved_item);
}
resolved_item.insert(JsonIdDependencies, std::move(deps_list));
resolved.insert(pkg_url, std::move(resolved_item));
}
manifest.insert(JsonIdResolved, std::move(resolved));
} // destroy resolved

manifest.insert(JsonIdResolved, resolved);
Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, manifest);
snapshot.insert(JsonIdManifests, manifests);
Debug::print(Json::stringify(snapshot));
return snapshot;
}
return nullopt;
Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, std::move(manifest));
snapshot.insert(JsonIdManifests, std::move(manifests));

Debug::print(Json::stringify(snapshot));
return snapshot;
}

std::set<PackageSpec> adjust_action_plan_to_status_db(ActionPlan& action_plan, const StatusParagraphs& status_db)
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,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