mirror of
https://github.com/cemu-project/vcpkg.git
synced 2025-02-23 11:07:10 +01:00
Convert BuildType/Configuration Type into simple enum classes
This commit is contained in:
parent
831f0631f7
commit
9a698d7088
@ -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};
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
#include "CStringView.h"
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
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};
|
||||
}
|
||||
}
|
@ -2,12 +2,12 @@
|
||||
|
||||
#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>
|
||||
@ -141,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;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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";
|
||||
@ -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())
|
||||
|
@ -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" />
|
||||
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user