Add EMPTY_INCLUDE_FOLDER policy. Resolves #816

This commit is contained in:
Alexander Karatarakis 2017-03-24 12:49:08 -07:00
parent cbfc4c0e54
commit 3b511adfe4
4 changed files with 38 additions and 16 deletions

View File

@ -85,6 +85,9 @@ if(CMD MATCHES "^BUILD$")
if (DEFINED VCPKG_POLICY_ONLY_RELEASE_CRT)
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyOnlyReleaseCRT: ${VCPKG_POLICY_ONLY_RELEASE_CRT}\n")
endif()
if (DEFINED VCPKG_POLICY_EMPTY_INCLUDE_FOLDER)
file(APPEND ${BUILD_INFO_FILE_PATH} "PolicyEmptyIncludeFolder: ${VCPKG_POLICY_EMPTY_INCLUDE_FOLDER}\n")
endif()
elseif(CMD MATCHES "^CREATE$")
file(TO_NATIVE_PATH ${VCPKG_ROOT_DIR} NATIVE_VCPKG_ROOT_DIR)
file(TO_NATIVE_PATH ${DOWNLOADS} NATIVE_DOWNLOADS)

View File

@ -9,7 +9,8 @@ namespace vcpkg::PostBuildLint::BuildPolicies
NULLVALUE = 0,
EMPTY_PACKAGE,
DLLS_WITHOUT_LIBS,
ONLY_RELEASE_CRT
ONLY_RELEASE_CRT,
EMPTY_INCLUDE_FOLDER
};
struct type
@ -31,8 +32,9 @@ namespace vcpkg::PostBuildLint::BuildPolicies
static constexpr type EMPTY_PACKAGE(backing_enum_t::EMPTY_PACKAGE);
static constexpr type DLLS_WITHOUT_LIBS(backing_enum_t::DLLS_WITHOUT_LIBS);
static constexpr type ONLY_RELEASE_CRT(backing_enum_t::ONLY_RELEASE_CRT);
static constexpr type EMPTY_INCLUDE_FOLDER(backing_enum_t::EMPTY_INCLUDE_FOLDER);
static constexpr std::array<type, 3> values = { EMPTY_PACKAGE, DLLS_WITHOUT_LIBS, ONLY_RELEASE_CRT };
static constexpr std::array<type, 4> values = { EMPTY_PACKAGE, DLLS_WITHOUT_LIBS, ONLY_RELEASE_CRT, EMPTY_INCLUDE_FOLDER };
type parse(const std::string& s);
}

View File

@ -7,6 +7,7 @@
#include "coff_file_reader.h"
#include "PostBuildLint_BuildInfo.h"
#include "PostBuildLint_BuildType.h"
#include "PostBuildLint.h"
namespace vcpkg::PostBuildLint
{
@ -52,8 +53,25 @@ namespace vcpkg::PostBuildLint
return v;
}
static lint_status check_for_files_in_include_directory(const fs::path& package_dir)
template <class T>
static bool contains_and_enabled(const std::map<T, opt_bool_t> map, const T& key)
{
auto it = map.find(key);
if (it != map.cend() && it->second == opt_bool_t::ENABLED)
{
return true;
}
return false;
}
static lint_status check_for_files_in_include_directory(const std::map<BuildPolicies::type, opt_bool_t>& policies, const fs::path& package_dir)
{
if (contains_and_enabled(policies, BuildPolicies::EMPTY_INCLUDE_FOLDER))
{
return lint_status::SUCCESS;
}
const fs::path include_dir = package_dir / "include";
if (!fs::exists(include_dir) || fs::is_empty(include_dir))
{
@ -601,18 +619,6 @@ namespace vcpkg::PostBuildLint
left += static_cast<size_t>(right);
}
template <class T>
static bool contains_and_enabled(const std::map<T, opt_bool_t> map, const T& key)
{
auto it = map.find(key);
if (it != map.cend() && it->second == opt_bool_t::ENABLED)
{
return true;
}
return false;
}
static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths)
{
const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths);
@ -627,7 +633,7 @@ namespace vcpkg::PostBuildLint
return error_count;
}
error_count += check_for_files_in_include_directory(package_dir);
error_count += check_for_files_in_include_directory(build_info.policies, package_dir);
error_count += check_for_files_in_debug_include_directory(package_dir);
error_count += check_for_files_in_debug_share_directory(package_dir);
error_count += check_folder_lib_cmake(package_dir, spec);

View File

@ -10,6 +10,7 @@ namespace vcpkg::PostBuildLint::BuildPolicies
static const std::string NAME_EMPTY_PACKAGE = "PolicyEmptyPackage";
static const std::string NAME_DLLS_WITHOUT_LIBS = "PolicyDLLsWithoutLIBs";
static const std::string NAME_ONLY_RELEASE_CRT = "PolicyOnlyReleaseCRT";
static const std::string NAME_EMPTY_INCLUDE_FOLDER = "PolicyEmptyIncludeFolder";
const std::string& type::toString() const
{
@ -21,6 +22,8 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return NAME_DLLS_WITHOUT_LIBS;
case ONLY_RELEASE_CRT:
return NAME_ONLY_RELEASE_CRT;
case EMPTY_INCLUDE_FOLDER:
return NAME_EMPTY_INCLUDE_FOLDER;
case NULLVALUE:
return NULLVALUE_STRING;
default:
@ -33,6 +36,7 @@ namespace vcpkg::PostBuildLint::BuildPolicies
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";
static const std::string CMAKE_VARIABLE_ONLY_RELEASE_CRT = "VCPKG_POLICY_ONLY_RELEASE_CRT";
static const std::string CMAKE_VARIABLE_EMPTY_INCLUDE_FOLDER = "VCPKG_POLICY_EMPTY_INCLUDE_FOLDER";
switch (this->backing_enum)
{
@ -42,6 +46,8 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return CMAKE_VARIABLE_DLLS_WITHOUT_LIBS;
case ONLY_RELEASE_CRT:
return CMAKE_VARIABLE_ONLY_RELEASE_CRT;
case EMPTY_INCLUDE_FOLDER:
return CMAKE_VARIABLE_EMPTY_INCLUDE_FOLDER;
case NULLVALUE:
Enums::nullvalue_used(VCPKG_LINE_INFO, ENUM_NAME);
default:
@ -66,6 +72,11 @@ namespace vcpkg::PostBuildLint::BuildPolicies
return BuildPolicies::ONLY_RELEASE_CRT;
}
if (s == NAME_EMPTY_INCLUDE_FOLDER)
{
return BuildPolicies::EMPTY_INCLUDE_FOLDER;
}
return BuildPolicies::NULLVALUE;
}
}