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

Make SPDX resource heuristics an object rather than a value. #1530

Merged
merged 1 commit into from
Nov 1, 2024
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
2 changes: 1 addition & 1 deletion include/vcpkg/commands.build.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ namespace vcpkg
Optional<Path> abi_tag_file;
std::vector<Path> relative_port_files;
std::vector<std::string> relative_port_hashes;
std::vector<Json::Value> heuristic_resources;
std::vector<Json::Object> heuristic_resources;
};

void compute_all_abis(const VcpkgPaths& paths,
Expand Down
4 changes: 2 additions & 2 deletions include/vcpkg/spdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace vcpkg
View<std::string> hashes,
std::string created_time,
std::string document_namespace,
std::vector<Json::Value>&& resource_docs);
std::vector<Json::Object>&& resource_docs);

Json::Value run_resource_heuristics(StringView contents, StringView portRawVersion);
Json::Object run_resource_heuristics(StringView contents, StringView portRawVersion);
}
4 changes: 2 additions & 2 deletions src/vcpkg-test/spdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,15 +316,15 @@ TEST_CASE ("spdx concat resources", "[spdx]")
})json",
"test")
.value(VCPKG_LINE_INFO)
.value;
.value.object(VCPKG_LINE_INFO);
auto doc2 = Json::parse(R"json(
{
"packages": [ "p1", "p2", "p3" ],
"files": [ "f4", "f5" ]
})json",
"test")
.value(VCPKG_LINE_INFO)
.value;
.value.object(VCPKG_LINE_INFO);

const auto sbom = create_spdx_sbom(ipa, {}, {}, "now+1", "ns", {std::move(doc1), std::move(doc2)});

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ namespace vcpkg

static void write_sbom(const VcpkgPaths& paths,
const InstallPlanAction& action,
std::vector<Json::Value> heuristic_resources)
std::vector<Json::Object> heuristic_resources)
{
auto& fs = paths.get_filesystem();
const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);
Expand Down
14 changes: 6 additions & 8 deletions src/vcpkg/spdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static Json::Object make_resource(
return obj;
}

Json::Value vcpkg::run_resource_heuristics(StringView contents, StringView version_text)
Json::Object vcpkg::run_resource_heuristics(StringView contents, StringView version_text)
{
// These are a sequence of heuristics to enable proof-of-concept extraction of remote resources for SPDX SBOM
// inclusion
Expand Down Expand Up @@ -130,15 +130,15 @@ Json::Value vcpkg::run_resource_heuristics(StringView contents, StringView versi
packages.push_back(
make_resource(fmt::format("SPDXRef-resource-{}", ++n), filename, std::move(url), sha, filename));
}
return Json::Value::object(std::move(ret));
return ret;
}

std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action,
View<Path> relative_paths,
View<std::string> hashes,
std::string created_time,
std::string document_namespace,
std::vector<Json::Value>&& resource_docs)
std::vector<Json::Object>&& resource_docs)
{
Checks::check_exit(VCPKG_LINE_INFO, relative_paths.size() == hashes.size());

Expand Down Expand Up @@ -249,11 +249,9 @@ std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action,

for (auto&& rdoc : resource_docs)
{
if (!rdoc.is_object()) continue;
auto robj = std::move(rdoc).object(VCPKG_LINE_INFO);
append_move_if_exists_and_array(rels, robj, JsonIdRelationships);
append_move_if_exists_and_array(files, robj, JsonIdFiles);
append_move_if_exists_and_array(packages, robj, JsonIdPackages);
append_move_if_exists_and_array(rels, rdoc, JsonIdRelationships);
append_move_if_exists_and_array(files, rdoc, JsonIdFiles);
append_move_if_exists_and_array(packages, rdoc, JsonIdPackages);
}

return Json::stringify(doc);
Expand Down
Loading