PostBuildLint enum revamp
MODIFY
include/PostBuildLint_BuildInfo.h
include/PostBuildLint_BuildInfo.h
@@ -12,8 +12,8 @@ namespace vcpkg::PostBuildLint
{
static BuildInfo create(std::unordered_map<std::string, std::string> pgh);
- LinkageType crt_linkage;
- LinkageType library_linkage;
+ LinkageType::type crt_linkage;
+ LinkageType::type library_linkage;
std::map<BuildPolicies::type, opt_bool_t> policies;
};

MODIFY
include/PostBuildLint_BuildPolicies.h
include/PostBuildLint_BuildPolicies.h
#pragma once
#include <string>
+#include <array>
namespace vcpkg::PostBuildLint::BuildPolicies
{
enum class backing_enum_t
{
- UNKNOWN = 0,
+ NULLVALUE = 0,
EMPTY_PACKAGE,
DLLS_WITHOUT_LIBS
};
struct type
{
+ constexpr type() : backing_enum(backing_enum_t::NULLVALUE) {}
constexpr explicit type(backing_enum_t backing_enum) : backing_enum(backing_enum) { }
constexpr operator backing_enum_t() const { return backing_enum; }
@@ -19,17 +21,16 @@ namespace vcpkg::PostBuildLint::BuildPolicies
const std::string& cmake_variable() const;
private:
- type();
backing_enum_t backing_enum;
};
- static constexpr int value_count = 3;
- const std::vector<type>& values();
+ static const std::string ENUM_NAME = "vcpkg::PostBuildLint::BuildPolicies";
-
- static constexpr type UNKNOWN(backing_enum_t::UNKNOWN);
+ static constexpr type NULLVALUE(backing_enum_t::NULLVALUE);
static constexpr type EMPTY_PACKAGE(backing_enum_t::EMPTY_PACKAGE);
static constexpr type DLLS_WITHOUT_LIBS(backing_enum_t::DLLS_WITHOUT_LIBS);
+ static constexpr std::array<type, 2> values = { EMPTY_PACKAGE, DLLS_WITHOUT_LIBS };
+
type parse(const std::string& s);
}

MODIFY
include/PostBuildLint_BuildType.h
include/PostBuildLint_BuildType.h
#pragma once
#include "PostBuildLint_ConfigurationType.h"
#include "PostBuildLint_LinkageType.h"
-#include <vector>
+#include <array>
#include <regex>
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::BuildType
{
- struct BuildType
+ enum class backing_enum_t
{
- static BuildType value_of(const ConfigurationType& config, const LinkageType& linkage);
-
- static const BuildType DEBUG_STATIC;
- static const BuildType DEBUG_DYNAMIC;
- static const BuildType RELEASE_STATIC;
- static const BuildType RELEASE_DYNAMIC;
+ DEBUG_STATIC = 1,
+ DEBUG_DYNAMIC,
+ RELEASE_STATIC,
+ RELEASE_DYNAMIC
+ };
- static const std::vector<BuildType>& values()
+ struct type
{
- static const std::vector<BuildType> v = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC };
- return v;
- }
+ type() = delete;
- BuildType() = delete;
+ constexpr explicit type(const backing_enum_t backing_enum, const ConfigurationType::type config, const LinkageType::type linkage) :
+ backing_enum(backing_enum), m_config(config), m_linkage(linkage) { }
- const ConfigurationType& config() const;
- const LinkageType& linkage() const;
- std::regex crt_regex() const;
- std::string toString() const;
+ constexpr operator backing_enum_t() const { return backing_enum; }
- private:
- BuildType(const ConfigurationType& config, const LinkageType& linkage, const std::string& crt_regex_as_string)
- : m_config(config), m_linkage(linkage), m_crt_regex_as_string(crt_regex_as_string)
- {
- }
+ const ConfigurationType::type& config() const;
+ const LinkageType::type& linkage() const;
+ const std::regex& crt_regex() const;
+ const std::string& toString() const;
- ConfigurationType m_config;
- LinkageType m_linkage;
- std::string m_crt_regex_as_string;
+ private:
+ backing_enum_t backing_enum;
+ ConfigurationType::type m_config;
+ LinkageType::type m_linkage;
};
- bool operator ==(const BuildType& lhs, const BuildType& rhs);
+ static const std::string ENUM_NAME = "vcpkg::PostBuildLint::BuildType";
+
+ static constexpr type DEBUG_STATIC = type(backing_enum_t::DEBUG_STATIC, ConfigurationType::DEBUG, LinkageType::STATIC);
+ static constexpr type DEBUG_DYNAMIC = type(backing_enum_t::DEBUG_DYNAMIC, ConfigurationType::DEBUG, LinkageType::DYNAMIC);
+ static constexpr type RELEASE_STATIC = type(backing_enum_t::RELEASE_STATIC, ConfigurationType::RELEASE, LinkageType::STATIC);
+ static constexpr type RELEASE_DYNAMIC = type(backing_enum_t::RELEASE_DYNAMIC, ConfigurationType::RELEASE, LinkageType::DYNAMIC);
+
+ static constexpr std::array<type, 4> values = { DEBUG_STATIC, DEBUG_DYNAMIC, RELEASE_STATIC, RELEASE_DYNAMIC };
- bool operator !=(const BuildType& lhs, const BuildType& rhs);
+ type value_of(const ConfigurationType::type& config, const LinkageType::type& linkage);
}

