Skip to content

Commit

Permalink
[vcpkg] Add experimental x-azblob binary provider
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219 authored and ras0219-msft committed Sep 20, 2020
1 parent 1359075 commit 7cc0443
Show file tree
Hide file tree
Showing 11 changed files with 599 additions and 193 deletions.
5 changes: 5 additions & 0 deletions toolsrc/include/vcpkg/base/downloads.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vcpkg/base/files.h>
#include <vcpkg/base/view.h>

namespace vcpkg::Downloads
{
Expand All @@ -13,4 +14,8 @@ namespace vcpkg::Downloads
const std::string& url,
const fs::path& download_path,
const std::string& sha512);

std::vector<int> download_files(Files::Filesystem& fs, View<std::pair<std::string, fs::path>> url_pairs);
int put_file(const Files::Filesystem&, StringView url, const fs::path& file);
std::vector<int> url_heads(View<std::string> urls);
}
36 changes: 36 additions & 0 deletions toolsrc/include/vcpkg/base/lockguarded.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

#include <mutex>

namespace vcpkg::Util
{
template<class T>
struct LockGuardPtr;

template<class T>
struct LockGuarded
{
friend struct LockGuardPtr<T>;

LockGuardPtr<T> lock() { return *this; }

private:
std::mutex m_mutex;
T m_t;
};

template<class T>
struct LockGuardPtr
{
T& operator*() { return m_ptr; }
T* operator->() { return &m_ptr; }

T* get() { return &m_ptr; }

LockGuardPtr(LockGuarded<T>& sync) : m_lock(sync.m_mutex), m_ptr(sync.m_t) { }

private:
std::unique_lock<std::mutex> m_lock;
T& m_ptr;
};
}
30 changes: 0 additions & 30 deletions toolsrc/include/vcpkg/base/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,36 +222,6 @@ namespace vcpkg::Util
~ResourceBase() = default;
};

template<class T>
struct LockGuardPtr;

template<class T>
struct LockGuarded
{
friend struct LockGuardPtr<T>;

LockGuardPtr<T> lock() { return *this; }

private:
std::mutex m_mutex;
T m_t;
};

template<class T>
struct LockGuardPtr
{
T& operator*() { return m_ptr; }
T* operator->() { return &m_ptr; }

T* get() { return &m_ptr; }

LockGuardPtr(LockGuarded<T>& sync) : m_lock(sync.m_mutex), m_ptr(sync.m_t) { }

private:
std::unique_lock<std::mutex> m_lock;
T& m_ptr;
};

namespace Enum
{
template<class E>
Expand Down
25 changes: 21 additions & 4 deletions toolsrc/include/vcpkg/binarycaching.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <vcpkg/packagespec.h>
#include <vcpkg/vcpkgpaths.h>

#include <set>

namespace vcpkg::Dependencies
{
struct InstallPlanAction;
Expand All @@ -19,6 +21,8 @@ namespace vcpkg::Build

namespace vcpkg
{
struct MergeBinaryProviders;

enum class RestoreResult
{
missing,
Expand All @@ -31,14 +35,27 @@ namespace vcpkg
virtual ~IBinaryProvider() = default;
/// Gives the BinaryProvider an opportunity to batch any downloading or server communication for executing
/// `plan`.
virtual void prefetch(const VcpkgPaths& paths, const Dependencies::ActionPlan& plan) = 0;
void prefetch(const VcpkgPaths& paths, const Dependencies::ActionPlan& plan);
/// Attempts to restore the package referenced by `action` into the packages directory.
virtual RestoreResult try_restore(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
virtual RestoreResult try_restore(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action);
/// Called upon a successful build of `action`
virtual void push_success(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
virtual void push_success(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action);
/// Requests the result of `try_restore()` without actually downloading the package. Used by CI to determine
/// missing packages.
std::unordered_map<const Dependencies::InstallPlanAction*, RestoreResult> precheck(
const VcpkgPaths& paths, View<Dependencies::InstallPlanAction> actions);

friend struct MergeBinaryProviders;

protected:
virtual void prefetch(const VcpkgPaths& paths,
const Dependencies::ActionPlan& plan,
std::set<PackageSpec>* restored);

/// Requests the result of `try_restore()` without actually downloading the package. Used by CI to determine
/// missing packages.
virtual RestoreResult precheck(const VcpkgPaths& paths, const Dependencies::InstallPlanAction& action) = 0;
virtual void precheck(const VcpkgPaths& paths,
std::unordered_map<const Dependencies::InstallPlanAction*, RestoreResult>* results_map);
};

IBinaryProvider& null_binary_provider();
Expand Down
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/dependencies.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace vcpkg::Dependencies
std::string displayname() const;
const std::string& public_abi() const;
bool has_package_abi() const;
Optional<const std::string&> package_abi() const;
const Build::PreBuildInfo& pre_build_info(LineInfo linfo) const;

PackageSpec spec;
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/include/vcpkg/globalstate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <vcpkg/base/chrono.h>
#include <vcpkg/base/util.h>
#include <vcpkg/base/lockguarded.h>

#include <atomic>
#include <string>
Expand Down
1 change: 1 addition & 0 deletions toolsrc/include/vcpkg/metrics.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vcpkg/base/files.h>
#include <vcpkg/base/lockguarded.h>
#include <vcpkg/base/util.h>

#include <string>
Expand Down
Loading

0 comments on commit 7cc0443

Please sign in to comment.