Skip to content

Commit 9de7943

Browse files
authored
Make SPDX resource hueristics an object rather than a value. (#1530)
Extracted from #1514 We were paying to package the object up into a value, then unpackage it.
1 parent 5a30615 commit 9de7943

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

include/vcpkg/commands.build.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace vcpkg
246246
Optional<Path> abi_tag_file;
247247
std::vector<Path> relative_port_files;
248248
std::vector<std::string> relative_port_hashes;
249-
std::vector<Json::Value> heuristic_resources;
249+
std::vector<Json::Object> heuristic_resources;
250250
};
251251

252252
void compute_all_abis(const VcpkgPaths& paths,

include/vcpkg/spdx.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace vcpkg
2727
View<std::string> hashes,
2828
std::string created_time,
2929
std::string document_namespace,
30-
std::vector<Json::Value>&& resource_docs);
30+
std::vector<Json::Object>&& resource_docs);
3131

32-
Json::Value run_resource_heuristics(StringView contents, StringView portRawVersion);
32+
Json::Object run_resource_heuristics(StringView contents, StringView portRawVersion);
3333
}

src/vcpkg-test/spdx.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ TEST_CASE ("spdx concat resources", "[spdx]")
316316
})json",
317317
"test")
318318
.value(VCPKG_LINE_INFO)
319-
.value;
319+
.value.object(VCPKG_LINE_INFO);
320320
auto doc2 = Json::parse(R"json(
321321
{
322322
"packages": [ "p1", "p2", "p3" ],
323323
"files": [ "f4", "f5" ]
324324
})json",
325325
"test")
326326
.value(VCPKG_LINE_INFO)
327-
.value;
327+
.value.object(VCPKG_LINE_INFO);
328328

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

src/vcpkg/commands.build.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ namespace vcpkg
922922

923923
static void write_sbom(const VcpkgPaths& paths,
924924
const InstallPlanAction& action,
925-
std::vector<Json::Value> heuristic_resources)
925+
std::vector<Json::Object> heuristic_resources)
926926
{
927927
auto& fs = paths.get_filesystem();
928928
const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);

src/vcpkg/spdx.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static Json::Object make_resource(
8282
return obj;
8383
}
8484

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

136136
std::string vcpkg::create_spdx_sbom(const InstallPlanAction& action,
137137
View<Path> relative_paths,
138138
View<std::string> hashes,
139139
std::string created_time,
140140
std::string document_namespace,
141-
std::vector<Json::Value>&& resource_docs)
141+
std::vector<Json::Object>&& resource_docs)
142142
{
143143
Checks::check_exit(VCPKG_LINE_INFO, relative_paths.size() == hashes.size());
144144

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

250250
for (auto&& rdoc : resource_docs)
251251
{
252-
if (!rdoc.is_object()) continue;
253-
auto robj = std::move(rdoc).object(VCPKG_LINE_INFO);
254-
append_move_if_exists_and_array(rels, robj, JsonIdRelationships);
255-
append_move_if_exists_and_array(files, robj, JsonIdFiles);
256-
append_move_if_exists_and_array(packages, robj, JsonIdPackages);
252+
append_move_if_exists_and_array(rels, rdoc, JsonIdRelationships);
253+
append_move_if_exists_and_array(files, rdoc, JsonIdFiles);
254+
append_move_if_exists_and_array(packages, rdoc, JsonIdPackages);
257255
}
258256

259257
return Json::stringify(doc);

0 commit comments

Comments
 (0)