MODIFY
include/PostBuildLint_ConfigurationType.h
include/PostBuildLint_ConfigurationType.h
#pragma once
#include <string>
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::ConfigurationType
{
- enum class ConfigurationType
+ enum class backing_enum_t
{
+ NULLVALUE = 0,
DEBUG = 1,
RELEASE = 2
};
- std::string to_string(const ConfigurationType& conf);
+ struct type
+ {
+ constexpr type() : backing_enum(backing_enum_t::NULLVALUE) {}
+ constexpr explicit type(backing_enum_t backing_enum) : backing_enum(backing_enum) { }
+ constexpr operator backing_enum_t() const { return backing_enum; }
+
+ const std::string& toString() const;
+
+ private:
+ backing_enum_t backing_enum;
+ };
+
+ static const std::string ENUM_NAME = "vcpkg::PostBuildLint::ConfigurationType";
+
+ static constexpr type NULLVALUE(backing_enum_t::NULLVALUE);
+ static constexpr type DEBUG(backing_enum_t::DEBUG);
+ static constexpr type RELEASE(backing_enum_t::RELEASE);
+
+ static constexpr std::array<type, 2> values = { DEBUG, RELEASE };
}

MODIFY
include/PostBuildLint_LinkageType.h
include/PostBuildLint_LinkageType.h
#pragma once
#include <string>
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::LinkageType
{
- enum class LinkageType
+ enum class backing_enum_t
{
+ NULLVALUE = 0,
DYNAMIC,
- STATIC,
- UNKNOWN
+ STATIC
};
- LinkageType linkage_type_value_of(const std::string& as_string);
+ struct type
+ {
+ constexpr type() : backing_enum(backing_enum_t::NULLVALUE) {}
+ constexpr explicit type(backing_enum_t backing_enum) : backing_enum(backing_enum) { }
+ constexpr operator backing_enum_t() const { return backing_enum; }
+
+ const std::string& toString() const;
+
+ private:
+ backing_enum_t backing_enum;
+ };
+
+ static const std::string ENUM_NAME = "vcpkg::PostBuildLint::LinkageType";
+
+ static constexpr type NULLVALUE(backing_enum_t::NULLVALUE);
+ static constexpr type DYNAMIC(backing_enum_t::DYNAMIC);
+ static constexpr type STATIC(backing_enum_t::STATIC);
+
+ static constexpr std::array<type, 2> values = { DYNAMIC, STATIC };
- std::string to_string(const LinkageType& build_info);
+ type value_of(const std::string& as_string);
}

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -500,12 +500,12 @@ namespace vcpkg::PostBuildLint
struct BuildType_and_file
{
fs::path file;
- BuildType build_type;
+ BuildType::type build_type;
};
- static lint_status check_crt_linkage_of_libs(const BuildType& expected_build_type, const std::vector<fs::path>& libs, const fs::path dumpbin_exe)
+ static lint_status check_crt_linkage_of_libs(const BuildType::type& expected_build_type, const std::vector<fs::path>& libs, const fs::path dumpbin_exe)
{
- std::vector<BuildType> bad_build_types = BuildType::values();
+ std::vector<BuildType::type> bad_build_types(BuildType::values.cbegin(), BuildType::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;
@@ -516,7 +516,7 @@ namespace vcpkg::PostBuildLint
System::exit_code_and_output ec_data = System::cmd_execute_and_capture_output(cmd_line);
Checks::check_exit(ec_data.exit_code == 0, "Running command:\n %s\n failed", Strings::utf16_to_utf8(cmd_line));
- for (const BuildType& bad_build_type : bad_build_types)
+ for (const BuildType::type& bad_build_type : bad_build_types)
{
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex()))
{
@@ -662,7 +662,7 @@ namespace vcpkg::PostBuildLint
switch (build_info.library_linkage)
{
- case LinkageType::DYNAMIC:
+ case LinkageType::backing_enum_t::DYNAMIC:
{
const std::vector<fs::path> debug_dlls = Files::recursive_find_files_with_extension_in_dir(debug_bin_dir, ".dll");
const std::vector<fs::path> release_dlls = Files::recursive_find_files_with_extension_in_dir(release_bin_dir, ".dll");
@@ -683,7 +683,7 @@ namespace vcpkg::PostBuildLint
error_count += check_outdated_crt_linkage_of_dlls(dlls, dumpbin_exe);
break;
}
- case LinkageType::STATIC:
+ case LinkageType::backing_enum_t::STATIC:
{
std::vector<fs::path> dlls;
Files::recursive_find_files_with_extension_in_dir(package_dir, ".dll", &dlls);
@@ -695,7 +695,7 @@ namespace vcpkg::PostBuildLint
error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage), release_libs, dumpbin_exe);
break;
}
- case LinkageType::UNKNOWN:
+ case LinkageType::backing_enum_t::NULLVALUE:
default:
Checks::unreachable();
}

