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

Merged
merged 18 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 13 additions & 19 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ namespace
{
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);
port_entries_obj.insert(kv_pair.first, 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,27 +450,20 @@ 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 vcpkg::get_builtin_baseline(paths).value_or_exit(VCPKG_LINE_INFO);
}();

// Get tree-ish from local repository state.
auto maybe_git_tree_map = paths.git_get_local_port_treeish_map();
auto& git_tree_map = maybe_git_tree_map.value_or_exit(VCPKG_LINE_INFO);

// Find ports with uncommitted changes
std::set<std::string> changed_ports;
auto git_config = paths.git_builtin_config();
auto maybe_changes = git_ports_with_uncommitted_changes(git_config);
if (auto changes = maybe_changes.get())
{
changed_ports.insert(changes->begin(), changes->end());
}
else if (verbose)
if (!maybe_changes.has_value() && verbose)
{
msg::println_warning(msgAddVersionDetectLocalChangesError);
}
Expand Down Expand Up @@ -524,9 +515,12 @@ namespace vcpkg
}

// find local uncommitted changes on port
if (Util::Sets::contains(changed_ports, port_name))
if (auto changed_ports = maybe_changes.get())
{
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
if (Util::Sets::contains(*changed_ports, port_name))
{
msg::println_warning(msgAddVersionUncommittedChanges, msg::package_name = port_name);
}
}

auto schemed_version = scfl->source_control_file->to_schemed_version();
Expand Down Expand Up @@ -555,7 +549,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
70 changes: 39 additions & 31 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,27 @@ namespace vcpkg
const auto github_run_id = args.github_run_id.get();
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"));

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)));

Json::Object snapshot;
snapshot.insert(JsonIdJob, job);
{
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

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);

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)
Expand All @@ -86,42 +88,48 @@ namespace vcpkg
return nullopt;
}
auto spec = action.spec.to_string();
map.insert(
{spec, fmt::format("pkg:github/vcpkg/{}@{}", spec, scfl->source_control_file->to_version())});
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)
{
const auto found = map.find(action.spec.to_string());
if (found == map.end())
{
continue;
}

const auto& pkg_url = found->second;
Json::Object resolved_item;
auto spec = action.spec.to_string();
const auto found = map.find(spec);
if (found != map.end())
resolved_item.insert(JsonIdPackageUnderscoreUrl, pkg_url);
resolved_item.insert(JsonIdRelationship, Json::Value::string(JsonIdDirect));

Json::Array deps_list;
for (auto&& dep : action.package_dependencies)
{
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)
const auto found_dep = map.find(dep.to_string());
if (found_dep != 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(found_dep->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, resolved);
manifest.insert(JsonIdResolved, std::move(resolved));
Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, manifest);
snapshot.insert(JsonIdManifests, manifests);
Debug::print(Json::stringify(snapshot));
return snapshot;
}

return nullopt;
}

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