Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas1664 committed Oct 15, 2023
1 parent 5b6f45d commit 2450ad8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 66 deletions.
1 change: 0 additions & 1 deletion include/vcpkg/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <vcpkg/statusparagraphs.h>
#include <vcpkg/vcpkgpaths.h>


#include <memory>
#include <string>
#include <vector>
Expand Down
26 changes: 6 additions & 20 deletions src/vcpkg-test/spdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,11 @@ TEST_CASE ("spdx maximum serialization", "[spdx]")
auto& abi = *(ipa.abi_info = AbiInfo{}).get();
abi.package_abi = "ABIHASH";

std::vector<AbiEntry> port_abi{
{"vcpkg.json", "vcpkg.json-hash"},
{"portfile.cmake", "portfile.cmake-hash"},
{"patches/patch1.diff", "patch1.diff-hash"}
};
std::vector<AbiEntry> port_abi{{"vcpkg.json", "vcpkg.json-hash"},
{"portfile.cmake", "portfile.cmake-hash"},
{"patches/patch1.diff", "patch1.diff-hash"}};

const auto sbom =
create_spdx_sbom(ipa,
port_abi,
"now",
"https://test-document-namespace",
{});
const auto sbom = create_spdx_sbom(ipa, port_abi, "now", "https://test-document-namespace", {});

auto expected = Json::parse(R"json(
{
Expand Down Expand Up @@ -184,16 +177,9 @@ TEST_CASE ("spdx minimum serialization", "[spdx]")
InstallPlanAction ipa(spec, scfl, "test_packages_root", RequestType::USER_REQUESTED, Test::X86_WINDOWS, {}, {}, {});
auto& abi = *(ipa.abi_info = AbiInfo{}).get();
abi.package_abi = "deadbeef";
std::vector<AbiEntry> port_abi{
{"vcpkg.json", "hash-vcpkg.json"},
{"portfile.cmake", "hash-portfile.cmake"}
};
std::vector<AbiEntry> port_abi{{"vcpkg.json", "hash-vcpkg.json"}, {"portfile.cmake", "hash-portfile.cmake"}};

const auto sbom = create_spdx_sbom(ipa,
port_abi,
"now+1",
"https://test-document-namespace-2",
{});
const auto sbom = create_spdx_sbom(ipa, port_abi, "now+1", "https://test-document-namespace-2", {});

auto expected = Json::parse(R"json(
{
Expand Down
55 changes: 32 additions & 23 deletions src/vcpkg/abi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ namespace vcpkg
std::vector<AbiEntry> port_files_abi;
};

static std::string grdk_hash(const Filesystem& fs,
const PreBuildInfo& pre_build_info)
static std::string grdk_hash(const Filesystem& fs, const PreBuildInfo& pre_build_info)
{
static const Cache<Path, Optional<std::string>> grdk_cache;
if (auto game_dk_latest = pre_build_info.gamedk_latest_path.get())
Expand Down Expand Up @@ -98,7 +97,8 @@ namespace vcpkg
auto& fs = paths.get_filesystem();

abi_entries.emplace_back("cmake", paths.get_tool_version(Tools::CMAKE, stdout_sink));
abi_entries.emplace_back("ports.cmake", Hash::get_file_hash(fs, paths.ports_cmake, Hash::Algorithm::Sha256).value_or(""));
abi_entries.emplace_back("ports.cmake",
Hash::get_file_hash(fs, paths.ports_cmake, Hash::Algorithm::Sha256).value_or(""));
abi_entries.emplace_back("post_build_checks", "2");

// This #ifdef is mirrored in tools.cpp's PowershellProvider
Expand All @@ -116,7 +116,8 @@ namespace vcpkg
std::vector<AbiEntry> helpers(files.size());

parallel_transform(files.begin(), files.size(), helpers.begin(), [&fs](auto&& file) {
return AbiEntry{file.stem().to_string(), Hash::get_file_hash(fs, file, Hash::Algorithm::Sha256).value_or("")};
return AbiEntry{file.stem().to_string(),
Hash::get_file_hash(fs, file, Hash::Algorithm::Sha256).value_or("")};
});
return helpers;
}
Expand Down Expand Up @@ -260,15 +261,16 @@ namespace vcpkg
{
if (!dependency_abis.empty())
{
auto dep_no_hash_it = std::find_if(
dependency_abis.begin(), dependency_abis.end(), [](const auto& dep_abi) { return dep_abi.value.empty(); });
auto dep_no_hash_it = std::find_if(dependency_abis.begin(), dependency_abis.end(), [](const auto& dep_abi) {
return dep_abi.value.empty();
});
if (dep_no_hash_it != dependency_abis.end())
{
Debug::print("Binary caching for package ",
spec,
" is disabled due to missing abi info for ",
dep_no_hash_it->key,
'\n');
spec,
" is disabled due to missing abi info for ",
dep_no_hash_it->key,
'\n');
return false;
}
}
Expand All @@ -277,10 +279,10 @@ namespace vcpkg

// PRE: initialize_abi_tag() was called and returned true
static PackageAbiResult make_abi_tag(const VcpkgPaths& paths,
InstallPlanAction& action,
View<AbiEntry> common_abi,
std::vector<AbiEntry>&& dependency_abis,
const AsyncLazy<std::vector<AbiEntry>>& cmake_script_hashes)
InstallPlanAction& action,
View<AbiEntry> common_abi,
std::vector<AbiEntry>&& dependency_abis,
const AsyncLazy<std::vector<AbiEntry>>& cmake_script_hashes)
{
auto& fs = paths.get_filesystem();
AbiInfo& abi_info = *action.abi_info.get();
Expand All @@ -291,13 +293,13 @@ namespace vcpkg

// abi tags from prebuildinfo
abi_entries_from_pre_build_info(fs, *abi_info.pre_build_info, abi_tag_entries);

auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);

// portfile hashes/contents
auto&& [port_files_abi, cmake_contents] = get_port_files(fs, scfl);
abi_tag_entries.insert(abi_tag_entries.end(), port_files_abi.cbegin(), port_files_abi.cend());

// cmake helpers (access to cmake helper hashes in cache not in parallel)
for (auto&& helper : cmake_script_hashes.get())
{
Expand Down Expand Up @@ -332,7 +334,8 @@ namespace vcpkg
std::string full_abi_info =
Strings::join("", abi_tag_entries, [](const AbiEntry& p) { return p.key + " " + p.value + "\n"; });
abi_info.package_abi = Hash::get_string_sha256(full_abi_info);
abi_info.abi_tag_file.emplace(paths.build_dir(action.spec) / action.spec.triplet().canonical_name() + ".vcpkg_abi_info.txt");
abi_info.abi_tag_file.emplace(paths.build_dir(action.spec) / action.spec.triplet().canonical_name() +
".vcpkg_abi_info.txt");

return {action, std::move(full_abi_info), std::move(cmake_contents), std::move(port_files_abi)};
}
Expand Down Expand Up @@ -382,7 +385,7 @@ namespace vcpkg
}
return dependency_abis;
}

