Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vcpkg policy cmake helper port support #17

Merged
merged 5 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ namespace vcpkg::Build
ALLOW_RESTRICTED_HEADERS,
SKIP_DUMPBIN_CHECKS,
SKIP_ARCHITECTURE_CHECK,
CMAKE_HELPER_PORT,
// Must be last
COUNT,
};
Expand Down
3 changes: 3 additions & 0 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ namespace vcpkg::Build
static const std::string NAME_ALLOW_RESTRICTED_HEADERS = "PolicyAllowRestrictedHeaders";
static const std::string NAME_SKIP_DUMPBIN_CHECKS = "PolicySkipDumpbinChecks";
static const std::string NAME_SKIP_ARCHITECTURE_CHECK = "PolicySkipArchitectureCheck";
static const std::string NAME_CMAKE_HELPER_PORT = "PolicyCmakeHelperPort";

static std::remove_const_t<decltype(ALL_POLICIES)> generate_all_policies()
{
Expand Down Expand Up @@ -255,6 +256,7 @@ namespace vcpkg::Build
case BuildPolicy::ALLOW_RESTRICTED_HEADERS: return NAME_ALLOW_RESTRICTED_HEADERS;
case BuildPolicy::SKIP_DUMPBIN_CHECKS: return NAME_SKIP_DUMPBIN_CHECKS;
case BuildPolicy::SKIP_ARCHITECTURE_CHECK: return NAME_SKIP_ARCHITECTURE_CHECK;
case BuildPolicy::CMAKE_HELPER_PORT: return NAME_CMAKE_HELPER_PORT;
default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
Expand All @@ -274,6 +276,7 @@ namespace vcpkg::Build
case BuildPolicy::ALLOW_RESTRICTED_HEADERS: return "VCPKG_POLICY_ALLOW_RESTRICTED_HEADERS";
case BuildPolicy::SKIP_DUMPBIN_CHECKS: return "VCPKG_POLICY_SKIP_DUMPBIN_CHECKS";
case BuildPolicy::SKIP_ARCHITECTURE_CHECK: return "VCPKG_POLICY_SKIP_ARCHITECTURE_CHECK";
case BuildPolicy::CMAKE_HELPER_PORT: return "VCPKG_POLICY_CMAKE_HELPER_PORT";
default: Checks::unreachable(VCPKG_LINE_INFO);
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/vcpkg/postbuildlint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ namespace vcpkg::PostBuildLint
}

const fs::path include_dir = package_dir / "include";

if (policies.is_enabled(BuildPolicy::CMAKE_HELPER_PORT))
{
if (fs.exists(include_dir))
{
System::print2(System::Color::warning,
"The folder /include exists in a cmake helper port; this is incorrect, since only cmake "
"files should be installed\n");
return LintStatus::ERROR_DETECTED;
}
else
{
return LintStatus::SUCCESS;
}
}

if (!fs.exists(include_dir) || fs.is_empty(include_dir))
{
System::print2(System::Color::warning,
Expand Down Expand Up @@ -222,6 +238,30 @@ namespace vcpkg::PostBuildLint
return LintStatus::SUCCESS;
}

static LintStatus check_for_vcpkg_port_config(const Files::Filesystem& fs,
const Build::BuildPolicies& policies,
const fs::path& package_dir,
const PackageSpec& spec)
{
const fs::path relative_path =
fs::u8path("share") / fs::u8path(spec.name()) / fs::u8path("vcpkg-port-config.cmake");
const fs::path absolute_path = package_dir / relative_path;

if (policies.is_enabled(BuildPolicy::CMAKE_HELPER_PORT))
{
if (!fs.exists(absolute_path))
{
System::print2(System::Color::warning,
"The /",
fs::u8string(relative_path),
" file does not exist. This file must exist for CMake helper ports.\n");
return LintStatus::ERROR_DETECTED;
}
}

return LintStatus::SUCCESS;
}

static LintStatus check_folder_lib_cmake(const Files::Filesystem& fs,
const fs::path& package_dir,
const PackageSpec& spec)
Expand Down Expand Up @@ -855,6 +895,7 @@ namespace vcpkg::PostBuildLint
error_count += check_for_restricted_include_files(fs, build_info.policies, package_dir);
error_count += check_for_files_in_debug_include_directory(fs, package_dir);
error_count += check_for_files_in_debug_share_directory(fs, package_dir);
error_count += check_for_vcpkg_port_config(fs, build_info.policies, package_dir, spec);
error_count += check_folder_lib_cmake(fs, package_dir, spec);
error_count += check_for_misplaced_cmake_files(fs, package_dir, spec);
error_count += check_folder_debug_lib_cmake(fs, package_dir, spec);
Expand Down