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

Rework and parallelize abi hashing #1225

Open
wants to merge 72 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
09ae1d1
wip
Thomas1664 Oct 8, 2023
f5de1c6
revert unrelated changes
Thomas1664 Oct 8, 2023
2ccb2cf
revert unrelated changes
Thomas1664 Oct 8, 2023
7c70020
revert unrelated changes
Thomas1664 Oct 8, 2023
4a2a33f
remove abi things from vcpkg paths
Thomas1664 Oct 8, 2023
a89aec4
dependency abis
Thomas1664 Oct 8, 2023
8c0ed22
AsyncLazy
Thomas1664 Oct 9, 2023
2b4fef5
Fix dangling thread in AsyncLazy
Thomas1664 Oct 10, 2023
fc89573
~future does this already
Thomas1664 Oct 10, 2023
49485da
wip
Thomas1664 Oct 14, 2023
4e61638
fix some compile errors
Thomas1664 Oct 14, 2023
0a60508
Satisfy preconditions
Thomas1664 Oct 14, 2023
e03aaa5
Fix bug
Thomas1664 Oct 14, 2023
01a61a1
static grdk cache
Thomas1664 Oct 15, 2023
425840c
Write abi and spdx files
Thomas1664 Oct 15, 2023
5b6f45d
Fix stack buffer overflow
Thomas1664 Oct 15, 2023
2450ad8
format
Thomas1664 Oct 15, 2023
4365002
Fix build
Thomas1664 Oct 16, 2023
935037a
Fill in toolset
Thomas1664 Oct 16, 2023
3c79afb
Properly save files
Thomas1664 Oct 16, 2023
512ffd5
format
Thomas1664 Oct 16, 2023
39cf12e
Merge branch 'microsoft:main' into parallel-abi-hashes
Thomas1664 Oct 19, 2023
f09aebe
async
Thomas1664 Oct 28, 2023
9760190
Merge branch 'main' into parallel-abi-hashes
Thomas1664 Oct 28, 2023
5e4acb3
reorder to avoid vector copy
Thomas1664 Oct 28, 2023
e129cd2
avoid potential bad optional access
Thomas1664 Oct 28, 2023
e1b9a8a
format
Thomas1664 Oct 28, 2023
840c684
common abi causes race when trying to download pwsh
Thomas1664 Oct 28, 2023
0e934c9
remove debug code
Thomas1664 Oct 28, 2023
256a515
remove async lazy
Thomas1664 Oct 28, 2023
33178d5
revert any changes to lazy.h
Thomas1664 Oct 28, 2023
93fb0f4
back to const&
Thomas1664 Oct 28, 2023
16189f1
format
Thomas1664 Oct 28, 2023
1103176
const_iterator
Thomas1664 Oct 28, 2023
a0695ca
Fix sbom data race
Thomas1664 Oct 28, 2023
0f67c89
Generate UUID in parallel
Thomas1664 Oct 28, 2023
ace0d3d
Avoid Strings::join
Thomas1664 Oct 28, 2023
324c087
Merge branch 'microsoft:main' into parallel-abi-hashes
Thomas1664 Nov 1, 2023
1ba7070
Merge branch 'microsoft:main' into parallel-abi-hashes
Thomas1664 Nov 4, 2023
f475440
Fix merge
Thomas1664 Nov 4, 2023
3ea517a
Merge branch 'main' into parallel-abi-hashes
Thomas1664 Nov 9, 2023
cdc412e
Fix merge
Thomas1664 Nov 9, 2023
7ba0ddf
prepare merge
Thomas1664 Nov 16, 2023
af8bc6e
Merge branch 'main' into parallel-abi-hashes
Thomas1664 Nov 16, 2023
972435e
format
Thomas1664 Nov 16, 2023
4e877f3
Merge branch 'parallel-abi-hashes' of https://github.com/Thomas1664/v…
Thomas1664 Nov 16, 2023
6586362
sanitize includes
Thomas1664 Nov 16, 2023
f8e0040
sanitize includes
Thomas1664 Nov 16, 2023
75d720c
Sanitize includes
Thomas1664 Nov 16, 2023
c4c0282
sanitize comments
Thomas1664 Nov 16, 2023
99b1b01
small improvements
Thomas1664 Nov 28, 2023
1a5a128
fix '2'
Thomas1664 Nov 28, 2023
5c53988
format
Thomas1664 Nov 28, 2023
3cf9414
Merge branch 'main' into parallel-abi-hashes
Thomas1664 Dec 16, 2023
b2a48cc
Fix merge
Thomas1664 Dec 16, 2023
9a0e6cb
Merge remote-tracking branch 'origin/main' into parallel-abi-hashes
Thomas1664 Mar 18, 2024
17b12b5
fix merge
Thomas1664 Mar 18, 2024
ba828da
format
Thomas1664 Mar 18, 2024
aa74502
Merge remote-tracking branch 'origin/main' into parallel-abi-hashes
Thomas1664 Mar 22, 2024
323e93c
try fix e2e
Thomas1664 Mar 22, 2024
497b967
fix e2e
Thomas1664 Mar 22, 2024
5d9be80
try again
Thomas1664 Mar 22, 2024
3fe1e3e
remove old e2e code
Thomas1664 Mar 22, 2024
a6b3842
Merge remote-tracking branch 'origin/main' into parallel-abi-hashes
Thomas1664 Apr 8, 2024
33d08f6
fix merge
Thomas1664 Apr 8, 2024
c12f20e
format
Thomas1664 Apr 8, 2024
03fbb31
Merge remote-tracking branch 'upstream/main' into parallel-abi-hashes
Thomas1664 Aug 25, 2024
56a7c35
Merge branch 'main' into parallel-abi-hashes
Thomas1664 Aug 25, 2024
d39dea7
format
Thomas1664 Aug 25, 2024
a2de0c1
Try fix merge
Thomas1664 Aug 25, 2024
4b84a33
Fix paths
Thomas1664 Aug 25, 2024
e9c9ab6
Restore fixes from upstream/main
Thomas1664 Aug 25, 2024
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
66 changes: 66 additions & 0 deletions include/vcpkg/abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#pragma once