void compute_all_abis(const VcpkgPaths& paths,
ActionPlan& action_plan,
const CMakeVars::CMakeVarProvider& var_provider,
Expand Down Expand Up @@ -424,17 +427,23 @@ namespace vcpkg
}
}

abi_results.push_back(make_abi_tag(paths, action, common_abi, std::move(dependency_abis), cmake_script_hashes));
abi_results.push_back(
make_abi_tag(paths, action, common_abi, std::move(dependency_abis), cmake_script_hashes));
}
// populate abi tag
for (auto&& abi_result : abi_results)
{
// write abi tag file
fs.write_contents_and_dirs(abi_result.action.abi_info.value_or_exit(VCPKG_LINE_INFO).abi_tag_file.value_or_exit(VCPKG_LINE_INFO), abi_result.abi_str, VCPKG_LINE_INFO);

fs.write_contents_and_dirs(
abi_result.action.abi_info.value_or_exit(VCPKG_LINE_INFO).abi_tag_file.value_or_exit(VCPKG_LINE_INFO),
abi_result.abi_str,
VCPKG_LINE_INFO);

// make and write sbom file
auto& scf = abi_result.action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO).source_control_file;
std::vector<Json::Value> heuristic_resources{run_resource_heuristics(abi_result.cmake_content, scf->core_paragraph->raw_version)};
auto& scf =
abi_result.action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO).source_control_file;
std::vector<Json::Value> heuristic_resources{
run_resource_heuristics(abi_result.cmake_content, scf->core_paragraph->raw_version)};
write_sbom(paths, abi_result.action, std::move(heuristic_resources), abi_result.port_files_abi);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/vcpkg/commands.build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,6 @@ namespace vcpkg
return result;
}


ExtendedBuildResult build_package(const VcpkgCmdArguments& args,
const VcpkgPaths& paths,
const InstallPlanAction& action,
Expand Down
40 changes: 19 additions & 21 deletions src/vcpkg/spdx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,27 +258,25 @@ void vcpkg::write_sbom(const VcpkgPaths& paths,
const InstallPlanAction& action,
std::vector<Json::Value> heuristic_resources,
const std::vector<AbiEntry>& port_files_abi)
{
auto& fs = paths.get_filesystem();
const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);
const auto& scf = *scfl.source_control_file;
{
auto& fs = paths.get_filesystem();
const auto& scfl = action.source_control_file_and_location.value_or_exit(VCPKG_LINE_INFO);
const auto& scf = *scfl.source_control_file;

auto doc_ns = Strings::concat("https://spdx.org/spdxdocs/",
scf.core_paragraph->name,
'-',
action.spec.triplet(),
'-',
scf.to_version(),
'-',
generate_random_UUID());
auto doc_ns = Strings::concat("https://spdx.org/spdxdocs/",
scf.core_paragraph->name,
'-',
action.spec.triplet(),
'-',
scf.to_version(),
'-',
generate_random_UUID());

const auto now = CTime::now_string();
const auto now = CTime::now_string();

const auto json_path =
action.package_dir.value_or_exit(VCPKG_LINE_INFO) / "share" / action.spec.name() / "vcpkg.spdx.json";
fs.write_contents_and_dirs(
json_path,
create_spdx_sbom(
action, port_files_abi, now, doc_ns, std::move(heuristic_resources)),
VCPKG_LINE_INFO);
}
const auto json_path =
action.package_dir.value_or_exit(VCPKG_LINE_INFO) / "share" / action.spec.name() / "vcpkg.spdx.json";
fs.write_contents_and_dirs(json_path,
create_spdx_sbom(action, port_files_abi, now, doc_ns, std::move(heuristic_resources)),
VCPKG_LINE_INFO);
}

0 comments on commit 2450ad8

Please sign in to comment.