MODIFY
src/PostBuildLint_BuildInfo.cpp
src/PostBuildLint_BuildInfo.cpp
@@ -17,18 +17,18 @@ namespace vcpkg::PostBuildLint
{
BuildInfo build_info;
const std::string crt_linkage_as_string = details::remove_required_field(&pgh, BuildInfoRequiredField::CRT_LINKAGE);
- build_info.crt_linkage = linkage_type_value_of(crt_linkage_as_string);
- Checks::check_exit(build_info.crt_linkage != LinkageType::UNKNOWN, "Invalid crt linkage type: [%s]", crt_linkage_as_string);
+ build_info.crt_linkage = LinkageType::value_of(crt_linkage_as_string);
+ Checks::check_exit(build_info.crt_linkage != LinkageType::NULLVALUE, "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 = linkage_type_value_of(library_linkage_as_string);
- Checks::check_exit(build_info.library_linkage != LinkageType::UNKNOWN, "Invalid library linkage type: [%s]", library_linkage_as_string);
+ build_info.library_linkage = LinkageType::value_of(library_linkage_as_string);
+ Checks::check_exit(build_info.library_linkage != LinkageType::NULLVALUE, "Invalid library linkage type: [%s]", library_linkage_as_string);
// The remaining entries are policies
for (const std::unordered_map<std::string, std::string>::value_type& p : pgh)
{
const BuildPolicies::type policy = BuildPolicies::parse(p.first);
- Checks::check_exit(policy != BuildPolicies::UNKNOWN, "Unknown policy found: %s", p.first);
+ Checks::check_exit(policy != BuildPolicies::NULLVALUE, "Unknown policy found: %s", p.first);
const opt_bool_t status = opt_bool::parse(p.second);
build_info.policies.emplace(policy, status);
}

MODIFY
src/PostBuildLint_BuildPolicies.cpp
src/PostBuildLint_BuildPolicies.cpp
#include "pch.h"
#include "PostBuildLint_BuildPolicies.h"
-#include "vcpkg_Checks.h"
+#include "vcpkg_Enums.h"
namespace vcpkg::PostBuildLint::BuildPolicies
{
- static const std::string NAME_UNKNOWN = "PolicyUnknown";
+ static const std::string NULLVALUE_STRING = Enums::nullvalue_toString(ENUM_NAME);
+
static const std::string NAME_EMPTY_PACKAGE = "PolicyEmptyPackage";
static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs";
@@ -16,10 +17,10 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return NAME_EMPTY_PACKAGE;
case DLLS_WITHOUT_LIBS:
return NAME_DLLS_WITHOUT_LIBS;
- case UNKNOWN:
- return NAME_UNKNOWN;
+ case NULLVALUE:
+ return NULLVALUE_STRING;
default:
- Checks::unreachable();
+ Enums::unreachable(ENUM_NAME);
}
}
@@ -34,19 +35,11 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return CMAKE_VARIABLE_EMPTY_PACKAGE;
case DLLS_WITHOUT_LIBS:
return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS;
- case UNKNOWN:
- Checks::exit_with_message("No CMake command corresponds to UNKNOWN");
+ case NULLVALUE:
+ Enums::nullvalue_used(ENUM_NAME);
default:
- Checks::unreachable();
- }
+ Enums::unreachable(ENUM_NAME);
}
-
- type::type(): backing_enum(backing_enum_t::UNKNOWN) {}
-
- const std::vector<type>& values()
- {
- static const std::vector<type>& v = {UNKNOWN, EMPTY_PACKAGE, DLLS_WITHOUT_LIBS};
- return v;
}
type parse(const std::string& s)
@@ -61,6 +54,6 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return BuildPolicies::DLLS_WITHOUT_LIBS;
}
- return BuildPolicies::UNKNOWN;
+ return BuildPolicies::NULLVALUE;
}
}