#include <vcpkg/fwd/abi.h>
#include <vcpkg/fwd/cmakevars.h>
#include <vcpkg/fwd/dependencies.h>
#include <vcpkg/fwd/vcpkgpaths.h>

#include <vcpkg/base/optional.h>
#include <vcpkg/base/path.h>

#include <vcpkg/commands.build.h>
#include <vcpkg/statusparagraphs.h>

#include <memory>
#include <string>
#include <vector>

namespace vcpkg
{
struct AbiEntry
{
std::string key;
std::string value;

AbiEntry() = default;
AbiEntry(std::string key, std::string value) : key(std::move(key)), value(std::move(value)) { }

bool operator<(const AbiEntry& other) const noexcept
{
return key < other.key || (key == other.key && value < other.value);
}
};

struct AbiInfo
{
// These should always be known if an AbiInfo exists
std::unique_ptr<PreBuildInfo> pre_build_info;
Optional<const Toolset&> toolset;
// These might not be known if compiler tracking is turned off or the port is --editable
Optional<const CompilerInfo&> compiler_info;
Optional<const std::string&> triplet_abi;
std::string package_abi;

// Checks if full abi tag was created
bool abi_tag_complete() const noexcept { return package_abi.size() != 0; }

void abi_file_contents(std::string&& abi_tag, std::string&& sbom_file) noexcept
{
abi_tag_file_contents.emplace(std::move(abi_tag));
sbom_file_contents.emplace(std::move(sbom_file));
}

// PRE: abi_tag_complete() == true
// dir: Directory where the files should be saved, usually packages_dir/share
void save_abi_files(const Filesystem& fs, Path&& dir) const;

private:
Optional<std::string> abi_tag_file_contents;
Optional<std::string> sbom_file_contents;
};

void compute_all_abis(const VcpkgPaths& paths,
ActionPlan& action_plan,
const CMakeVars::CMakeVarProvider& var_provider,
const StatusParagraphs& status_db);
} // namespace vcpkg
3 changes: 2 additions & 1 deletion include/vcpkg/base/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ namespace vcpkg

const char* c_str() const noexcept;

std::string generic_u8string() const;
std::string generic_u8string() const&;
std::string generic_u8string() &&;

bool empty() const noexcept;

Expand Down
34 changes: 0 additions & 34 deletions include/vcpkg/commands.build.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,6 @@ namespace vcpkg

BuildInfo read_build_info(const ReadOnlyFilesystem& fs, const Path& filepath);

struct AbiEntry
{
std::string key;
std::string value;

AbiEntry() = default;
AbiEntry(StringView key, StringView value) : key(key.to_string()), value(value.to_string()) { }

bool operator<(const AbiEntry& other) const
{
return key < other.key || (key == other.key && value < other.value);
}
};

struct CompilerInfo
{
std::string id;
Expand All @@ -234,26 +220,6 @@ namespace vcpkg
std::string path;
};

