Rework BuildType enum
MODIFY
include/PostBuildLint_BuildType.h
include/PostBuildLint_BuildType.h
#include <array>
#include <regex>
-namespace vcpkg::PostBuildLint::BuildType
+namespace vcpkg::PostBuildLint
+{
+ struct BuildType
{
enum class BackingEnum
{
@@ -14,12 +16,15 @@ namespace vcpkg::PostBuildLint::BuildType
RELEASE_DYNAMIC
};
- struct Type
- {
- Type() = delete;
+ static BuildType value_of(const ConfigurationType::Type& config, const LinkageType& linkage);
+
+ BuildType() = delete;
- constexpr explicit Type(const BackingEnum backing_enum, const ConfigurationType::Type config, const LinkageType linkage) :
- backing_enum(backing_enum), m_config(config), m_linkage(linkage) { }
+ constexpr explicit BuildType(const BackingEnum backing_enum, const ConfigurationType::Type config, const LinkageType linkage)
+ :
+ backing_enum(backing_enum)
+ , m_config(config)
+ , m_linkage(linkage) { }
constexpr operator BackingEnum() const { return backing_enum; }
@@ -34,14 +39,14 @@ namespace vcpkg::PostBuildLint::BuildType
LinkageType m_linkage;
};
- static const std::string ENUM_NAME = "vcpkg::PostBuildLint::BuildType";
-
- static constexpr Type DEBUG_STATIC = Type(BackingEnum::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageTypeC::STATIC);
- static constexpr Type DEBUG_DYNAMIC = Type(BackingEnum::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageTypeC::DYNAMIC);
- static constexpr Type RELEASE_STATIC = Type(BackingEnum::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageTypeC::STATIC);
- static constexpr Type RELEASE_DYNAMIC = Type(BackingEnum::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageTypeC::DYNAMIC);
+ namespace BuildTypeC
+ {
+ static constexpr const char* ENUM_NAME = "vcpkg::PostBuildLint::BuildType";
- static constexpr std::array<Type, 4> values = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC };
+ static constexpr BuildType DEBUG_STATIC = BuildType(BuildType::BackingEnum::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageTypeC::STATIC);
+ static constexpr BuildType DEBUG_DYNAMIC = BuildType(BuildType::BackingEnum::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageTypeC::DYNAMIC);
+ static constexpr BuildType RELEASE_STATIC = BuildType(BuildType::BackingEnum::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageTypeC::STATIC);
+ static constexpr BuildType RELEASE_DYNAMIC = BuildType(BuildType::BackingEnum::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageTypeC::DYNAMIC);
- Type value_of(const ConfigurationType::Type& config, const LinkageType& linkage);
-}
+ static constexpr std::array<BuildType, 4> VALUES = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC };
+ }}

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -522,12 +522,12 @@ namespace vcpkg::PostBuildLint
struct BuildType_and_file
{
fs::path file;
- BuildType::Type build_type;
+ BuildType build_type;
};
- static LintStatus check_crt_linkage_of_libs(const BuildType::Type& expected_build_type, const std::vector<fs::path>& libs, const fs::path dumpbin_exe)
+ static LintStatus check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector<fs::path>& libs, const fs::path dumpbin_exe)
{
- std::vector<BuildType::Type> bad_build_types(BuildType::values.cbegin(), BuildType::values.cend());
+ std::vector<BuildType> bad_build_types(BuildTypeC::VALUES.cbegin(), BuildTypeC::VALUES.cend());
bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type), bad_build_types.end());
std::vector<BuildType_and_file> libs_with_invalid_crt;
@@ -538,7 +538,7 @@ namespace vcpkg::PostBuildLint
System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line);
Checks::check_exit(VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line));
- for (const BuildType::Type& bad_build_type : bad_build_types)
+ for (const BuildType& bad_build_type : bad_build_types)
{
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex()))
{

MODIFY
src/PostBuildLint_BuildType.cpp
src/PostBuildLint_BuildType.cpp
#include "PostBuildLint_BuildType.h"
#include "vcpkg_Checks.h"
-namespace vcpkg::PostBuildLint::BuildType
+namespace vcpkg::PostBuildLint
{
- Type value_of(const ConfigurationType::Type& config, const LinkageType& linkage)
+ BuildType BuildType::value_of(const ConfigurationType::Type& config, const LinkageType& linkage)
{
if (config == ConfigurationType::DEBUG && linkage == LinkageTypeC::STATIC)
{
- return DEBUG_STATIC;
+ return BuildTypeC::DEBUG_STATIC;
}
if (config == ConfigurationType::DEBUG && linkage == LinkageTypeC::DYNAMIC)
{
- return DEBUG_DYNAMIC;
+ return BuildTypeC::DEBUG_DYNAMIC;
}
if (config == ConfigurationType::RELEASE && linkage == LinkageTypeC::STATIC)
{
- return RELEASE_STATIC;
+ return BuildTypeC::RELEASE_STATIC;
}
if (config == ConfigurationType::RELEASE && linkage == LinkageTypeC::DYNAMIC)
{
- return RELEASE_DYNAMIC;
+ return BuildTypeC::RELEASE_DYNAMIC;
}
Checks::unreachable(VCPKG_LINE_INFO);
}
- const ConfigurationType::Type& Type::config() const
+ const ConfigurationType::Type& BuildType::config() const
{
return this->m_config;
}
- const LinkageType& Type::linkage() const
+ const LinkageType& BuildType::linkage() const
{
return this->m_linkage;
}
- const std::regex& Type::crt_regex() const
+ const std::regex& BuildType::crt_regex() const
{
static const std::regex REGEX_DEBUG_STATIC(R"(/DEFAULTLIB:LIBCMTD)", std::regex_constants::icase);
static const std::regex REGEX_DEBUG_DYNAMIC(R"(/DEFAULTLIB:MSVCRTD)", std::regex_constants::icase);
@@ -48,20 +48,20 @@ namespace vcpkg::PostBuildLint::BuildType
switch (backing_enum)
{
- case BuildType::DEBUG_STATIC:
+ case BuildTypeC::DEBUG_STATIC:
return REGEX_DEBUG_STATIC;
- case BuildType::DEBUG_DYNAMIC:
+ case BuildTypeC::DEBUG_DYNAMIC:
return REGEX_DEBUG_DYNAMIC;
- case BuildType::RELEASE_STATIC:
+ case BuildTypeC::RELEASE_STATIC:
return REGEX_RELEASE_STATIC;
- case BuildType::RELEASE_DYNAMIC:
+ case BuildTypeC::RELEASE_DYNAMIC:
return REGEX_RELEASE_DYNAMIC;
default:
Checks::unreachable(VCPKG_LINE_INFO);
}
}
- const std::string& Type::to_string() const
+ const std::string& BuildType::to_string() const
{
static const std::string NAME_DEBUG_STATIC("Debug,Static");
static const std::string NAME_DEBUG_DYNAMIC("Debug,Dynamic");
@@ -70,13 +70,13 @@ namespace vcpkg::PostBuildLint::BuildType
switch (backing_enum)
{
- case BuildType::DEBUG_STATIC:
+ case BuildTypeC::DEBUG_STATIC:
return NAME_DEBUG_STATIC;
- case BuildType::DEBUG_DYNAMIC:
+ case BuildTypeC::DEBUG_DYNAMIC:
return NAME_DEBUG_DYNAMIC;
- case BuildType::RELEASE_STATIC:
+ case BuildTypeC::RELEASE_STATIC:
return NAME_RELEASE_STATIC;
- case BuildType::RELEASE_DYNAMIC:
+ case BuildTypeC::RELEASE_DYNAMIC:
return NAME_RELEASE_DYNAMIC;
default:
Checks::unreachable(VCPKG_LINE_INFO);

Rework BuildType enum