MODIFY
src/PostBuildLint_BuildType.cpp
src/PostBuildLint_BuildType.cpp
#include "pch.h"
#include "PostBuildLint_BuildType.h"
-#include "vcpkg_Checks.h"
+#include "vcpkg_Enums.h"
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::BuildType
{
- const BuildType BuildType::DEBUG_STATIC = BuildType(ConfigurationType::DEBUG, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMTD)");
- const BuildType BuildType::DEBUG_DYNAMIC = BuildType(ConfigurationType::DEBUG, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRTD)");
- const BuildType BuildType::RELEASE_STATIC = BuildType(ConfigurationType::RELEASE, LinkageType::STATIC, R"(/DEFAULTLIB:LIBCMT[^D])");
- const BuildType BuildType::RELEASE_DYNAMIC = BuildType(ConfigurationType::RELEASE, LinkageType::DYNAMIC, R"(/DEFAULTLIB:MSVCRT[^D])");
-
- BuildType BuildType::value_of(const ConfigurationType& config, const LinkageType& linkage)
+ type value_of(const ConfigurationType::type& config, const LinkageType::type& linkage)
{
if (config == ConfigurationType::DEBUG && linkage == LinkageType::STATIC)
{
@@ -31,38 +26,60 @@ namespace vcpkg::PostBuildLint
return RELEASE_DYNAMIC;
}
- Checks::unreachable();
+ Enums::unreachable(ENUM_NAME);
}
- const ConfigurationType& BuildType::config() const
+ const ConfigurationType::type& type::config() const
{
return this->m_config;
}
- const LinkageType& BuildType::linkage() const
+ const LinkageType::type& type::linkage() const
{
return this->m_linkage;
}
- std::regex BuildType::crt_regex() const
+ const std::regex& type::crt_regex() const
{
- const std::regex r(this->m_crt_regex_as_string, std::regex_constants::icase);
- return r;
- }
+ 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);
+ static const std::regex REGEX_RELEASE_STATIC(R"(/DEFAULTLIB:LIBCMT[^D])", std::regex_constants::icase);
+ static const std::regex REGEX_RELEASE_DYNAMIC(R"(/DEFAULTLIB:MSVCRT[^D])", std::regex_constants::icase);
- std::string BuildType::toString() const
+ switch (backing_enum)
{
- const std::string s = Strings::format("[%s,%s]", to_string(this->m_config), to_string(this->m_linkage));
- return s;
+ case BuildType::DEBUG_STATIC:
+ return REGEX_DEBUG_STATIC;
+ case BuildType::DEBUG_DYNAMIC:
+ return REGEX_DEBUG_DYNAMIC;
+ case BuildType::RELEASE_STATIC:
+ return REGEX_RELEASE_STATIC;
+ case BuildType::RELEASE_DYNAMIC:
+ return REGEX_RELEASE_DYNAMIC;
+ default:
+ Enums::unreachable(ENUM_NAME);
+ }
}
- bool operator==(const BuildType& lhs, const BuildType& rhs)
+ const std::string& type::toString() const
{
- return lhs.config() == rhs.config() && lhs.linkage() == rhs.linkage();
- }
+ static const std::string NAME_DEBUG_STATIC("Debug,Static");
+ static const std::string NAME_DEBUG_DYNAMIC("Debug,Dynamic");
+ static const std::string NAME_RELEASE_STATIC("Release,Static");
+ static const std::string NAME_RELEASE_DYNAMIC("Release,Dynamic");
- bool operator!=(const BuildType& lhs, const BuildType& rhs)
+ switch (backing_enum)
{
- return !(lhs == rhs);
+ case BuildType::DEBUG_STATIC:
+ return NAME_DEBUG_STATIC;
+ case BuildType::DEBUG_DYNAMIC:
+ return NAME_DEBUG_DYNAMIC;
+ case BuildType::RELEASE_STATIC:
+ return NAME_RELEASE_STATIC;
+ case BuildType::RELEASE_DYNAMIC:
+ return NAME_RELEASE_DYNAMIC;
+ default:
+ Enums::unreachable(ENUM_NAME);
+ }
}
}

