From 8fe1851e1eb51a971b2b7cfdb8161ac03bbbd6d5 Mon Sep 17 00:00:00 2001 From: ras0219 <533828+ras0219@users.noreply.github.com> Date: Tue, 6 Oct 2020 12:06:26 -0700 Subject: [vcpkg] Enable reentrant vcpkg calls (#13751) * [vcpkg] Enable recursive vcpkg calls Via envvars VCPKG_COMMAND and VCPKG_X_RECURSIVE_DATA. Child processes can call vcpkg via "$VCPKG_COMMAND " in limited internal circumstances. * [vcpkg] Address CR comments * [vcpkg] Do not move through Optional<&> into Optional Co-authored-by: Robert Schumacher --- toolsrc/include/vcpkg/base/optional.h | 18 ++++++++++++++++++ toolsrc/include/vcpkg/base/system.h | 1 + toolsrc/include/vcpkg/vcpkgcmdarguments.h | 4 ++++ 3 files changed, 23 insertions(+) (limited to 'toolsrc/include') diff --git a/toolsrc/include/vcpkg/base/optional.h b/toolsrc/include/vcpkg/base/optional.h index 54e370dff..caacf815e 100644 --- a/toolsrc/include/vcpkg/base/optional.h +++ b/toolsrc/include/vcpkg/base/optional.h @@ -29,6 +29,24 @@ namespace vcpkg constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() { } constexpr OptionalStorage(const T& t) : m_is_present(true), m_t(t) { } constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) { } + template::value>> + constexpr explicit OptionalStorage(Optional&& t) : m_is_present(false), m_inactive() + { + if (auto p = t.get()) + { + m_is_present = true; + new (&m_t) T(std::move(*p)); + } + } + template + constexpr explicit OptionalStorage(const Optional& t) : m_is_present(false), m_inactive() + { + if (auto p = t.get()) + { + m_is_present = true; + new (&m_t) T(*p); + } + } ~OptionalStorage() noexcept { diff --git a/toolsrc/include/vcpkg/base/system.h b/toolsrc/include/vcpkg/base/system.h index 2340728fd..8e45f6538 100644 --- a/toolsrc/include/vcpkg/base/system.h +++ b/toolsrc/include/vcpkg/base/system.h @@ -8,6 +8,7 @@ namespace vcpkg::System { Optional get_environment_variable(ZStringView varname) noexcept; + void set_environment_variable(ZStringView varname, Optional value) noexcept; const ExpectedS& get_home_dir() noexcept; diff --git a/toolsrc/include/vcpkg/vcpkgcmdarguments.h b/toolsrc/include/vcpkg/vcpkgcmdarguments.h index 3901000e3..eaf5cc3eb 100644 --- a/toolsrc/include/vcpkg/vcpkgcmdarguments.h +++ b/toolsrc/include/vcpkg/vcpkgcmdarguments.h @@ -174,10 +174,13 @@ namespace vcpkg constexpr static StringLiteral REGISTRIES_FEATURE = "registries"; Optional registries_feature = nullopt; + constexpr static StringLiteral RECURSIVE_DATA_ENV = "VCPKG_X_RECURSIVE_DATA"; + bool binary_caching_enabled() const { return binary_caching.value_or(true); } bool compiler_tracking_enabled() const { return compiler_tracking.value_or(true); } bool registries_enabled() const { return registries_feature.value_or(false); } bool output_json() const { return json.value_or(false); } + bool is_recursive_invocation() const { return m_is_recursive_invocation; } std::string command; std::vector command_arguments; @@ -192,6 +195,7 @@ namespace vcpkg void track_feature_flag_metrics() const; private: + bool m_is_recursive_invocation = false; std::unordered_set command_switches; std::unordered_map> command_options; }; -- cgit v1.2.3