From 0e6a771b2fc403087f8cb396456dac7ef06d8ee3 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Thu, 24 Oct 2024 13:04:54 -0700 Subject: [PATCH] Make SPDX resource hueristics an object rather than a value. Extracted from https://github.com/microsoft/vcpkg-tool/pull/1514 We were paying to package the object up into a value, then unpackage it. --- include/vcpkg/commands.build.h | 2 +- include/vcpkg/spdx.h | 4 ++-- src/vcpkg-test/spdx.cpp | 4 ++-- src/vcpkg/commands.build.cpp | 2 +- src/vcpkg/spdx.cpp | 14 ++++++-------- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/vcpkg/commands.build.h b/include/vcpkg/commands.build.h index 747c130141..7a9a47e355 100644 --- a/include/vcpkg/commands.build.h +++ b/include/vcpkg/commands.build.h @@ -246,7 +246,7 @@ namespace vcpkg Optional abi_tag_file; std::vector relative_port_files; std::vector relative_port_hashes; - std::vector heuristic_resources; + std::vector heuristic_resources; }; void compute_all_abis(const VcpkgPaths& paths, diff --git a/include/vcpkg/spdx.h b/include/vcpkg/spdx.h index 902b731872..09d9bf5749 100644 --- a/include/vcpkg/spdx.h +++ b/include/vcpkg/spdx.h @@ -27,7 +27,7 @@ namespace vcpkg View hashes, std::string created_time, std::string document_namespace, - std::vector&& resource_docs); + std::vector&& resource_docs); - Json::Value run_resource_heuristics(StringView contents, StringView portRawVersion); + Json::Object run_resource_heuristics(StringView contents, StringView portRawVersion); } diff --git a/src/vcpkg-test/spdx.cpp b/src/vcpkg-test/spdx.cpp index 743e0207f2..efe68a3c71 100644 --- a/src/vcpkg-test/spdx.cpp +++ b/src/vcpkg-test/spdx.cpp @@ -316,7 +316,7 @@ 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" ], @@ -324,7 +324,7 @@ TEST_CASE ("spdx concat resources", "[spdx]") })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)}); diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp index d1a8a8d494..26d949ea58 100644 --- a/src/vcpkg/commands.build.cpp +++ b/src/vcpkg/commands.build.cpp @@ -922,7 +922,7 @@ namespace vcpkg static void write_sbom(const VcpkgPaths& paths, const InstallPlanAction& action, - std::vector heuristic_resources) + std::vector heuristic_resources) { auto& fs = paths.get_filesystem(); const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO); diff --git a/src/vcpkg/spdx.cpp b/src/vcpkg/spdx.cpp index 2e28a3b404..d5c77cee5e 100644 --- a/src/vcpkg/spdx.cpp +++ b/src/vcpkg/spdx.cpp @@ -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 @@ -130,7 +130,7 @@ 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, @@ -138,7 +138,7 @@ std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action, View hashes, std::string created_time, std::string document_namespace, - std::vector&& resource_docs) + std::vector&& resource_docs) { Checks::check_exit(VCPKG_LINE_INFO, relative_paths.size() == hashes.size()); @@ -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);