MODIFY
src/PostBuildLint_ConfigurationType.cpp
src/PostBuildLint_ConfigurationType.cpp
#include "pch.h"
#include "PostBuildLint_ConfigurationType.h"
-#include "vcpkg_Checks.h"
+#include "vcpkg_Enums.h"
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::ConfigurationType
{
- std::string to_string(const ConfigurationType& conf)
+ static const std::string NULLVALUE_STRING = Enums::nullvalue_toString(ENUM_NAME);
+
+ static const std::string NAME_DEBUG = "Debug";
+ static const std::string NAME_RELEASE = "Release";
+
+ const std::string& type::toString() const
{
- switch (conf)
+ switch (this->backing_enum)
{
case ConfigurationType::DEBUG:
- return "Debug";
+ return NAME_DEBUG;
case ConfigurationType::RELEASE:
- return "Release";
+ return NAME_RELEASE;
+ case ConfigurationType::NULLVALUE:
+ return NULLVALUE_STRING;
default:
- Checks::unreachable();
+ Enums::unreachable(ENUM_NAME);
}
}
}

MODIFY
src/PostBuildLint_LinkageType.cpp
src/PostBuildLint_LinkageType.cpp
#include "pch.h"
#include "PostBuildLint_LinkageType.h"
-#include "vcpkg_Checks.h"
+#include "vcpkg_Enums.h"
-namespace vcpkg::PostBuildLint
+namespace vcpkg::PostBuildLint::LinkageType
{
- LinkageType linkage_type_value_of(const std::string& as_string)
+ static const std::string NULLVALUE_STRING = Enums::nullvalue_toString(ENUM_NAME);
+
+ static const std::string NAME_DYNAMIC = "dynamic";
+ static const std::string NAME_STATIC = "static";
+
+ const std::string& type::toString() const
{
- if (as_string == "dynamic")
+ switch (this->backing_enum)
{
- return LinkageType::DYNAMIC;
+ case LinkageType::DYNAMIC:
+ return NAME_DYNAMIC;
+ case LinkageType::STATIC:
+ return NAME_STATIC;
+ case LinkageType::NULLVALUE:
+ return NULLVALUE_STRING;
+ default:
+ Enums::unreachable(ENUM_NAME);
}
-
- if (as_string == "static")
- {
- return LinkageType::STATIC;
}
- return LinkageType::UNKNOWN;
+ type value_of(const std::string& as_string)
+ {
+ if (as_string == NAME_DYNAMIC)
+ {
+ return LinkageType::DYNAMIC;
}
- std::string to_string(const LinkageType& build_info)
+ if (as_string == NAME_STATIC)
{
- switch (build_info)
- {
- case LinkageType::STATIC:
- return "static";
- case LinkageType::DYNAMIC:
- return "dynamic";
- default:
- Checks::unreachable();
+ return LinkageType::STATIC;
}
+
+ return LinkageType::NULLVALUE;
}
}

PostBuildLint enum revamp