mirror of
https://github.com/microsoft/vcpkg.git
synced 2025-01-19 03:13:03 +08:00
Rework BuildInfo enum
This commit is contained in:
parent
95c222d460
commit
0a51047157
@ -15,7 +15,7 @@ namespace vcpkg::PostBuildLint
|
||||
LinkageType::Type crt_linkage;
|
||||
LinkageType::Type library_linkage;
|
||||
|
||||
std::map<BuildPolicies::Type, OptBoolT> policies;
|
||||
std::map<BuildPolicies, OptBoolT> policies;
|
||||
};
|
||||
|
||||
BuildInfo read_build_info(const Files::Filesystem& fs, const fs::path& filepath);
|
||||
|
@ -2,21 +2,23 @@
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
namespace vcpkg::PostBuildLint::BuildPolicies
|
||||
namespace vcpkg::PostBuildLint
|
||||
{
|
||||
enum class BackingEnum
|
||||
struct BuildPolicies final
|
||||
{
|
||||
NULLVALUE = 0,
|
||||
EMPTY_PACKAGE,
|
||||
DLLS_WITHOUT_LIBS,
|
||||
ONLY_RELEASE_CRT,
|
||||
EMPTY_INCLUDE_FOLDER
|
||||
};
|
||||
enum class BackingEnum
|
||||
{
|
||||
NULLVALUE = 0,
|
||||
EMPTY_PACKAGE,
|
||||
DLLS_WITHOUT_LIBS,
|
||||
ONLY_RELEASE_CRT,
|
||||
EMPTY_INCLUDE_FOLDER
|
||||
};
|
||||
|
||||
struct Type
|
||||
{
|
||||
constexpr Type() : backing_enum(BackingEnum::NULLVALUE) {}
|
||||
constexpr explicit Type(BackingEnum backing_enum) : backing_enum(backing_enum) { }
|
||||
static BuildPolicies parse(const std::string& s);
|
||||
|
||||
constexpr BuildPolicies() : backing_enum(BackingEnum::NULLVALUE) {}
|
||||
constexpr explicit BuildPolicies(BackingEnum backing_enum) : backing_enum(backing_enum) { }
|
||||
constexpr operator BackingEnum() const { return backing_enum; }
|
||||
|
||||
const std::string& to_string() const;
|
||||
@ -28,13 +30,13 @@ namespace vcpkg::PostBuildLint::BuildPolicies
|
||||
|
||||
static const std::string ENUM_NAME = "vcpkg::PostBuildLint::BuildPolicies";
|
||||
|
||||
static constexpr Type NULLVALUE(BackingEnum::NULLVALUE);
|
||||
static constexpr Type EMPTY_PACKAGE(BackingEnum::EMPTY_PACKAGE);
|
||||
static constexpr Type DLLS_WITHOUT_LIBS(BackingEnum::DLLS_WITHOUT_LIBS);
|
||||
static constexpr Type ONLY_RELEASE_CRT(BackingEnum::ONLY_RELEASE_CRT);
|
||||
static constexpr Type EMPTY_INCLUDE_FOLDER(BackingEnum::EMPTY_INCLUDE_FOLDER);
|
||||
namespace BuildPoliciesC
|
||||
{
|
||||
constexpr BuildPolicies NULLVALUE(BuildPolicies::BackingEnum::NULLVALUE);
|
||||
constexpr BuildPolicies EMPTY_PACKAGE(BuildPolicies::BackingEnum::EMPTY_PACKAGE);
|
||||
constexpr BuildPolicies DLLS_WITHOUT_LIBS(BuildPolicies::BackingEnum::DLLS_WITHOUT_LIBS);
|
||||
constexpr BuildPolicies ONLY_RELEASE_CRT(BuildPolicies::BackingEnum::ONLY_RELEASE_CRT);
|
||||
constexpr BuildPolicies EMPTY_INCLUDE_FOLDER(BuildPolicies::BackingEnum::EMPTY_INCLUDE_FOLDER);
|
||||
|
||||
static constexpr std::array<Type, 4> values = { EMPTY_PACKAGE, DLLS_WITHOUT_LIBS, ONLY_RELEASE_CRT, EMPTY_INCLUDE_FOLDER };
|
||||
|
||||
Type parse(const std::string& s);
|
||||
}
|
||||
constexpr std::array<BuildPolicies, 4> VALUES = { EMPTY_PACKAGE,DLLS_WITHOUT_LIBS, ONLY_RELEASE_CRT, EMPTY_INCLUDE_FOLDER };
|
||||
}}
|
||||
|
@ -73,9 +73,9 @@ namespace vcpkg::PostBuildLint
|
||||
return false;
|
||||
}
|
||||
|
||||
static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies::Type, OptBoolT>& policies, const fs::path& package_dir)
|
||||
static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs, const std::map<BuildPolicies, OptBoolT>& policies, const fs::path& package_dir)
|
||||
{
|
||||
if (contains_and_enabled(policies, BuildPolicies::EMPTY_INCLUDE_FOLDER))
|
||||
if (contains_and_enabled(policies, BuildPoliciesC::EMPTY_INCLUDE_FOLDER))
|
||||
{
|
||||
return LintStatus::SUCCESS;
|
||||
}
|
||||
@ -443,9 +443,9 @@ namespace vcpkg::PostBuildLint
|
||||
return LintStatus::ERROR_DETECTED;
|
||||
}
|
||||
|
||||
static LintStatus check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies::Type, OptBoolT>& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir)
|
||||
static LintStatus check_lib_files_are_available_if_dlls_are_available(const std::map<BuildPolicies, OptBoolT>& policies, const size_t lib_count, const size_t dll_count, const fs::path& lib_dir)
|
||||
{
|
||||
auto it = policies.find(BuildPolicies::DLLS_WITHOUT_LIBS);
|
||||
auto it = policies.find(BuildPoliciesC::DLLS_WITHOUT_LIBS);
|
||||
if (it != policies.cend() && it->second == OptBoolT::ENABLED)
|
||||
{
|
||||
return LintStatus::SUCCESS;
|
||||
@ -456,7 +456,7 @@ namespace vcpkg::PostBuildLint
|
||||
System::println(System::Color::warning, "Import libs were not present in %s", lib_dir.u8string());
|
||||
System::println(System::Color::warning,
|
||||
"If this is intended, add the following line in the portfile:\n"
|
||||
" SET(%s enabled)", BuildPolicies::DLLS_WITHOUT_LIBS.cmake_variable());
|
||||
" SET(%s enabled)", BuildPoliciesC::DLLS_WITHOUT_LIBS.cmake_variable());
|
||||
return LintStatus::ERROR_DETECTED;
|
||||
}
|
||||
|
||||
@ -651,7 +651,7 @@ namespace vcpkg::PostBuildLint
|
||||
|
||||
size_t error_count = 0;
|
||||
|
||||
if (contains_and_enabled(build_info.policies, BuildPolicies::EMPTY_PACKAGE))
|
||||
if (contains_and_enabled(build_info.policies, BuildPoliciesC::EMPTY_PACKAGE))
|
||||
{
|
||||
return error_count;
|
||||
}
|
||||
@ -721,7 +721,7 @@ namespace vcpkg::PostBuildLint
|
||||
|
||||
error_count += check_bin_folders_are_not_present_in_static_build(fs, package_dir);
|
||||
|
||||
if (!contains_and_enabled(build_info.policies, BuildPolicies::ONLY_RELEASE_CRT))
|
||||
if (!contains_and_enabled(build_info.policies, BuildPoliciesC::ONLY_RELEASE_CRT))
|
||||
{
|
||||
error_count += check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage), debug_libs, toolset.dumpbin);
|
||||
}
|
||||
|
@ -28,8 +28,8 @@ namespace vcpkg::PostBuildLint
|
||||
// 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(VCPKG_LINE_INFO, policy != BuildPolicies::NULLVALUE, "Unknown policy found: %s", p.first);
|
||||
const BuildPolicies policy = BuildPolicies::parse(p.first);
|
||||
Checks::check_exit(VCPKG_LINE_INFO, policy != BuildPoliciesC::NULLVALUE, "Unknown policy found: %s", p.first);
|
||||
const OptBoolT status = OptBool::parse(p.second);
|
||||
build_info.policies.emplace(policy, status);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "vcpkg_Enums.h"
|
||||
#include "vcpkg_Checks.h"
|
||||
|
||||
namespace vcpkg::PostBuildLint::BuildPolicies
|
||||
namespace vcpkg::PostBuildLint
|
||||
{
|
||||
static const std::string NULLVALUE_STRING = Enums::nullvalue_to_string(ENUM_NAME);
|
||||
|
||||
@ -12,26 +12,51 @@ namespace vcpkg::PostBuildLint::BuildPolicies
|
||||
static const std::string NAME_ONLY_RELEASE_CRT = "PolicyOnlyReleaseCRT";
|
||||
static const std::string NAME_EMPTY_INCLUDE_FOLDER = "PolicyEmptyIncludeFolder";
|
||||
|
||||
const std::string& Type::to_string() const
|
||||
BuildPolicies BuildPolicies::parse(const std::string& s)
|
||||
{
|
||||
if (s == NAME_EMPTY_PACKAGE)
|
||||
{
|
||||
return BuildPoliciesC::EMPTY_PACKAGE;
|
||||
}
|
||||
|
||||
if (s == NAME_DLLS_WITHOUT_LIBS)
|
||||
{
|
||||
return BuildPoliciesC::DLLS_WITHOUT_LIBS;
|
||||
}
|
||||
|
||||
if (s == NAME_ONLY_RELEASE_CRT)
|
||||
{
|
||||
return BuildPoliciesC::ONLY_RELEASE_CRT;
|
||||
}
|
||||
|
||||
if (s == NAME_EMPTY_INCLUDE_FOLDER)
|
||||
{
|
||||
return BuildPoliciesC::EMPTY_INCLUDE_FOLDER;
|
||||
}
|
||||
|
||||
return BuildPoliciesC::NULLVALUE;
|
||||
}
|
||||
|
||||
const std::string& BuildPolicies::to_string() const
|
||||
{
|
||||
switch (this->backing_enum)
|
||||
{
|
||||
case EMPTY_PACKAGE:
|
||||
case BuildPoliciesC::EMPTY_PACKAGE:
|
||||
return NAME_EMPTY_PACKAGE;
|
||||
case DLLS_WITHOUT_LIBS:
|
||||
case BuildPoliciesC::DLLS_WITHOUT_LIBS:
|
||||
return NAME_DLLS_WITHOUT_LIBS;
|
||||
case ONLY_RELEASE_CRT:
|
||||
case BuildPoliciesC::ONLY_RELEASE_CRT:
|
||||
return NAME_ONLY_RELEASE_CRT;
|
||||
case EMPTY_INCLUDE_FOLDER:
|
||||
case BuildPoliciesC::EMPTY_INCLUDE_FOLDER:
|
||||
return NAME_EMPTY_INCLUDE_FOLDER;
|
||||
case NULLVALUE:
|
||||
case BuildPoliciesC::NULLVALUE:
|
||||
return NULLVALUE_STRING;
|
||||
default:
|
||||
Checks::unreachable(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& Type::cmake_variable() const
|
||||
const std::string& BuildPolicies::cmake_variable() const
|
||||
{
|
||||
static const std::string CMAKE_VARIABLE_EMPTY_PACKAGE = "VCPKG_POLICY_EMPTY_PACKAGE";
|
||||
static const std::string CMAKE_VARIABLE_DLLS_WITHOUT_LIBS = "VCPKG_POLICY_DLLS_WITHOUT_LIBS";
|
||||
@ -40,43 +65,18 @@ namespace vcpkg::PostBuildLint::BuildPolicies
|
||||
|
||||
switch (this->backing_enum)
|
||||
{
|
||||
case EMPTY_PACKAGE:
|
||||
case BuildPoliciesC::EMPTY_PACKAGE:
|
||||
return CMAKE_VARIABLE_EMPTY_PACKAGE;
|
||||
case DLLS_WITHOUT_LIBS:
|
||||
case BuildPoliciesC::DLLS_WITHOUT_LIBS:
|
||||
return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS;
|
||||
case ONLY_RELEASE_CRT:
|
||||
case BuildPoliciesC::ONLY_RELEASE_CRT:
|
||||
return CMAKE_VARIABLE_ONLY_RELEASE_CRT;
|
||||
case EMPTY_INCLUDE_FOLDER:
|
||||
case BuildPoliciesC::EMPTY_INCLUDE_FOLDER:
|
||||
return CMAKE_VARIABLE_EMPTY_INCLUDE_FOLDER;
|
||||
case NULLVALUE:
|
||||
case BuildPoliciesC::NULLVALUE:
|
||||
Enums::nullvalue_used(VCPKG_LINE_INFO, ENUM_NAME);
|
||||
default:
|
||||
Checks::unreachable(VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
Type parse(const std::string& s)
|
||||
{
|
||||
if (s == NAME_EMPTY_PACKAGE)
|
||||
{
|
||||
return BuildPolicies::EMPTY_PACKAGE;
|
||||
}
|
||||
|
||||
if (s == NAME_DLLS_WITHOUT_LIBS)
|
||||
{
|
||||
return BuildPolicies::DLLS_WITHOUT_LIBS;
|
||||
}
|
||||
|
||||
if (s == NAME_ONLY_RELEASE_CRT)
|
||||
{
|
||||
return BuildPolicies::ONLY_RELEASE_CRT;
|
||||
}
|
||||
|
||||
if (s == NAME_EMPTY_INCLUDE_FOLDER)
|
||||
{
|
||||
return BuildPolicies::EMPTY_INCLUDE_FOLDER;
|
||||
}
|
||||
|
||||
return BuildPolicies::NULLVALUE;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user