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 11 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 11 additions & 14 deletions src/vcpkg/commands.add-version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,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 @@ -108,7 +108,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 @@ -132,15 +132,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 @@ -365,11 +363,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 @@ -382,7 +379,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 @@ -451,7 +448,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 @@ -463,7 +460,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
106 changes: 59 additions & 47 deletions src/vcpkg/commands.set-installed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,75 +49,87 @@ namespace vcpkg
Optional<Json::Object> create_dependency_graph_snapshot(const VcpkgCmdArguments& args,
const ActionPlan& action_plan)
{
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())
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(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(*args.github_run_id.get()));
job.insert(JsonIdCorrelator,
Json::Value::string(*args.github_workflow.get() + "-" + *args.github_job.get()));
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(*args.github_sha.get()));
snapshot.insert(JsonIdRef, Json::Value::string(*args.github_ref.get()));
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(*args.github_sha.get()));
snapshot.insert(JsonIdRef, Json::Value::string(*args.github_ref.get()));
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)
{
if (!action.source_control_file_and_location.has_value())
{
if (!action.source_control_file_and_location.has_value())
{
return nullopt;
}
const auto& scf = *action.source_control_file_and_location.get();
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});
return nullopt;
}
const auto& scf = *action.source_control_file_and_location.get();
auto version = scf.to_version().to_string();
auto s = action.spec.to_string();
auto pkg_url = Strings::concat("pkg:github/vcpkg/", s, "@", version);
map.emplace(std::move(s), std::move(pkg_url));
}

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

{
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())
{
auto pkg_url = map.at(action.spec.to_string());
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())
{
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(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);
Json::Object manifests;
manifests.insert(JsonIdVcpkgDotJson, manifest);
snapshot.insert(JsonIdManifests, manifests);
manifest.insert(JsonIdResolved, std::move(resolved));
} // destroy resolved

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 @@ -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