struct AbiInfo
{
// These should always be known if an AbiInfo exists
std::unique_ptr<PreBuildInfo> pre_build_info;
Optional<const Toolset&> toolset;
// These might not be known if compiler tracking is turned off or the port is --editable
Optional<const CompilerInfo&> compiler_info;
Optional<const std::string&> triplet_abi;
std::string package_abi;
Optional<Path> abi_tag_file;
std::vector<Path> relative_port_files;
std::vector<std::string> relative_port_hashes;
std::vector<Json::Value> heuristic_resources;
};

void compute_all_abis(const VcpkgPaths& paths,
ActionPlan& action_plan,
const CMakeVars::CMakeVarProvider& var_provider,
const StatusParagraphs& status_db);

struct EnvCache
{
explicit EnvCache(bool compiler_tracking) : m_compiler_tracking(compiler_tracking) { }
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <vcpkg/base/optional.h>

#include <vcpkg/abi.h>
#include <vcpkg/commands.build.h>
#include <vcpkg/packagespec.h>
#include <vcpkg/statusparagraph.h>
Expand Down
7 changes: 7 additions & 0 deletions include/vcpkg/fwd/abi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace vcpkg
{
struct AbiInfo;
struct AbiEntry;
}
2 changes: 0 additions & 2 deletions include/vcpkg/fwd/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ namespace vcpkg
struct PreBuildInfo;
struct ExtendedBuildResult;
struct BuildInfo;
struct AbiEntry;
struct CompilerInfo;
struct AbiInfo;
struct EnvCache;
struct BuildCommand;
}
8 changes: 6 additions & 2 deletions include/vcpkg/spdx.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <vcpkg/base/fwd/json.h>
#include <vcpkg/base/fwd/stringview.h>

#include <vcpkg/fwd/abi.h>
#include <vcpkg/fwd/dependencies.h>

#include <vcpkg/base/span.h>
Expand All @@ -23,11 +24,14 @@ namespace vcpkg
/// @param resource_docs Additional documents to concatenate into the created document. These are intended to
/// capture fetched resources, such as tools or source archives.
std::string create_spdx_sbom(const InstallPlanAction& action,
View<Path> relative_paths,
View<std::string> hashes,
View<AbiEntry> port_files_abi,
std::string created_time,
std::string document_namespace,
std::vector<Json::Value>&& resource_docs);

Json::Value run_resource_heuristics(StringView contents, StringView portRawVersion);
std::string write_sbom(const InstallPlanAction& action,
std::vector<Json::Value>&& heuristic_resources,
const std::vector<AbiEntry>& port_files_abi,
StringView uuid);
}
2 changes: 0 additions & 2 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ namespace vcpkg
Path build_info_file_path(const PackageSpec& spec) const;

const TripletDatabase& get_triplet_db() const;
const std::map<std::string, std::string>& get_cmake_script_hashes() const;
StringView get_ports_cmake_hash() const;

LockFile& get_installed_lockfile() const;
void flush_lockfile() const;
Expand Down
1 change: 1 addition & 0 deletions src/vcpkg-test/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <vcpkg/base/xmlserializer.h>

#include <vcpkg/abi.h>
#include <vcpkg/binarycaching.h>
#include <vcpkg/binarycaching.private.h>
#include <vcpkg/dependencies.h>
Expand Down
23 changes: 9 additions & 14 deletions src/vcpkg-test/spdx.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <vcpkg-test/util.h>

#include <vcpkg/abi.h>
#include <vcpkg/dependencies.h>
#include <vcpkg/spdx.h>

Expand All @@ -25,13 +26,11 @@ TEST_CASE ("spdx maximum serialization", "[spdx]")
auto& abi = *(ipa.abi_info = AbiInfo{}).get();
abi.package_abi = "ABIHASH";

const auto sbom =
create_spdx_sbom(ipa,
std::vector<Path>{"vcpkg.json", "portfile.cmake", "patches/patch1.diff"},
std::vector<std::string>{"vcpkg.json-hash", "portfile.cmake-hash", "patch1.diff-hash"},
"now",
"https://test-document-namespace",
{});
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", {});

auto expected = Json::parse(R"json(
{
Expand Down Expand Up @@ -179,13 +178,9 @@ TEST_CASE ("spdx minimum serialization", "[spdx]")
spec, scfl, "test_packages_root", RequestType::USER_REQUESTED, UseHeadVersion::No, Editable::No, {}, {}, {});
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"}};

const auto sbom = create_spdx_sbom(ipa,
std::vector<Path>{"vcpkg.json", "portfile.cmake"},
std::vector<std::string>{"hash-vcpkg.json", "hash-portfile.cmake"},
"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 Expand Up @@ -326,7 +321,7 @@ TEST_CASE ("spdx concat resources", "[spdx]")
.value(VCPKG_LINE_INFO)
.value;

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

auto expected = Json::parse(R"json(
{
Expand Down
Loading
Loading