aboutsummaryrefslogtreecommitdiff
path: root/toolsrc
diff options
context:
space:
mode:
Diffstat (limited to 'toolsrc')
-rw-r--r--toolsrc/include/LineInfo.h2
-rw-r--r--toolsrc/include/PackageSpec.h6
-rw-r--r--toolsrc/include/PackageSpecParseResult.h32
-rw-r--r--toolsrc/include/Paragraphs.h3
-rw-r--r--toolsrc/include/PostBuildLint_BuildType.h32
-rw-r--r--toolsrc/include/PostBuildLint_ConfigurationType.h36
-rw-r--r--toolsrc/include/PostBuildLint_LinkageType.h38
-rw-r--r--toolsrc/include/SourceParagraph.h54
-rw-r--r--toolsrc/include/VcpkgPaths.h9
-rw-r--r--toolsrc/include/vcpkg_Build.h57
-rw-r--r--toolsrc/include/vcpkg_Commands.h7
-rw-r--r--toolsrc/include/vcpkg_Util.h6
-rw-r--r--toolsrc/include/vcpkg_expected.h79
-rw-r--r--toolsrc/src/BinaryParagraph.cpp2
-rw-r--r--toolsrc/src/PackageSpec.cpp10
-rw-r--r--toolsrc/src/PackageSpecParseResult.cpp24
-rw-r--r--toolsrc/src/Paragraphs.cpp23
-rw-r--r--toolsrc/src/PostBuildLint.cpp17
-rw-r--r--toolsrc/src/PostBuildLint_BuildType.cpp12
-rw-r--r--toolsrc/src/PostBuildLint_ConfigurationType.cpp24
-rw-r--r--toolsrc/src/PostBuildLint_LinkageType.cpp39
-rw-r--r--toolsrc/src/SourceParagraph.cpp126
-rw-r--r--toolsrc/src/VcpkgPaths.cpp78
-rw-r--r--toolsrc/src/commands_build.cpp22
-rw-r--r--toolsrc/src/commands_ci.cpp55
-rw-r--r--toolsrc/src/commands_env.cpp2
-rw-r--r--toolsrc/src/commands_install.cpp147
-rw-r--r--toolsrc/src/tests_dependencies.cpp65
-rw-r--r--toolsrc/src/tests_paragraph.cpp87
-rw-r--r--toolsrc/src/vcpkg.cpp4
-rw-r--r--toolsrc/src/vcpkg_Build.cpp55
-rw-r--r--toolsrc/src/vcpkg_Dependencies.cpp10
-rw-r--r--toolsrc/src/vcpkg_Files.cpp6
-rw-r--r--toolsrc/src/vcpkg_Input.cpp4
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj4
-rw-r--r--toolsrc/vcpkglib/vcpkglib.vcxproj.filters12
36 files changed, 676 insertions, 513 deletions
diff --git a/toolsrc/include/LineInfo.h b/toolsrc/include/LineInfo.h
index 66d91c520..62973462a 100644
--- a/toolsrc/include/LineInfo.h
+++ b/toolsrc/include/LineInfo.h
@@ -1,5 +1,7 @@
#pragma once
+#include <string>
+
namespace vcpkg
{
struct LineInfo
diff --git a/toolsrc/include/PackageSpec.h b/toolsrc/include/PackageSpec.h
index 050d9d079..58edb8274 100644
--- a/toolsrc/include/PackageSpec.h
+++ b/toolsrc/include/PackageSpec.h
@@ -7,9 +7,11 @@ namespace vcpkg
{
struct PackageSpec
{
- static Expected<PackageSpec> from_string(const std::string& spec_as_string, const Triplet& default_triplet);
+ static ExpectedT<PackageSpec, PackageSpecParseResult> from_string(const std::string& spec_as_string,
+ const Triplet& default_triplet);
static std::string to_string(const std::string& name, const Triplet& triplet);
- static Expected<PackageSpec> from_name_and_triplet(const std::string& name, const Triplet& triplet);
+ static ExpectedT<PackageSpec, PackageSpecParseResult> from_name_and_triplet(const std::string& name,
+ const Triplet& triplet);
const std::string& name() const;
diff --git a/toolsrc/include/PackageSpecParseResult.h b/toolsrc/include/PackageSpecParseResult.h
index b72c534c2..1462b8073 100644
--- a/toolsrc/include/PackageSpecParseResult.h
+++ b/toolsrc/include/PackageSpecParseResult.h
@@ -1,5 +1,6 @@
#pragma once
-#include <system_error>
+
+#include "vcpkg_expected.h"
namespace vcpkg
{
@@ -10,27 +11,22 @@ namespace vcpkg
INVALID_CHARACTERS
};
- struct PackageSpecParseResultCategoryImpl final : std::error_category
- {
- virtual const char* name() const noexcept override;
+ CStringView to_string(PackageSpecParseResult ev) noexcept;
- virtual std::string message(int ev) const noexcept override;
- };
-
- const std::error_category& package_spec_parse_result_category();
+ template<>
+ struct ErrorHolder<PackageSpecParseResult>
+ {
+ ErrorHolder() : m_err(PackageSpecParseResult::SUCCESS) {}
+ ErrorHolder(PackageSpecParseResult err) : m_err(err) {}
- std::error_code make_error_code(PackageSpecParseResult e);
+ constexpr bool has_error() const { return m_err != PackageSpecParseResult::SUCCESS; }
- PackageSpecParseResult to_package_spec_parse_result(int i);
+ const PackageSpecParseResult& error() const { return m_err; }
+ PackageSpecParseResult& error() { return m_err; }
- PackageSpecParseResult to_package_spec_parse_result(std::error_code ec);
-}
+ CStringView to_string() const { return vcpkg::to_string(m_err); }
-// Enable implicit conversion to std::error_code
-namespace std
-{
- template<>
- struct is_error_code_enum<vcpkg::PackageSpecParseResult> : ::std::true_type
- {
+ private:
+ PackageSpecParseResult m_err;
};
}
diff --git a/toolsrc/include/Paragraphs.h b/toolsrc/include/Paragraphs.h
index 66f6bd2e4..59f0eefc8 100644
--- a/toolsrc/include/Paragraphs.h
+++ b/toolsrc/include/Paragraphs.h
@@ -16,7 +16,8 @@ namespace vcpkg::Paragraphs
Expected<ParagraphDataMap> parse_single_paragraph(const std::string& str);
Expected<std::vector<ParagraphDataMap>> parse_paragraphs(const std::string& str);
- Expected<SourceParagraph> try_load_port(const Files::Filesystem& fs, const fs::path& control_path);
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> try_load_port(const Files::Filesystem& fs,
+ const fs::path& control_path);
Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec);
diff --git a/toolsrc/include/PostBuildLint_BuildType.h b/toolsrc/include/PostBuildLint_BuildType.h
index 58bb20766..38ad3084e 100644
--- a/toolsrc/include/PostBuildLint_BuildType.h
+++ b/toolsrc/include/PostBuildLint_BuildType.h
@@ -1,12 +1,17 @@
#pragma once
#include "CStringView.h"
-#include "PostBuildLint_ConfigurationType.h"
-#include "PostBuildLint_LinkageType.h"
+#include "vcpkg_Build.h"
#include <array>
#include <regex>
namespace vcpkg::PostBuildLint
{
+ enum class ConfigurationType
+ {
+ DEBUG,
+ RELEASE,
+ };
+
struct BuildType
{
enum class BackingEnum
@@ -17,11 +22,13 @@ namespace vcpkg::PostBuildLint
RELEASE_DYNAMIC
};
- static BuildType value_of(const ConfigurationType& config, const LinkageType& linkage);
+ static BuildType value_of(const ConfigurationType& config, const Build::LinkageType& linkage);
BuildType() = delete;
- constexpr BuildType(const BackingEnum backing_enum, const ConfigurationType config, const LinkageType linkage)
+ constexpr BuildType(const BackingEnum backing_enum,
+ const ConfigurationType config,
+ const Build::LinkageType linkage)
: backing_enum(backing_enum), m_config(config), m_linkage(linkage)
{
}
@@ -29,28 +36,29 @@ namespace vcpkg::PostBuildLint
constexpr operator BackingEnum() const { return backing_enum; }
const ConfigurationType& config() const;
- const LinkageType& linkage() const;
+ const Build::LinkageType& linkage() const;
const std::regex& crt_regex() const;
const std::string& to_string() const;
private:
BackingEnum backing_enum;
ConfigurationType m_config;
- LinkageType m_linkage;
+ Build::LinkageType m_linkage;
};
namespace BuildTypeC
{
- namespace CC = ConfigurationTypeC;
- namespace LC = LinkageTypeC;
+ using Build::LinkageType;
using BE = BuildType::BackingEnum;
static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::BuildType";
- static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, CC::DEBUG, LC::STATIC};
- static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, CC::DEBUG, LC::DYNAMIC};
- static constexpr BuildType RELEASE_STATIC = {BE::RELEASE_STATIC, CC::RELEASE, LC::STATIC};
- static constexpr BuildType RELEASE_DYNAMIC = {BE::RELEASE_DYNAMIC, CC::RELEASE, LC::DYNAMIC};
+ static constexpr BuildType DEBUG_STATIC = {BE::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageType::STATIC};
+ static constexpr BuildType DEBUG_DYNAMIC = {BE::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageType::DYNAMIC};
+ static constexpr BuildType RELEASE_STATIC = {
+ BE::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageType::STATIC};
+ static constexpr BuildType RELEASE_DYNAMIC = {
+ BE::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageType::DYNAMIC};
static constexpr std::array<BuildType, 4> VALUES = {
DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC};
diff --git a/toolsrc/include/PostBuildLint_ConfigurationType.h b/toolsrc/include/PostBuildLint_ConfigurationType.h
deleted file mode 100644
index 8157415b0..000000000
--- a/toolsrc/include/PostBuildLint_ConfigurationType.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-#include "CStringView.h"
-#include <string>
-
-namespace vcpkg::PostBuildLint
-{
- struct ConfigurationType
- {
- enum class BackingEnum
- {
- NULLVALUE = 0,
- DEBUG = 1,
- RELEASE = 2
- };
-
- constexpr ConfigurationType() : backing_enum(BackingEnum::NULLVALUE) {}
- constexpr explicit ConfigurationType(BackingEnum backing_enum) : backing_enum(backing_enum) {}
- constexpr operator BackingEnum() const { return backing_enum; }
-
- const std::string& to_string() const;
-
- private:
- BackingEnum backing_enum;
- };
-
- namespace ConfigurationTypeC
- {
- static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::ConfigurationType";
-
- static constexpr ConfigurationType NULLVALUE(ConfigurationType::BackingEnum::NULLVALUE);
- static constexpr ConfigurationType DEBUG(ConfigurationType::BackingEnum::DEBUG);
- static constexpr ConfigurationType RELEASE(ConfigurationType::BackingEnum::RELEASE);
-
- static constexpr std::array<ConfigurationType, 2> VALUES = {DEBUG, RELEASE};
- }
-}
diff --git a/toolsrc/include/PostBuildLint_LinkageType.h b/toolsrc/include/PostBuildLint_LinkageType.h
deleted file mode 100644
index 8d19dc5a4..000000000
--- a/toolsrc/include/PostBuildLint_LinkageType.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#pragma once
-#include "CStringView.h"
-#include <string>
-
-namespace vcpkg::PostBuildLint
-{
- struct LinkageType final
- {
- enum class BackingEnum
- {
- NULLVALUE = 0,
- DYNAMIC,
- STATIC
- };
-
- static LinkageType value_of(const std::string& as_string);
-
- constexpr LinkageType() : backing_enum(BackingEnum::NULLVALUE) {}
- constexpr explicit LinkageType(BackingEnum backing_enum) : backing_enum(backing_enum) {}
- constexpr operator BackingEnum() const { return backing_enum; }
-
- const std::string& to_string() const;
-
- private:
- BackingEnum backing_enum;
- };
-
- namespace LinkageTypeC
- {
- static constexpr CStringView ENUM_NAME = "vcpkg::PostBuildLint::LinkageType";
-
- static constexpr LinkageType NULLVALUE(LinkageType::BackingEnum::NULLVALUE);
- static constexpr LinkageType DYNAMIC(LinkageType::BackingEnum::DYNAMIC);
- static constexpr LinkageType STATIC(LinkageType::BackingEnum::STATIC);
-
- static constexpr std::array<LinkageType, 2> VALUES = {DYNAMIC, STATIC};
- }
-}
diff --git a/toolsrc/include/SourceParagraph.h b/toolsrc/include/SourceParagraph.h
index 19f558170..a53158f3f 100644
--- a/toolsrc/include/SourceParagraph.h
+++ b/toolsrc/include/SourceParagraph.h
@@ -1,5 +1,9 @@
#pragma once
+#include "vcpkg_System.h"
+#include "vcpkg_expected.h"
+
+#include <string>
#include <unordered_map>
#include <vector>
@@ -15,24 +19,68 @@ namespace vcpkg
const std::string& to_string(const Dependency& dep);
+ struct ParseControlErrorInfo
+ {
+ std::string name;
+ std::string remaining_fields_as_string;
+ std::string valid_fields_as_string;
+ std::error_code error;
+ };
+
/// <summary>
/// Port metadata (CONTROL file)
/// </summary>
struct SourceParagraph
{
- SourceParagraph();
+ static ExpectedT<SourceParagraph, ParseControlErrorInfo> parse_control_file(
+ std::unordered_map<std::string, std::string> fields);
- explicit SourceParagraph(std::unordered_map<std::string, std::string> fields);
+ SourceParagraph() = default;
std::string name;
std::string version;
std::string description;
std::string maintainer;
+ std::vector<std::string> supports;
std::vector<Dependency> depends;
};
+ void print_error_message(const ParseControlErrorInfo& info);
+ void print_error_message(std::vector<ParseControlErrorInfo> error_info_list);
+
std::vector<std::string> filter_dependencies(const std::vector<Dependency>& deps, const Triplet& t);
std::vector<Dependency> expand_qualified_dependencies(const std::vector<std::string>& depends);
- std::vector<std::string> parse_depends(const std::string& depends_string);
+ std::vector<std::string> parse_comma_list(const std::string& str);
+
+ struct Supports
+ {
+ static ExpectedT<Supports, std::vector<std::string>> parse(const std::vector<std::string>& strs);
+
+ using Architecture = System::CPUArchitecture;
+
+ enum class Platform
+ {
+ WINDOWS,
+ UWP,
+ };
+ enum class Linkage
+ {
+ DYNAMIC,
+ STATIC,
+ };
+ enum class ToolsetVersion
+ {
+ V140,
+ V141,
+ };
+
+ bool supports(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools);
+
+ private:
+ std::vector<Architecture> architectures;
+ std::vector<Platform> platforms;
+ std::vector<Linkage> crt_linkages;
+ std::vector<ToolsetVersion> toolsets;
+ };
}
diff --git a/toolsrc/include/VcpkgPaths.h b/toolsrc/include/VcpkgPaths.h
index 25c1728b9..95cd4bc28 100644
--- a/toolsrc/include/VcpkgPaths.h
+++ b/toolsrc/include/VcpkgPaths.h
@@ -48,7 +48,12 @@ namespace vcpkg
const fs::path& get_cmake_exe() const;
const fs::path& get_git_exe() const;
const fs::path& get_nuget_exe() const;
- const Toolset& get_toolset() const;
+
+ /// <summary>Retrieve a toolset matching a VS version</summary>
+ /// <remarks>
+ /// Valid version strings are "v140", "v141", and "". Empty string gets the latest.
+ /// </remarks>
+ const Toolset& get_toolset(const std::string& toolset_version) const;
Files::Filesystem& get_filesystem() const;
@@ -56,6 +61,6 @@ namespace vcpkg
Lazy<fs::path> cmake_exe;
Lazy<fs::path> git_exe;
Lazy<fs::path> nuget_exe;
- Lazy<Toolset> toolset;
+ Lazy<std::vector<Toolset>> toolsets;
};
}
diff --git a/toolsrc/include/vcpkg_Build.h b/toolsrc/include/vcpkg_Build.h
index e0a5ae1ce..e13f66029 100644
--- a/toolsrc/include/vcpkg_Build.h
+++ b/toolsrc/include/vcpkg_Build.h
@@ -2,18 +2,50 @@
#include "CStringView.h"
#include "PackageSpec.h"
-#include "PostBuildLint_LinkageType.h"
#include "StatusParagraphs.h"
#include "VcpkgPaths.h"
#include "vcpkg_Files.h"
#include "vcpkg_optional.h"
+#include <array>
#include <map>
#include <unordered_map>
#include <vector>
namespace vcpkg::Build
{
+ enum class UseHeadVersion
+ {
+ NO = 0,
+ YES
+ };
+
+ inline UseHeadVersion to_use_head_version(const bool value)
+ {
+ return value ? UseHeadVersion::YES : UseHeadVersion::NO;
+ }
+
+ inline bool to_bool(const UseHeadVersion value) { return value == UseHeadVersion::YES; }
+
+ enum class AllowDownloads
+ {
+ NO = 0,
+ YES
+ };
+
+ inline AllowDownloads to_allow_downloads(const bool value)
+ {
+ return value ? AllowDownloads::YES : AllowDownloads::NO;
+ }
+
+ inline bool to_bool(const AllowDownloads value) { return value == AllowDownloads::YES; }
+
+ struct BuildPackageOptions
+ {
+ UseHeadVersion use_head_version;
+ AllowDownloads allow_downloads;
+ };
+
enum class BuildResult
{
NULLVALUE = 0,
@@ -59,17 +91,18 @@ namespace vcpkg::Build
struct BuildPackageConfig
{
- BuildPackageConfig(const SourceParagraph& src, const Triplet& triplet, fs::path&& port_dir)
- : src(src), triplet(triplet), port_dir(std::move(port_dir)), use_head_version(false), no_downloads(false)
+ BuildPackageConfig(const SourceParagraph& src,
+ const Triplet& triplet,
+ fs::path&& port_dir,
+ const BuildPackageOptions& build_package_options)
+ : src(src), triplet(triplet), port_dir(std::move(port_dir)), build_package_options(build_package_options)
{
}
const SourceParagraph& src;
const Triplet& triplet;
fs::path port_dir;
-
- bool use_head_version;
- bool no_downloads;
+ const BuildPackageOptions& build_package_options;
};
ExtendedBuildResult build_package(const VcpkgPaths& paths,
@@ -108,10 +141,18 @@ namespace vcpkg::Build
std::map<BuildPolicy, bool> m_policies;
};
+ enum class LinkageType : char
+ {
+ DYNAMIC,
+ STATIC,
+ };
+
+ Optional<LinkageType> to_linkage_type(const std::string& str);
+
struct BuildInfo
{
- PostBuildLint::LinkageType crt_linkage;
- PostBuildLint::LinkageType library_linkage;
+ LinkageType crt_linkage;
+ LinkageType library_linkage;
Optional<std::string> version;
diff --git a/toolsrc/include/vcpkg_Commands.h b/toolsrc/include/vcpkg_Commands.h
index 14d468352..006971e47 100644
--- a/toolsrc/include/vcpkg_Commands.h
+++ b/toolsrc/include/vcpkg_Commands.h
@@ -4,6 +4,8 @@
#include "VcpkgCmdArguments.h"
#include "VcpkgPaths.h"
#include "VersionT.h"
+#include "vcpkg_Build.h"
+#include "vcpkg_Dependencies.h"
#include <array>
namespace vcpkg::Commands
@@ -48,6 +50,11 @@ namespace vcpkg::Commands
const fs::path& listfile() const;
};
+ Build::BuildResult perform_install_plan_action(const VcpkgPaths& paths,
+ const Dependencies::InstallPlanAction& action,
+ const Build::BuildPackageOptions& install_plan_options,
+ StatusParagraphs& status_db);
+
void install_files_and_write_listfile(Files::Filesystem& fs,
const fs::path& source_dir,
const InstallDir& dirs);
diff --git a/toolsrc/include/vcpkg_Util.h b/toolsrc/include/vcpkg_Util.h
index 6648302ac..1bd1bcc4a 100644
--- a/toolsrc/include/vcpkg_Util.h
+++ b/toolsrc/include/vcpkg_Util.h
@@ -34,6 +34,12 @@ namespace vcpkg::Util
cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
}
+ template<class Container, class V>
+ auto find(const Container& cont, V&& v)
+ {
+ return std::find(cont.cbegin(), cont.cend(), v);
+ }
+
template<class Container, class Pred>
auto find_if(const Container& cont, Pred pred)
{
diff --git a/toolsrc/include/vcpkg_expected.h b/toolsrc/include/vcpkg_expected.h
index 3a920022b..15dbf5e79 100644
--- a/toolsrc/include/vcpkg_expected.h
+++ b/toolsrc/include/vcpkg_expected.h
@@ -5,27 +5,63 @@
namespace vcpkg
{
- template<class T>
- class Expected
+ template<class Err>
+ struct ErrorHolder
{
- public:
- // Constructors are intentionally implicit
- Expected(const std::error_code& ec) : m_error_code(ec), m_t() {}
+ ErrorHolder() : m_is_error(false) {}
+ ErrorHolder(const Err& err) : m_is_error(true), m_err(err) {}
+ ErrorHolder(Err&& err) : m_is_error(true), m_err(std::move(err)) {}
+
+ constexpr bool has_error() const { return m_is_error; }
+
+ const Err& error() const { return m_err; }
+ Err& error() { return m_err; }
+
+ CStringView to_string() const { return "value was error"; }
+
+ private:
+ bool m_is_error;
+ Err m_err;
+ };
+
+ template<>
+ struct ErrorHolder<std::error_code>
+ {
+ ErrorHolder() = default;
+ ErrorHolder(const std::error_code& err) : m_err(err) {}
+
+ constexpr bool has_error() const { return bool(m_err); }
- Expected(std::errc ec) : Expected(std::make_error_code(ec)) {}
+ const std::error_code& error() const { return m_err; }
+ std::error_code& error() { return m_err; }
- Expected(const T& t) : m_error_code(), m_t(t) {}
+ CStringView to_string() const { return "value was error"; }
- Expected(T&& t) : m_error_code(), m_t(std::move(t)) {}
+ private:
+ std::error_code m_err;
+ };
+
+ template<class T, class S>
+ class ExpectedT
+ {
+ public:
+ constexpr ExpectedT() = default;
+
+ // Constructors are intentionally implicit
+
+ ExpectedT(const S& s) : m_s(s) {}
+ ExpectedT(S&& s) : m_s(std::move(s)) {}
- Expected() : Expected(std::error_code(), T()) {}
+ ExpectedT(const T& t) : m_t(t) {}
+ ExpectedT(T&& t) : m_t(std::move(t)) {}
- Expected(const Expected&) = default;
- Expected(Expected&&) = default;
- Expected& operator=(const Expected&) = default;
- Expected& operator=(Expected&&) = default;
+ ExpectedT(const ExpectedT&) = default;
+ ExpectedT(ExpectedT&&) = default;
+ ExpectedT& operator=(const ExpectedT&) = default;
+ ExpectedT& operator=(ExpectedT&&) = default;
- std::error_code error_code() const { return this->m_error_code; }
+ explicit constexpr operator bool() const noexcept { return !m_s.has_error(); }
+ constexpr bool has_value() const noexcept { return !m_s.has_error(); }
T&& value_or_exit(const LineInfo& line_info) &&
{
@@ -39,9 +75,13 @@ namespace vcpkg
return this->m_t;
}
+ const S& error() const & { return this->m_s.error(); }
+
+ S&& error() && { return std::move(this->m_s.error()); }
+
const T* get() const
{
- if (m_error_code)
+ if (!this->has_value())
{
return nullptr;
}
@@ -50,7 +90,7 @@ namespace vcpkg
T* get()
{
- if (m_error_code)
+ if (!this->has_value())
{
return nullptr;
}
@@ -60,10 +100,13 @@ namespace vcpkg
private:
void exit_if_error(const LineInfo& line_info) const
{
- Checks::check_exit(line_info, !this->m_error_code, this->m_error_code.message());
+ Checks::check_exit(line_info, !m_s.has_error(), m_s.to_string());
}
- std::error_code m_error_code;
+ ErrorHolder<S> m_s;
T m_t;
};
+
+ template<class T>
+ using Expected = ExpectedT<T, std::error_code>;
}
diff --git a/toolsrc/src/BinaryParagraph.cpp b/toolsrc/src/BinaryParagraph.cpp
index d545eee2a..21980cd7d 100644
--- a/toolsrc/src/BinaryParagraph.cpp
+++ b/toolsrc/src/BinaryParagraph.cpp
@@ -42,7 +42,7 @@ namespace vcpkg
Checks::check_exit(VCPKG_LINE_INFO, multi_arch == "same", "Multi-Arch must be 'same' but was %s", multi_arch);
std::string deps = details::remove_optional_field(&fields, BinaryParagraphOptionalField::DEPENDS);
- this->depends = parse_depends(deps);
+ this->depends = parse_comma_list(deps);
}
BinaryParagraph::BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet)
diff --git a/toolsrc/src/PackageSpec.cpp b/toolsrc/src/PackageSpec.cpp
index 69883a030..ab005f255 100644
--- a/toolsrc/src/PackageSpec.cpp
+++ b/toolsrc/src/PackageSpec.cpp
@@ -7,7 +7,8 @@ namespace vcpkg
{
static bool is_valid_package_spec_char(char c) { return (c == '-') || isdigit(c) || (isalpha(c) && islower(c)); }
- Expected<PackageSpec> PackageSpec::from_string(const std::string& spec_as_string, const Triplet& default_triplet)
+ ExpectedT<PackageSpec, PackageSpecParseResult> PackageSpec::from_string(const std::string& spec_as_string,
+ const Triplet& default_triplet)
{
auto pos = spec_as_string.find(':');
if (pos == std::string::npos)
@@ -18,7 +19,7 @@ namespace vcpkg
auto pos2 = spec_as_string.find(':', pos + 1);
if (pos2 != std::string::npos)
{
- return std::error_code(PackageSpecParseResult::TOO_MANY_COLONS);
+ return PackageSpecParseResult::TOO_MANY_COLONS;
}
const std::string name = spec_as_string.substr(0, pos);
@@ -26,11 +27,12 @@ namespace vcpkg
return from_name_and_triplet(name, triplet);
}
- Expected<PackageSpec> PackageSpec::from_name_and_triplet(const std::string& name, const Triplet& triplet)
+ ExpectedT<PackageSpec, PackageSpecParseResult> PackageSpec::from_name_and_triplet(const std::string& name,
+ const Triplet& triplet)
{
if (Util::find_if_not(name, is_valid_package_spec_char) != name.end())
{
- return std::error_code(PackageSpecParseResult::INVALID_CHARACTERS);
+ return PackageSpecParseResult::INVALID_CHARACTERS;
}
PackageSpec p;
diff --git a/toolsrc/src/PackageSpecParseResult.cpp b/toolsrc/src/PackageSpecParseResult.cpp
index 487c3aa1d..838c788ba 100644
--- a/toolsrc/src/PackageSpecParseResult.cpp
+++ b/toolsrc/src/PackageSpecParseResult.cpp
@@ -5,11 +5,9 @@
namespace vcpkg
{
- const char* PackageSpecParseResultCategoryImpl::name() const noexcept { return "PackageSpecParseResult"; }
-
- std::string PackageSpecParseResultCategoryImpl::message(int ev) const noexcept
+ CStringView to_string(PackageSpecParseResult ev) noexcept
{
- switch (static_cast<PackageSpecParseResult>(ev))
+ switch (ev)
{
case PackageSpecParseResult::SUCCESS: return "OK";
case PackageSpecParseResult::TOO_MANY_COLONS: return "Too many colons";
@@ -19,22 +17,4 @@ namespace vcpkg
default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
-
- const std::error_category& package_spec_parse_result_category()
- {
- static PackageSpecParseResultCategoryImpl instance;
- return instance;
- }
-
- std::error_code make_error_code(PackageSpecParseResult e)
- {
- return std::error_code(static_cast<int>(e), package_spec_parse_result_category());
- }
-
- PackageSpecParseResult to_package_spec_parse_result(int i) { return static_cast<PackageSpecParseResult>(i); }
-
- PackageSpecParseResult to_package_spec_parse_result(std::error_code ec)
- {
- return to_package_spec_parse_result(ec.value());
- }
}
diff --git a/toolsrc/src/Paragraphs.cpp b/toolsrc/src/Paragraphs.cpp
index 70d3db2b3..13103d1f8 100644
--- a/toolsrc/src/Paragraphs.cpp
+++ b/toolsrc/src/Paragraphs.cpp
@@ -168,7 +168,7 @@ namespace vcpkg::Paragraphs
return parse_single_paragraph(*spgh);
}
- return contents.error_code();
+ return contents.error();
}
Expected<std::vector<std::unordered_map<std::string, std::string>>> get_paragraphs(const Files::Filesystem& fs,
@@ -180,7 +180,7 @@ namespace vcpkg::Paragraphs
return parse_paragraphs(*spgh);
}
- return contents.error_code();
+ return contents.error();
}
Expected<std::unordered_map<std::string, std::string>> parse_single_paragraph(const std::string& str)
@@ -201,15 +201,16 @@ namespace vcpkg::Paragraphs
return Parser(str.c_str(), str.c_str() + str.size()).get_paragraphs();
}
- Expected<SourceParagraph> try_load_port(const Files::Filesystem& fs, const fs::path& path)
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> try_load_port(const Files::Filesystem& fs, const fs::path& path)
{
+ ParseControlErrorInfo error_info;
Expected<std::unordered_map<std::string, std::string>> pghs = get_single_paragraph(fs, path / "CONTROL");
if (auto p = pghs.get())
{
- return SourceParagraph(*p);
+ return SourceParagraph::parse_control_file(*p);
}
-
- return pghs.error_code();
+ error_info.error = pghs.error();
+ return error_info;
}
Expected<BinaryParagraph> try_load_cached_package(const VcpkgPaths& paths, const PackageSpec& spec)
@@ -222,20 +223,26 @@ namespace vcpkg::Paragraphs
return BinaryParagraph(*p);
}
- return pghs.error_code();
+ return pghs.error();
}
std::vector<SourceParagraph> load_all_ports(const Files::Filesystem& fs, const fs::path& ports_dir)
{
std::vector<SourceParagraph> output;
+ std::vector<ParseControlErrorInfo> port_errors;
for (auto&& path : fs.get_files_non_recursive(ports_dir))
{
- Expected<SourceParagraph> source_paragraph = try_load_port(fs, path);
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> source_paragraph = try_load_port(fs, path);
if (auto srcpgh = source_paragraph.get())
{
output.emplace_back(std::move(*srcpgh));
}
+ else
+ {
+ port_errors.emplace_back(source_paragraph.error());
+ }
}
+ print_error_message(port_errors);
return output;
}
diff --git a/toolsrc/src/PostBuildLint.cpp b/toolsrc/src/PostBuildLint.cpp
index bcad27032..82d50a68f 100644
--- a/toolsrc/src/PostBuildLint.cpp
+++ b/toolsrc/src/PostBuildLint.cpp
@@ -733,7 +733,7 @@ namespace vcpkg::PostBuildLint
const auto& fs = paths.get_filesystem();
// for dumpbin
- const Toolset& toolset = paths.get_toolset();
+ const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset);
const fs::path package_dir = paths.package_dir(spec);
size_t error_count = 0;
@@ -777,7 +777,7 @@ namespace vcpkg::PostBuildLint
switch (build_info.library_linkage)
{
- case LinkageType::BackingEnum::DYNAMIC:
+ case Build::LinkageType::DYNAMIC:
{
std::vector<fs::path> debug_dlls = fs.get_files_recursive(debug_bin_dir);
Util::unstable_keep_if(debug_dlls, has_extension_pred(fs, ".dll"));
@@ -802,7 +802,7 @@ namespace vcpkg::PostBuildLint
error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin, build_info);
break;
}
- case LinkageType::BackingEnum::STATIC:
+ case Build::LinkageType::STATIC:
{
std::vector<fs::path> dlls = fs.get_files_recursive(package_dir);
Util::unstable_keep_if(dlls, has_extension_pred(fs, ".dll"));
@@ -812,18 +812,17 @@ namespace vcpkg::PostBuildLint
if (!build_info.policies.is_enabled(BuildPolicy::ONLY_RELEASE_CRT))
{
- error_count += check_crt_linkage_of_libs(
- BuildType::value_of(ConfigurationTypeC::DEBUG, build_info.crt_linkage),
- debug_libs,
- toolset.dumpbin);
+ error_count +=
+ check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage),
+ debug_libs,
+ toolset.dumpbin);
}
error_count +=
- check_crt_linkage_of_libs(BuildType::value_of(ConfigurationTypeC::RELEASE, build_info.crt_linkage),
+ check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage),
release_libs,
toolset.dumpbin);
break;
}
- case LinkageType::BackingEnum::NULLVALUE:
default: Checks::unreachable(VCPKG_LINE_INFO);
}
diff --git a/toolsrc/src/PostBuildLint_BuildType.cpp b/toolsrc/src/PostBuildLint_BuildType.cpp
index e690036d2..649f0ccca 100644
--- a/toolsrc/src/PostBuildLint_BuildType.cpp
+++ b/toolsrc/src/PostBuildLint_BuildType.cpp
@@ -5,24 +5,24 @@
namespace vcpkg::PostBuildLint
{
- BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage)
+ BuildType BuildType::value_of(const ConfigurationType& config, const Build::LinkageType& linkage)
{
- if (config == ConfigurationTypeC::DEBUG && linkage == LinkageTypeC::STATIC)
+ if (config == ConfigurationType::DEBUG && linkage == Build::LinkageType::STATIC)
{
return BuildTypeC::DEBUG_STATIC;
}
- if (config == ConfigurationTypeC::DEBUG && linkage == LinkageTypeC::DYNAMIC)
+ if (config == ConfigurationType::DEBUG && linkage == Build::LinkageType::DYNAMIC)
{
return BuildTypeC::DEBUG_DYNAMIC;
}
- if (config == ConfigurationTypeC::RELEASE && linkage == LinkageTypeC::STATIC)
+ if (config == ConfigurationType::RELEASE && linkage == Build::LinkageType::STATIC)
{
return BuildTypeC::RELEASE_STATIC;
}
- if (config == ConfigurationTypeC::RELEASE && linkage == LinkageTypeC::DYNAMIC)
+ if (config == ConfigurationType::RELEASE && linkage == Build::LinkageType::DYNAMIC)
{
return BuildTypeC::RELEASE_DYNAMIC;
}
@@ -32,7 +32,7 @@ namespace vcpkg::PostBuildLint
const ConfigurationType& BuildType::config() const { return this->m_config; }
- const LinkageType& BuildType::linkage() const { return this->m_linkage; }
+ const Build::LinkageType& BuildType::linkage() const { return this->m_linkage; }
const std::regex& BuildType::crt_regex() const
{
diff --git a/toolsrc/src/PostBuildLint_ConfigurationType.cpp b/toolsrc/src/PostBuildLint_ConfigurationType.cpp
deleted file mode 100644
index eeccb1804..000000000
--- a/toolsrc/src/PostBuildLint_ConfigurationType.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "pch.h"
-
-#include "PackageSpec.h"
-#include "PostBuildLint_ConfigurationType.h"
-#include "vcpkg_Enums.h"
-
-namespace vcpkg::PostBuildLint
-{
- static const std::string NULLVALUE_STRING = Enums::nullvalue_to_string(ConfigurationTypeC::ENUM_NAME);
-
- static const std::string NAME_DEBUG = "Debug";
- static const std::string NAME_RELEASE = "Release";
-
- const std::string& ConfigurationType::to_string() const
- {
- switch (this->backing_enum)
- {
- case ConfigurationTypeC::DEBUG: return NAME_DEBUG;
- case ConfigurationTypeC::RELEASE: return NAME_RELEASE;
- case ConfigurationTypeC::NULLVALUE: return NULLVALUE_STRING;
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
-}
diff --git a/toolsrc/src/PostBuildLint_LinkageType.cpp b/toolsrc/src/PostBuildLint_LinkageType.cpp
deleted file mode 100644
index 43bdbed7b..000000000
--- a/toolsrc/src/PostBuildLint_LinkageType.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "pch.h"
-
-#include "PostBuildLint_LinkageType.h"
-#include "vcpkg_Checks.h"
-#include "vcpkg_Enums.h"
-
-namespace vcpkg::PostBuildLint
-{
- static const std::string NULLVALUE_STRING = Enums::nullvalue_to_string(LinkageTypeC::ENUM_NAME);
-
- static const std::string NAME_DYNAMIC = "dynamic";
- static const std::string NAME_STATIC = "static";
-
- LinkageType LinkageType::value_of(const std::string& as_string)
- {
- if (as_string == NAME_DYNAMIC)
- {
- return LinkageTypeC::DYNAMIC;
- }
-
- if (as_string == NAME_STATIC)
- {
- return LinkageTypeC::STATIC;
- }
-
- return LinkageTypeC::NULLVALUE;
- }
-
- const std::string& LinkageType::to_string() const
- {
- switch (this->backing_enum)
- {
- case LinkageTypeC::DYNAMIC: return NAME_DYNAMIC;
- case LinkageTypeC::STATIC: return NAME_STATIC;
- case LinkageTypeC::NULLVALUE: return NULLVALUE_STRING;
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
-}
diff --git a/toolsrc/src/SourceParagraph.cpp b/toolsrc/src/SourceParagraph.cpp
index d140ce72b..2508af1e8 100644
--- a/toolsrc/src/SourceParagraph.cpp
+++ b/toolsrc/src/SourceParagraph.cpp
@@ -5,6 +5,9 @@
#include "vcpkg_Checks.h"
#include "vcpkg_Maps.h"
#include "vcpkg_System.h"
+#include "vcpkg_Util.h"
+#include "vcpkg_expected.h"
+
#include "vcpkglib_helpers.h"
namespace vcpkg
@@ -21,6 +24,7 @@ namespace vcpkg
static const std::string DESCRIPTION = "Description";
static const std::string MAINTAINER = "Maintainer";
static const std::string BUILD_DEPENDS = "Build-Depends";
+ static const std::string SUPPORTS = "Supports";
}
static const std::vector<std::string>& get_list_of_valid_fields()
@@ -30,22 +34,51 @@ namespace vcpkg
SourceParagraphOptionalField::DESCRIPTION,
SourceParagraphOptionalField::MAINTAINER,
- SourceParagraphOptionalField::BUILD_DEPENDS};
+ SourceParagraphOptionalField::BUILD_DEPENDS,
+ SourceParagraphOptionalField::SUPPORTS};
return valid_fields;
}
- SourceParagraph::SourceParagraph() = default;
+ void print_error_message(const ParseControlErrorInfo& info)
+ {
+ System::println(
+ System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", info.name);
+ System::println("The following fields were not expected:\n\n %s\n\n", info.remaining_fields_as_string);
+ System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", info.valid_fields_as_string);
+ System::println("Different source may be available for vcpkg. Use .\\bootstrap-vcpkg.bat to update.\n");
+ }
+
+ void print_error_message(std::vector<ParseControlErrorInfo> error_info_list)
+ {
+ if (error_info_list.size() == 0) return;
+ for (ParseControlErrorInfo error_info : error_info_list)
+ {
+ System::println(
+ System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", error_info.name);
+ System::println("The following fields were not expected:\n\n %s\n\n",
+ error_info.remaining_fields_as_string);
+ }
+
+ System::println("This is the list of valid fields (case-sensitive): \n\n %s\n",
+ error_info_list.front().valid_fields_as_string);
+ System::println("Different source may be available for vcpkg. Use .\\bootstrap-vcpkg.bat to update.\n");
+ }
- SourceParagraph::SourceParagraph(std::unordered_map<std::string, std::string> fields)
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> SourceParagraph::parse_control_file(
+ std::unordered_map<std::string, std::string> fields)
{
- this->name = details::remove_required_field(&fields, SourceParagraphRequiredField::SOURCE);
- this->version = details::remove_required_field(&fields, SourceParagraphRequiredField::VERSION);
- this->description = details::remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION);
- this->maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER);
+ SourceParagraph sparagraph;
+ sparagraph.name = details::remove_required_field(&fields, SourceParagraphRequiredField::SOURCE);
+ sparagraph.version = details::remove_required_field(&fields, SourceParagraphRequiredField::VERSION);
+ sparagraph.description = details::remove_optional_field(&fields, SourceParagraphOptionalField::DESCRIPTION);
+ sparagraph.maintainer = details::remove_optional_field(&fields, SourceParagraphOptionalField::MAINTAINER);
std::string deps = details::remove_optional_field(&fields, SourceParagraphOptionalField::BUILD_DEPENDS);
- this->depends = expand_qualified_dependencies(parse_depends(deps));
+ sparagraph.depends = expand_qualified_dependencies(parse_comma_list(deps));
+
+ std::string sups = details::remove_optional_field(&fields, SourceParagraphOptionalField::SUPPORTS);
+ sparagraph.supports = parse_comma_list(sups);
if (!fields.empty())
{
@@ -55,17 +88,14 @@ namespace vcpkg
const std::string remaining_fields_as_string = Strings::join("\n ", remaining_fields);
const std::string valid_fields_as_string = Strings::join("\n ", valid_fields);
- System::println(
- System::Color::error, "Error: There are invalid fields in the Source Paragraph of %s", this->name);
- System::println("The following fields were not expected:\n\n %s\n\n", remaining_fields_as_string);
- System::println("This is the list of valid fields (case-sensitive): \n\n %s\n", valid_fields_as_string);
- Checks::exit_fail(VCPKG_LINE_INFO);
+ return ParseControlErrorInfo{sparagraph.name, remaining_fields_as_string, valid_fields_as_string};
}
+ return sparagraph;
}
std::vector<Dependency> vcpkg::expand_qualified_dependencies(const std::vector<std::string>& depends)
{
- auto convert = [&](const std::string& depend_string) -> Dependency {
+ return Util::fmap(depends, [&](const std::string& depend_string) -> Dependency {
auto pos = depend_string.find(' ');
if (pos == std::string::npos) return {depend_string, ""};
// expect of the form "\w+ \[\w+\]"
@@ -78,21 +108,12 @@ namespace vcpkg
}
dep.qualifier = depend_string.substr(pos + 2, depend_string.size() - pos - 3);
return dep;
- };
-
- std::vector<vcpkg::Dependency> ret;
-
- for (auto&& depend_string : depends)
- {
- ret.push_back(convert(depend_string));
- }
-
- return ret;
+ });
}
- std::vector<std::string> parse_depends(const std::string& depends_string)
+ std::vector<std::string> parse_comma_list(const std::string& str)
{
- if (depends_string.empty())
+ if (str.empty())
{
return {};
}
@@ -102,17 +123,17 @@ namespace vcpkg
size_t cur = 0;
do
{
- auto pos = depends_string.find(',', cur);
+ auto pos = str.find(',', cur);
if (pos == std::string::npos)
{
- out.push_back(depends_string.substr(cur));
+ out.push_back(str.substr(cur));
break;
}
- out.push_back(depends_string.substr(cur, pos - cur));
+ out.push_back(str.substr(cur, pos - cur));
// skip comma and space
++pos;
- if (depends_string[pos] == ' ')
+ if (str[pos] == ' ')
{
++pos;
}
@@ -137,4 +158,49 @@ namespace vcpkg
}
const std::string& to_string(const Dependency& dep) { return dep.name; }
+
+ ExpectedT<Supports, std::vector<std::string>> Supports::parse(const std::vector<std::string>& strs)
+ {
+ Supports ret;
+ std::vector<std::string> unrecognized;
+
+ for (auto&& str : strs)
+ {
+ if (str == "x64")
+ ret.architectures.push_back(Architecture::X64);
+ else if (str == "x86")
+ ret.architectures.push_back(Architecture::X86);
+ else if (str == "arm")
+ ret.architectures.push_back(Architecture::ARM);
+ else if (str == "windows")
+ ret.platforms.push_back(Platform::WINDOWS);
+ else if (str == "uwp")
+ ret.platforms.push_back(Platform::UWP);
+ else if (str == "v140")
+ ret.toolsets.push_back(ToolsetVersion::V140);
+ else if (str == "v141")
+ ret.toolsets.push_back(ToolsetVersion::V141);
+ else if (str == "crt-static")
+ ret.crt_linkages.push_back(Linkage::STATIC);
+ else if (str == "crt-dynamic")
+ ret.crt_linkages.push_back(Linkage::DYNAMIC);
+ else
+ unrecognized.push_back(str);
+ }
+
+ if (unrecognized.empty())
+ return std::move(ret);
+ else
+ return std::move(unrecognized);
+ }
+
+ bool Supports::supports(Architecture arch, Platform plat, Linkage crt, ToolsetVersion tools)
+ {
+ auto is_in_or_empty = [](auto v, auto&& c) -> bool { return c.empty() || c.end() != Util::find(c, v); };
+ if (!is_in_or_empty(arch, architectures)) return false;
+ if (!is_in_or_empty(plat, platforms)) return false;
+ if (!is_in_or_empty(crt, crt_linkages)) return false;
+ if (!is_in_or_empty(tools, toolsets)) return false;
+ return true;
+ }
}
diff --git a/toolsrc/src/VcpkgPaths.cpp b/toolsrc/src/VcpkgPaths.cpp
index 3dd32de01..9068e3903 100644
--- a/toolsrc/src/VcpkgPaths.cpp
+++ b/toolsrc/src/VcpkgPaths.cpp
@@ -269,7 +269,7 @@ namespace vcpkg
return nullopt;
}
- static Toolset find_toolset_instance(const VcpkgPaths& paths)
+ static std::vector<Toolset> find_toolset_instances(const VcpkgPaths& paths)
{
const auto& fs = paths.get_filesystem();
@@ -277,7 +277,28 @@ namespace vcpkg
// Note: this will contain a mix of vcvarsall.bat locations and dumpbin.exe locations.
std::vector<fs::path> paths_examined;
+ std::vector<Toolset> found_toolsets;
+
+ // VS2015
+ const Optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance();
+ if (auto v = vs_2015_installation_instance.get())
+ {
+ const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat";
+
+ paths_examined.push_back(vs2015_vcvarsall_bat);
+ if (fs.exists(vs2015_vcvarsall_bat))
+ {
+ const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
+ paths_examined.push_back(vs2015_dumpbin_exe);
+ if (fs.exists(vs2015_dumpbin_exe))
+ {
+ found_toolsets.push_back({vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"});
+ }
+ }
+ }
+
// VS2017
+ Optional<Toolset> vs2017_toolset;
for (const fs::path& instance : vs2017_installation_instances)
{
const fs::path vc_dir = instance / "VC";
@@ -303,41 +324,50 @@ namespace vcpkg
paths_examined.push_back(dumpbin_path);
if (fs.exists(dumpbin_path))
{
- return {dumpbin_path, vcvarsall_bat, L"v141"};
+ vs2017_toolset = Toolset{dumpbin_path, vcvarsall_bat, L"v141"};
+ break;
}
}
+ if (auto value = vs2017_toolset.get())
+ {
+ found_toolsets.push_back(*value);
+ break;
+ }
}
- // VS2015
- const Optional<fs::path> vs_2015_installation_instance = get_VS2015_installation_instance();
- if (auto v = vs_2015_installation_instance.get())
+ if (found_toolsets.empty())
{
- const fs::path vs2015_vcvarsall_bat = *v / "VC" / "vcvarsall.bat";
-
- paths_examined.push_back(vs2015_vcvarsall_bat);
- if (fs.exists(vs2015_vcvarsall_bat))
+ System::println(System::Color::error, "Could not locate a complete toolset.");
+ System::println("The following paths were examined:");
+ for (const fs::path& path : paths_examined)
{
- const fs::path vs2015_dumpbin_exe = *v / "VC" / "bin" / "dumpbin.exe";
- paths_examined.push_back(vs2015_dumpbin_exe);
- if (fs.exists(vs2015_dumpbin_exe))
- {
- return {vs2015_dumpbin_exe, vs2015_vcvarsall_bat, L"v140"};
- }
+ System::println(" %s", path.u8string());
}
+ Checks::exit_fail(VCPKG_LINE_INFO);
}
- System::println(System::Color::error, "Could not locate a complete toolset.");
- System::println("The following paths were examined:");
- for (const fs::path& path : paths_examined)
- {
- System::println(" %s", path.u8string());
- }
- Checks::exit_fail(VCPKG_LINE_INFO);
+ return found_toolsets;
}
- const Toolset& VcpkgPaths::get_toolset() const
+ const Toolset& VcpkgPaths::get_toolset(const std::string& toolset_version) const
{
- return this->toolset.get_lazy([this]() { return find_toolset_instance(*this); });
+ // Invariant: toolsets are non-empty and sorted with newest at back()
+ const auto& vs_toolsets = this->toolsets.get_lazy([this]() { return find_toolset_instances(*this); });
+
+ if (toolset_version.empty())
+ {
+ return vs_toolsets.back();
+ }
+ else
+ {
+ const auto toolset = Util::find_if(vs_toolsets, [&](const Toolset& toolset) {
+ return toolset_version == Strings::to_utf8(toolset.version);
+ });
+ Checks::check_exit(
+ VCPKG_LINE_INFO, toolset != vs_toolsets.end(), "Could not find toolset '%s'", toolset_version);
+ return *toolset;
+ }
}
+
Files::Filesystem& VcpkgPaths::get_filesystem() const { return Files::get_real_filesystem(); }
}
diff --git a/toolsrc/src/commands_build.cpp b/toolsrc/src/commands_build.cpp
index ec6586fa3..5a5cd462e 100644
--- a/toolsrc/src/commands_build.cpp
+++ b/toolsrc/src/commands_build.cpp
@@ -33,13 +33,16 @@ namespace vcpkg::Commands::BuildCommand
Checks::exit_success(VCPKG_LINE_INFO);
}
- const Expected<SourceParagraph> maybe_spgh = Paragraphs::try_load_port(paths.get_filesystem(), port_dir);
- Checks::check_exit(VCPKG_LINE_INFO,
- !maybe_spgh.error_code(),
- "Could not find package %s: %s",
- spec,
- maybe_spgh.error_code().message());
- const SourceParagraph& spgh = *maybe_spgh.get();
+ const ExpectedT<SourceParagraph, ParseControlErrorInfo> maybe_spgh =
+ Paragraphs::try_load_port(paths.get_filesystem(), port_dir);
+
+ if (!maybe_spgh)
+ {
+ print_error_message(maybe_spgh.error());
+ Checks::exit_fail(VCPKG_LINE_INFO);
+ }
+
+ const SourceParagraph& spgh = maybe_spgh.value_or_exit(VCPKG_LINE_INFO);
Checks::check_exit(VCPKG_LINE_INFO,
spec.name() == spgh.name,
"The Name: field inside the CONTROL does not match the port directory: '%s' != '%s'",
@@ -47,9 +50,8 @@ namespace vcpkg::Commands::BuildCommand
spec.name());
StatusParagraphs status_db = database_load_check(paths);
- const Build::BuildPackageConfig build_config{
- spgh, spec.triplet(), paths.port_dir(spec),
- };
+ Build::BuildPackageOptions build_package_options{Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
+ const Build::BuildPackageConfig build_config{spgh, spec.triplet(), paths.port_dir(spec), build_package_options};
const auto result = Build::build_package(paths, build_config, status_db);
if (result.code == BuildResult::CASCADED_DUE_TO_MISSING_DEPENDENCIES)
{
diff --git a/toolsrc/src/commands_ci.cpp b/toolsrc/src/commands_ci.cpp
index e9755335c..bad1286f0 100644
--- a/toolsrc/src/commands_ci.cpp
+++ b/toolsrc/src/commands_ci.cpp
@@ -50,6 +50,8 @@ namespace vcpkg::Commands::CI
const ElapsedTime timer = ElapsedTime::create_started();
size_t counter = 0;
const size_t package_count = install_plan.size();
+ const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO, Build::AllowDownloads::YES};
+
for (const InstallPlanAction& action : install_plan)
{
const ElapsedTime build_timer = ElapsedTime::create_started();
@@ -60,55 +62,10 @@ namespace vcpkg::Commands::CI
timing.push_back("0");
results.push_back(BuildResult::NULLVALUE);
- try
- {
- switch (action.plan_type)
- {
- case InstallPlanType::ALREADY_INSTALLED:
- results.back() = BuildResult::SUCCEEDED;
- System::println(System::Color::success, "Package %s is already installed", display_name);
- break;
- case InstallPlanType::BUILD_AND_INSTALL:
- {
- System::println("Building package %s... ", display_name);
- auto&& source_paragraph = action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO);
- const Build::BuildPackageConfig build_config{
- source_paragraph, action.spec.triplet(), paths.port_dir(action.spec),
- };
- const auto result_ex = Build::build_package(paths, build_config, status_db);
- const auto result = result_ex.code;
-
- timing.back() = build_timer.to_string();
- results.back() = result;
- if (result != BuildResult::SUCCEEDED)
- {
- System::println(System::Color::error, Build::create_error_message(result, action.spec));
- continue;
- }
- System::println(System::Color::success, "Building package %s... done", display_name);
-
- const BinaryParagraph bpgh =
- Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name);
- Install::install_package(paths, bpgh, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- }
- case InstallPlanType::INSTALL:
- results.back() = BuildResult::SUCCEEDED;
- System::println("Installing package %s... ", display_name);
- Install::install_package(
- paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
- catch (const std::exception& e)
- {
- System::println(System::Color::error, "Error: Could not install package %s: %s", action.spec, e.what());
- results.back() = BuildResult::NULLVALUE;
- }
+ const BuildResult result =
+ Install::perform_install_plan_action(paths, action, install_plan_options, status_db);
+ timing.back() = build_timer.to_string();
+ results.back() = result;
System::println("Elapsed time for package %s: %s", action.spec, build_timer.to_string());
}
diff --git a/toolsrc/src/commands_env.cpp b/toolsrc/src/commands_env.cpp
index 5e1ecc5e7..dd7172b89 100644
--- a/toolsrc/src/commands_env.cpp
+++ b/toolsrc/src/commands_env.cpp
@@ -13,7 +13,7 @@ namespace vcpkg::Commands::Env
args.check_and_get_optional_command_arguments({});
auto pre_build_info = Build::PreBuildInfo::from_triplet_file(paths, default_triplet);
- System::cmd_execute_clean(Build::make_build_env_cmd(pre_build_info, paths.get_toolset()) + L" && cmd");
+ System::cmd_execute_clean(Build::make_build_env_cmd(pre_build_info, paths.get_toolset(pre_build_info.platform_toolset)) + L" && cmd");
Checks::exit_success(VCPKG_LINE_INFO);
}
diff --git a/toolsrc/src/commands_install.cpp b/toolsrc/src/commands_install.cpp
index bebe6a3a2..73b3e9eab 100644
--- a/toolsrc/src/commands_install.cpp
+++ b/toolsrc/src/commands_install.cpp
@@ -263,6 +263,77 @@ namespace vcpkg::Commands::Install
status_db->insert(std::make_unique<StatusParagraph>(source_paragraph));
}
+ using Build::BuildResult;
+
+ BuildResult perform_install_plan_action(const VcpkgPaths& paths,
+ const InstallPlanAction& action,
+ const Build::BuildPackageOptions& build_package_options,
+ StatusParagraphs& status_db)
+ {
+ const InstallPlanType& plan_type = action.plan_type;
+ const std::string display_name = action.spec.to_string();
+
+ const bool is_user_requested = action.request_type == RequestType::USER_REQUESTED;
+ const bool use_head_version = to_bool(build_package_options.use_head_version);
+
+ if (plan_type == InstallPlanType::ALREADY_INSTALLED)
+ {
+ if (use_head_version && is_user_requested)
+ {
+ System::println(
+ System::Color::warning, "Package %s is already installed -- not building from HEAD", display_name);
+ }
+ else
+ {
+ System::println(System::Color::success, "Package %s is already installed", display_name);
+ }
+ return BuildResult::SUCCEEDED;
+ }
+
+ if (plan_type == InstallPlanType::BUILD_AND_INSTALL)
+ {
+ if (use_head_version)
+ System::println("Building package %s from HEAD... ", display_name);
+ else
+ System::println("Building package %s... ", display_name);
+
+ const Build::BuildPackageConfig build_config{
+ action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
+ action.spec.triplet(),
+ paths.port_dir(action.spec),
+ build_package_options};
+ const auto result = Build::build_package(paths, build_config, status_db);
+ if (result.code != Build::BuildResult::SUCCEEDED)
+ {
+ System::println(System::Color::error, Build::create_error_message(result.code, action.spec));
+ return result.code;
+ }
+ System::println("Building package %s... done", display_name);
+
+ const BinaryParagraph bpgh =
+ Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
+ System::println("Installing package %s... ", display_name);
+ install_package(paths, bpgh, &status_db);
+ System::println(System::Color::success, "Installing package %s... done", display_name);
+ return BuildResult::SUCCEEDED;
+ }
+
+ if (plan_type == InstallPlanType::INSTALL)
+ {
+ if (use_head_version && is_user_requested)
+ {
+ System::println(
+ System::Color::warning, "Package %s is already built -- not building from HEAD", display_name);
+ }
+ System::println("Installing package %s... ", display_name);
+ install_package(paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
+ System::println(System::Color::success, "Installing package %s... done", display_name);
+ return BuildResult::SUCCEEDED;
+ }
+
+ Checks::unreachable(VCPKG_LINE_INFO);
+ }
+
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_DRY_RUN = "--dry-run";
@@ -315,80 +386,16 @@ namespace vcpkg::Commands::Install
Checks::exit_success(VCPKG_LINE_INFO);
}
+ const Build::BuildPackageOptions install_plan_options = {Build::to_use_head_version(use_head_version),
+ Build::to_allow_downloads(!no_downloads)};
+
// execute the plan
for (const InstallPlanAction& action : install_plan)
{
- const std::string display_name = action.spec.to_string();
-
- try
- {
- switch (action.plan_type)
- {
- case InstallPlanType::ALREADY_INSTALLED:
- if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
- {
- System::println(System::Color::warning,
- "Package %s is already installed -- not building from HEAD",
- display_name);
- }
- else
- {
- System::println(System::Color::success, "Package %s is already installed", display_name);
- }
- break;
- case InstallPlanType::BUILD_AND_INSTALL:
- {
- Build::BuildPackageConfig build_config{
- action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
- action.spec.triplet(),
- paths.port_dir(action.spec),
- };
-
- build_config.use_head_version =
- use_head_version && action.request_type == RequestType::USER_REQUESTED;
- build_config.no_downloads = no_downloads;
-
- if (build_config.use_head_version)
- System::println("Building package %s from HEAD... ", display_name);
- else
- System::println("Building package %s... ", display_name);
-
- const auto result = Build::build_package(paths, build_config, status_db);
- if (result.code != Build::BuildResult::SUCCEEDED)
- {
- System::println(System::Color::error,
- Build::create_error_message(result.code, action.spec));
- System::println(Build::create_user_troubleshooting_message(action.spec));
- Checks::exit_fail(VCPKG_LINE_INFO);
- }
- System::println("Building package %s... done", display_name);
-
- const BinaryParagraph bpgh =
- Paragraphs::try_load_cached_package(paths, action.spec).value_or_exit(VCPKG_LINE_INFO);
- System::println("Installing package %s... ", display_name);
- install_package(paths, bpgh, &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- }
- case InstallPlanType::INSTALL:
- if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
- {
- System::println(System::Color::warning,
- "Package %s is already built -- not building from HEAD",
- display_name);
- }
- System::println("Installing package %s... ", display_name);
- install_package(
- paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);
- System::println(System::Color::success, "Installing package %s... done", display_name);
- break;
- case InstallPlanType::UNKNOWN:
- default: Checks::unreachable(VCPKG_LINE_INFO);
- }
- }
- catch (const std::exception& e)
+ const BuildResult result = perform_install_plan_action(paths, action, install_plan_options, status_db);
+ if (result != BuildResult::SUCCEEDED)
{
- System::println(System::Color::error, "Error: Could not install package %s: %s", action.spec, e.what());
+ System::println(Build::create_user_troubleshooting_message(action.spec));
Checks::exit_fail(VCPKG_LINE_INFO);
}
}
diff --git a/toolsrc/src/tests_dependencies.cpp b/toolsrc/src/tests_dependencies.cpp
index 3aabed80e..fdf2afea8 100644
--- a/toolsrc/src/tests_dependencies.cpp
+++ b/toolsrc/src/tests_dependencies.cpp
@@ -15,7 +15,7 @@ namespace UnitTest1
{
TEST_METHOD(parse_depends_one)
{
- auto v = expand_qualified_dependencies(parse_depends("libA [windows]"));
+ auto v = expand_qualified_dependencies(parse_comma_list("libA [windows]"));
Assert::AreEqual(size_t(1), v.size());
Assert::AreEqual("libA", v[0].name.c_str());
Assert::AreEqual("windows", v[0].qualifier.c_str());
@@ -23,7 +23,7 @@ namespace UnitTest1
TEST_METHOD(filter_depends)
{
- auto deps = expand_qualified_dependencies(parse_depends("libA [windows], libB, libC [uwp]"));
+ auto deps = expand_qualified_dependencies(parse_comma_list("libA [windows], libB, libC [uwp]"));
auto v = filter_dependencies(deps, Triplet::X64_WINDOWS);
Assert::AreEqual(size_t(2), v.size());
Assert::AreEqual("libA", v[0].c_str());
@@ -35,4 +35,65 @@ namespace UnitTest1
Assert::AreEqual("libC", v2[1].c_str());
}
};
+
+ class SupportsTests : public TestClass<SupportsTests>
+ {
+ TEST_METHOD(parse_supports_all)
+ {
+ auto v = Supports::parse({
+ "x64", "x86", "arm", "windows", "uwp", "v140", "v141", "crt-static", "crt-dynamic",
+ });
+ Assert::AreNotEqual(uintptr_t(0), uintptr_t(v.get()));
+
+ Assert::IsTrue(v.get()->supports(System::CPUArchitecture::X64,
+ Supports::Platform::UWP,
+ Supports::Linkage::DYNAMIC,
+ Supports::ToolsetVersion::V140));
+ Assert::IsTrue(v.get()->supports(System::CPUArchitecture::ARM,
+ Supports::Platform::WINDOWS,
+ Supports::Linkage::STATIC,
+ Supports::ToolsetVersion::V141));
+ }
+
+ TEST_METHOD(parse_supports_invalid)
+ {
+ auto v = Supports::parse({"arm64"});
+ Assert::AreEqual(uintptr_t(0), uintptr_t(v.get()));
+ Assert::AreEqual(size_t(1), v.error().size());
+ Assert::AreEqual("arm64", v.error()[0].c_str());
+ }
+
+ TEST_METHOD(parse_supports_case_sensitive)
+ {
+ auto v = Supports::parse({"Windows"});
+ Assert::AreEqual(uintptr_t(0), uintptr_t(v.get()));
+ Assert::AreEqual(size_t(1), v.error().size());
+ Assert::AreEqual("Windows", v.error()[0].c_str());
+ }
+
+ TEST_METHOD(parse_supports_some)
+ {
+ auto v = Supports::parse({
+ "x64", "x86", "windows",
+ });
+ Assert::AreNotEqual(uintptr_t(0), uintptr_t(v.get()));
+
+ Assert::IsTrue(v.get()->supports(System::CPUArchitecture::X64,
+ Supports::Platform::WINDOWS,
+ Supports::Linkage::DYNAMIC,
+ Supports::ToolsetVersion::V140));
+ Assert::IsFalse(v.get()->supports(System::CPUArchitecture::ARM,
+ Supports::Platform::WINDOWS,
+ Supports::Linkage::DYNAMIC,
+ Supports::ToolsetVersion::V140));
+ Assert::IsFalse(v.get()->supports(System::CPUArchitecture::X64,
+ Supports::Platform::UWP,
+ Supports::Linkage::DYNAMIC,
+ Supports::ToolsetVersion::V140));
+ Assert::IsTrue(v.get()->supports(System::CPUArchitecture::X64,
+ Supports::Platform::WINDOWS,
+ Supports::Linkage::STATIC,
+ Supports::ToolsetVersion::V141));
+ }
+ };
}
diff --git a/toolsrc/src/tests_paragraph.cpp b/toolsrc/src/tests_paragraph.cpp
index b66adc816..374e4ddd1 100644
--- a/toolsrc/src/tests_paragraph.cpp
+++ b/toolsrc/src/tests_paragraph.cpp
@@ -25,7 +25,10 @@ namespace UnitTest1
{
TEST_METHOD(SourceParagraph_Construct_Minimum)
{
- vcpkg::SourceParagraph pgh({{"Source", "zlib"}, {"Version", "1.2.8"}});
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({{"Source", "zlib"}, {"Version", "1.2.8"}});
+
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
Assert::AreEqual("zlib", pgh.name.c_str());
Assert::AreEqual("1.2.8", pgh.version.c_str());
@@ -36,22 +39,34 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Construct_Maximum)
{
- vcpkg::SourceParagraph pgh({{"Source", "s"},
- {"Version", "v"},
- {"Maintainer", "m"},
- {"Description", "d"},
- {"Build-Depends", "bd"}});
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({
+ {"Source", "s"},
+ {"Version", "v"},
+ {"Maintainer", "m"},
+ {"Description", "d"},
+ {"Build-Depends", "bd"},
+ {"Supports", "x64"},
+ });
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
+
Assert::AreEqual("s", pgh.name.c_str());
Assert::AreEqual("v", pgh.version.c_str());
Assert::AreEqual("m", pgh.maintainer.c_str());
Assert::AreEqual("d", pgh.description.c_str());
Assert::AreEqual(size_t(1), pgh.depends.size());
Assert::AreEqual("bd", pgh.depends[0].name.c_str());
+ Assert::AreEqual(size_t(1), pgh.supports.size());
+ Assert::AreEqual("x64", pgh.supports[0].c_str());
}
TEST_METHOD(SourceParagraph_Two_Depends)
{
- vcpkg::SourceParagraph pgh({{"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "z, openssl"}});
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({
+ {"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "z, openssl"},
+ });
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
Assert::AreEqual(size_t(2), pgh.depends.size());
Assert::AreEqual("z", pgh.depends[0].name.c_str());
@@ -60,8 +75,11 @@ namespace UnitTest1
TEST_METHOD(SourceParagraph_Three_Depends)
{
- vcpkg::SourceParagraph pgh(
- {{"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "z, openssl, xyz"}});
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({
+ {"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "z, openssl, xyz"},
+ });
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
Assert::AreEqual(size_t(3), pgh.depends.size());
Assert::AreEqual("z", pgh.depends[0].name.c_str());
@@ -69,10 +87,27 @@ namespace UnitTest1
Assert::AreEqual("xyz", pgh.depends[2].name.c_str());
}
+ TEST_METHOD(SourceParagraph_Three_Supports)
+ {
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({
+ {"Source", "zlib"}, {"Version", "1.2.8"}, {"Supports", "x64, windows, uwp"},
+ });
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
+
+ Assert::AreEqual(size_t(3), pgh.supports.size());
+ Assert::AreEqual("x64", pgh.supports[0].c_str());
+ Assert::AreEqual("windows", pgh.supports[1].c_str());
+ Assert::AreEqual("uwp", pgh.supports[2].c_str());
+ }
+
TEST_METHOD(SourceParagraph_Construct_Qualified_Depends)
{
- vcpkg::SourceParagraph pgh(
- {{"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "libA [windows], libB [uwp]"}});
+ auto m_pgh = vcpkg::SourceParagraph::parse_control_file({
+ {"Source", "zlib"}, {"Version", "1.2.8"}, {"Build-Depends", "libA [windows], libB [uwp]"},
+ });
+ Assert::IsTrue(m_pgh.has_value());
+ auto& pgh = *m_pgh.get();
Assert::AreEqual("zlib", pgh.name.c_str());
Assert::AreEqual("1.2.8", pgh.version.c_str());
@@ -101,13 +136,15 @@ namespace UnitTest1
TEST_METHOD(BinaryParagraph_Construct_Maximum)
{
- vcpkg::BinaryParagraph pgh({{"Package", "s"},
- {"Version", "v"},
- {"Architecture", "x86-windows"},
- {"Multi-Arch", "same"},
- {"Maintainer", "m"},
- {"Description", "d"},
- {"Depends", "bd"}});
+ vcpkg::BinaryParagraph pgh({
+ {"Package", "s"},
+ {"Version", "v"},
+ {"Architecture", "x86-windows"},
+ {"Multi-Arch", "same"},
+ {"Maintainer", "m"},
+ {"Description", "d"},
+ {"Depends", "bd"},
+ });
Assert::AreEqual("s", pgh.spec.name().c_str());
Assert::AreEqual("v", pgh.version.c_str());
Assert::AreEqual("m", pgh.maintainer.c_str());
@@ -327,28 +364,26 @@ namespace UnitTest1
TEST_METHOD(package_spec_parse)
{
- vcpkg::Expected<vcpkg::PackageSpec> spec =
+ vcpkg::ExpectedT<vcpkg::PackageSpec, vcpkg::PackageSpecParseResult> spec =
vcpkg::PackageSpec::from_string("zlib", vcpkg::Triplet::X86_WINDOWS);
- Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS,
- vcpkg::to_package_spec_parse_result(spec.error_code()));
+ Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, spec.error());
Assert::AreEqual("zlib", spec.get()->name().c_str());
Assert::AreEqual(vcpkg::Triplet::X86_WINDOWS.canonical_name(), spec.get()->triplet().canonical_name());
}
TEST_METHOD(package_spec_parse_with_arch)
{
- vcpkg::Expected<vcpkg::PackageSpec> spec =
+ vcpkg::ExpectedT<vcpkg::PackageSpec, vcpkg::PackageSpecParseResult> spec =
vcpkg::PackageSpec::from_string("zlib:x64-uwp", vcpkg::Triplet::X86_WINDOWS);
- Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS,
- vcpkg::to_package_spec_parse_result(spec.error_code()));
+ Assert::AreEqual(vcpkg::PackageSpecParseResult::SUCCESS, spec.error());
Assert::AreEqual("zlib", spec.get()->name().c_str());
Assert::AreEqual(vcpkg::Triplet::X64_UWP.canonical_name(), spec.get()->triplet().canonical_name());
}
TEST_METHOD(package_spec_parse_with_multiple_colon)
{
- auto ec = vcpkg::PackageSpec::from_string("zlib:x86-uwp:", vcpkg::Triplet::X86_WINDOWS).error_code();
- Assert::AreEqual(vcpkg::PackageSpecParseResult::TOO_MANY_COLONS, vcpkg::to_package_spec_parse_result(ec));
+ auto ec = vcpkg::PackageSpec::from_string("zlib:x86-uwp:", vcpkg::Triplet::X86_WINDOWS).error();
+ Assert::AreEqual(vcpkg::PackageSpecParseResult::TOO_MANY_COLONS, ec);
}
TEST_METHOD(utf8_to_utf16)
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 154aefd0a..738b7b284 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -61,10 +61,10 @@ static void inner(const VcpkgCmdArguments& args)
const Expected<VcpkgPaths> expected_paths = VcpkgPaths::create(vcpkg_root_dir);
Checks::check_exit(VCPKG_LINE_INFO,
- !expected_paths.error_code(),
+ !expected_paths.error(),
"Error: Invalid vcpkg root directory %s: %s",
vcpkg_root_dir.string(),
- expected_paths.error_code().message());
+ expected_paths.error().message());
const VcpkgPaths paths = expected_paths.value_or_exit(VCPKG_LINE_INFO);
int exit_code = _wchdir(paths.root.c_str());
Checks::check_exit(VCPKG_LINE_INFO, exit_code == 0, "Changing the working dir failed");
diff --git a/toolsrc/src/vcpkg_Build.cpp b/toolsrc/src/vcpkg_Build.cpp
index d44a673fc..0ca6dc243 100644
--- a/toolsrc/src/vcpkg_Build.cpp
+++ b/toolsrc/src/vcpkg_Build.cpp
@@ -13,11 +13,15 @@
#include "vcpkglib.h"
#include "vcpkglib_helpers.h"
-using vcpkg::PostBuildLint::LinkageType;
-namespace LinkageTypeC = vcpkg::PostBuildLint::LinkageTypeC;
-
namespace vcpkg::Build
{
+ Optional<LinkageType> to_linkage_type(const std::string& str)
+ {
+ if (str == "dynamic") return LinkageType::DYNAMIC;
+ if (str == "static") return LinkageType::STATIC;
+ return nullopt;
+ }
+
namespace BuildInfoRequiredField
{
static const std::string CRT_LINKAGE = "CRTLinkage";
@@ -128,21 +132,21 @@ namespace vcpkg::Build
const fs::path& git_exe_path = paths.get_git_exe();
const fs::path ports_cmake_script_path = paths.ports_cmake;
- const Toolset& toolset = paths.get_toolset();
auto pre_build_info = PreBuildInfo::from_triplet_file(paths, triplet);
+ const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset);
const auto cmd_set_environment = make_build_env_cmd(pre_build_info, toolset);
- const std::wstring cmd_launch_cmake =
- make_cmake_cmd(cmake_exe_path,
- ports_cmake_script_path,
- {{L"CMD", L"BUILD"},
- {L"PORT", config.src.name},
- {L"CURRENT_PORT_DIR", config.port_dir / "/."},
- {L"TARGET_TRIPLET", triplet.canonical_name()},
- {L"VCPKG_PLATFORM_TOOLSET", toolset.version},
- {L"VCPKG_USE_HEAD_VERSION", config.use_head_version ? L"1" : L"0"},
- {L"_VCPKG_NO_DOWNLOADS", config.no_downloads ? L"1" : L"0"},
- {L"GIT", git_exe_path}});
+ const std::wstring cmd_launch_cmake = make_cmake_cmd(
+ cmake_exe_path,
+ ports_cmake_script_path,
+ {{L"CMD", L"BUILD"},
+ {L"PORT", config.src.name},
+ {L"CURRENT_PORT_DIR", config.port_dir / "/."},
+ {L"TARGET_TRIPLET", triplet.canonical_name()},
+ {L"VCPKG_PLATFORM_TOOLSET", toolset.version},
+ {L"VCPKG_USE_HEAD_VERSION", to_bool(config.build_package_options.use_head_version) ? L"1" : L"0"},
+ {L"_VCPKG_NO_DOWNLOADS", !to_bool(config.build_package_options.allow_downloads) ? L"1" : L"0"},
+ {L"GIT", git_exe_path}});
const std::wstring command = Strings::wformat(LR"(%s && %s)", cmd_set_environment, cmd_launch_cmake);
@@ -217,19 +221,20 @@ namespace vcpkg::Build
BuildInfo build_info;
const std::string crt_linkage_as_string =
details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE);
- build_info.crt_linkage = LinkageType::value_of(crt_linkage_as_string);
- Checks::check_exit(VCPKG_LINE_INFO,
- build_info.crt_linkage != LinkageTypeC::NULLVALUE,
- "Invalid crt linkage type: [%s]",
- crt_linkage_as_string);
+
+ auto crtlinkage = to_linkage_type(crt_linkage_as_string);
+ if (auto p = crtlinkage.get())
+ build_info.crt_linkage = *p;
+ else
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Invalid crt linkage type: [%s]", crt_linkage_as_string);
const std::string library_linkage_as_string =
details::remove_required_field(&pgh, BuildInfoRequiredField::LIBRARY_LINKAGE);
- build_info.library_linkage = LinkageType::value_of(library_linkage_as_string);
- Checks::check_exit(VCPKG_LINE_INFO,
- build_info.library_linkage != LinkageTypeC::NULLVALUE,
- "Invalid library linkage type: [%s]",
- library_linkage_as_string);
+ auto liblinkage = to_linkage_type(library_linkage_as_string);
+ if (auto p = liblinkage.get())
+ build_info.library_linkage = *p;
+ else
+ Checks::exit_with_message(VCPKG_LINE_INFO, "Invalid library linkage type: [%s]", library_linkage_as_string);
auto it_version = pgh.find("Version");
if (it_version != pgh.end())
diff --git a/toolsrc/src/vcpkg_Dependencies.cpp b/toolsrc/src/vcpkg_Dependencies.cpp
index acfb55239..ea5832e46 100644
--- a/toolsrc/src/vcpkg_Dependencies.cpp
+++ b/toolsrc/src/vcpkg_Dependencies.cpp
@@ -174,11 +174,14 @@ namespace vcpkg::Dependencies
if (auto bpgh = maybe_bpgh.get())
return InstallPlanAction{spec, {nullopt, *bpgh, nullopt}, request_type};
- Expected<SourceParagraph> maybe_spgh =
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> maybe_spgh =
Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec));
if (auto spgh = maybe_spgh.get())
return InstallPlanAction{spec, {nullopt, nullopt, *spgh}, request_type};
+ else
+ print_error_message(maybe_spgh.error());
+
Checks::exit_with_message(VCPKG_LINE_INFO, "Could not find package %s", spec);
}
};
@@ -283,11 +286,14 @@ namespace vcpkg::Dependencies
if (auto bpgh = maybe_bpgh.get())
return ExportPlanAction{spec, {nullopt, *bpgh, nullopt}, request_type};
- Expected<SourceParagraph> maybe_spgh =
+ ExpectedT<SourceParagraph, ParseControlErrorInfo> maybe_spgh =
Paragraphs::try_load_port(paths.get_filesystem(), paths.port_dir(spec));
if (auto spgh = maybe_spgh.get())
return ExportPlanAction{spec, {nullopt, nullopt, *spgh}, request_type};
+ else
+ print_error_message(maybe_spgh.error());
+
Checks::exit_with_message(VCPKG_LINE_INFO, "Could not find package %s", spec);
}
};
diff --git a/toolsrc/src/vcpkg_Files.cpp b/toolsrc/src/vcpkg_Files.cpp
index 17aa2997a..7b12ea699 100644
--- a/toolsrc/src/vcpkg_Files.cpp
+++ b/toolsrc/src/vcpkg_Files.cpp
@@ -15,7 +15,7 @@ namespace vcpkg::Files
std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary);
if (file_stream.fail())
{
- return std::errc::no_such_file_or_directory;
+ return std::make_error_code(std::errc::no_such_file_or_directory);
}
file_stream.seekg(0, file_stream.end);
@@ -24,7 +24,7 @@ namespace vcpkg::Files
if (length > SIZE_MAX)
{
- return std::errc::file_too_large;
+ return std::make_error_code(std::errc::file_too_large);
}
std::string output;
@@ -39,7 +39,7 @@ namespace vcpkg::Files
std::fstream file_stream(file_path, std::ios_base::in | std::ios_base::binary);
if (file_stream.fail())
{
- return std::errc::no_such_file_or_directory;
+ return std::make_error_code(std::errc::no_such_file_or_directory);
}
std::vector<std::string> output;
diff --git a/toolsrc/src/vcpkg_Input.cpp b/toolsrc/src/vcpkg_Input.cpp
index 7d8e4767e..df738315b 100644
--- a/toolsrc/src/vcpkg_Input.cpp
+++ b/toolsrc/src/vcpkg_Input.cpp
@@ -12,14 +12,14 @@ namespace vcpkg::Input
CStringView example_text)
{
const std::string as_lowercase = Strings::ascii_to_lowercase(package_spec_as_string);
- Expected<PackageSpec> expected_spec = PackageSpec::from_string(as_lowercase, default_triplet);
+ auto expected_spec = PackageSpec::from_string(as_lowercase, default_triplet);
if (auto spec = expected_spec.get())
{
return *spec;
}
// Intentionally show the lowercased string
- System::println(System::Color::error, "Error: %s: %s", expected_spec.error_code().message(), as_lowercase);
+ System::println(System::Color::error, "Error: %s: %s", vcpkg::to_string(expected_spec.error()), as_lowercase);
System::print(example_text);
Checks::exit_fail(VCPKG_LINE_INFO);
}
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj b/toolsrc/vcpkglib/vcpkglib.vcxproj
index 4ec37a16d..abc2e4a4e 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj
@@ -154,8 +154,6 @@
<ClInclude Include="..\include\Paragraphs.h" />
<ClInclude Include="..\include\pch.h" />
<ClInclude Include="..\include\PostBuildLint.h" />
- <ClInclude Include="..\include\PostBuildLint_ConfigurationType.h" />
- <ClInclude Include="..\include\PostBuildLint_LinkageType.h" />
<ClInclude Include="..\include\SourceParagraph.h" />
<ClInclude Include="..\include\StatusParagraph.h" />
<ClInclude Include="..\include\StatusParagraphs.h" />
@@ -218,8 +216,6 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\src\PostBuildLint.cpp" />
- <ClCompile Include="..\src\PostBuildLint_ConfigurationType.cpp" />
- <ClCompile Include="..\src\PostBuildLint_LinkageType.cpp" />
<ClCompile Include="..\src\PostBuildLint_BuildType.cpp" />
<ClCompile Include="..\src\vcpkg_Chrono.cpp" />
<ClCompile Include="..\src\vcpkglib.cpp" />
diff --git a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
index 895eb2a4a..599bfeafb 100644
--- a/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
+++ b/toolsrc/vcpkglib/vcpkglib.vcxproj.filters
@@ -129,12 +129,6 @@
<ClCompile Include="..\src\PostBuildLint.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\PostBuildLint_LinkageType.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
- <ClCompile Include="..\src\PostBuildLint_ConfigurationType.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\src\PostBuildLint_BuildType.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -257,12 +251,6 @@
<ClInclude Include="..\include\PostBuildLint.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="..\include\PostBuildLint_LinkageType.h">
- <Filter>Header Files</Filter>
- </ClInclude>
- <ClInclude Include="..\include\PostBuildLint_ConfigurationType.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="..\include\vcpkg_Enums.h">
<Filter>Header Files</Filter>
</ClInclude>