2017-01-28 04:49:09 +08:00
|
|
|
#include "pch.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
|
2017-04-04 05:45:00 +08:00
|
|
|
#include "PackageSpec.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
#include "PostBuildLint.h"
|
2017-02-02 05:54:08 +08:00
|
|
|
#include "PostBuildLint_BuildType.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
#include "VcpkgPaths.h"
|
|
|
|
#include "coff_file_reader.h"
|
2017-04-30 19:09:05 +08:00
|
|
|
#include "vcpkg_Build.h"
|
2017-04-28 09:08:52 +08:00
|
|
|
#include "vcpkg_Files.h"
|
|
|
|
#include "vcpkg_System.h"
|
|
|
|
#include "vcpkg_Util.h"
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-05-04 07:33:02 +08:00
|
|
|
using vcpkg::Build::PreBuildInfo;
|
2017-04-30 19:09:05 +08:00
|
|
|
using vcpkg::Build::BuildInfo;
|
2017-05-24 15:44:00 +08:00
|
|
|
using vcpkg::Build::BuildPolicy;
|
2017-04-30 19:09:05 +08:00
|
|
|
|
2017-01-06 06:14:11 +08:00
|
|
|
namespace vcpkg::PostBuildLint
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-09 11:19:35 +08:00
|
|
|
static auto has_extension_pred(const Files::Filesystem& fs, const std::string& ext)
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
return [&fs, ext](const fs::path& path) { return !fs.is_directory(path) && path.extension() == ext; };
|
2017-04-09 11:19:35 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
enum class LintStatus
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
SUCCESS = 0,
|
2016-10-12 02:32:23 +08:00
|
|
|
ERROR_DETECTED = 1
|
2016-09-19 11:50:08 +08:00
|
|
|
};
|
|
|
|
|
2017-02-08 14:57:37 +08:00
|
|
|
struct OutdatedDynamicCrt
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
std::regex regex;
|
2017-02-09 04:36:32 +08:00
|
|
|
|
|
|
|
OutdatedDynamicCrt(const std::string& name, const std::string& regex_as_string)
|
2017-04-28 09:08:52 +08:00
|
|
|
: name(name), regex(std::regex(regex_as_string, std::regex_constants::icase))
|
|
|
|
{
|
|
|
|
}
|
2017-02-08 14:57:37 +08:00
|
|
|
};
|
|
|
|
|
2017-07-25 00:03:03 +08:00
|
|
|
const std::vector<OutdatedDynamicCrt>& get_outdated_dynamic_crts()
|
2017-05-23 10:30:50 +08:00
|
|
|
{
|
2017-05-23 11:49:15 +08:00
|
|
|
static const std::vector<OutdatedDynamicCrt> v_no_msvcrt = {
|
|
|
|
{"msvcp100.dll", R"(msvcp100\.dll)"},
|
|
|
|
{"msvcp100d.dll", R"(msvcp100d\.dll)"},
|
|
|
|
{"msvcp110.dll", R"(msvcp110\.dll)"},
|
|
|
|
{"msvcp110_win.dll", R"(msvcp110_win\.dll)"},
|
|
|
|
{"msvcp120.dll", R"(msvcp120\.dll)"},
|
|
|
|
{"msvcp120_clr0400.dll", R"(msvcp120_clr0400\.dll)"},
|
|
|
|
{"msvcp60.dll", R"(msvcp60\.dll)"},
|
|
|
|
{"msvcp60.dll", R"(msvcp60\.dll)"},
|
2017-05-23 10:30:50 +08:00
|
|
|
|
2017-05-23 11:49:15 +08:00
|
|
|
{"msvcr100.dll", R"(msvcr100\.dll)"},
|
|
|
|
{"msvcr100d.dll", R"(msvcr100d\.dll)"},
|
|
|
|
{"msvcr100_clr0400.dll", R"(msvcr100_clr0400\.dll)"},
|
|
|
|
{"msvcr110.dll", R"(msvcr110\.dll)"},
|
|
|
|
{"msvcr120.dll", R"(msvcr120\.dll)"},
|
|
|
|
{"msvcr120_clr0400.dll", R"(msvcr120_clr0400\.dll)"},
|
|
|
|
{"msvcrt20.dll", R"(msvcrt20\.dll)"},
|
|
|
|
{"msvcrt40.dll", R"(msvcrt40\.dll)"}};
|
|
|
|
|
2017-07-25 00:03:03 +08:00
|
|
|
return v_no_msvcrt;
|
2017-05-23 10:30:50 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_for_files_in_include_directory(const Files::Filesystem& fs,
|
2017-05-24 15:44:00 +08:00
|
|
|
const Build::BuildPolicies& policies,
|
2017-04-28 09:08:52 +08:00
|
|
|
const fs::path& package_dir)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-05-24 15:44:00 +08:00
|
|
|
if (policies.is_enabled(BuildPolicy::EMPTY_INCLUDE_FOLDER))
|
2017-03-25 03:49:08 +08:00
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2017-03-25 03:49:08 +08:00
|
|
|
}
|
|
|
|
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path include_dir = package_dir / "include";
|
2017-04-12 06:16:39 +08:00
|
|
|
if (!fs.exists(include_dir) || fs.is_empty(include_dir))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"The folder /include is empty. This indicates the library was not correctly installed.");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_for_files_in_debug_include_directory(const Files::Filesystem& fs,
|
|
|
|
const fs::path& package_dir)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path debug_include_dir = package_dir / "debug" / "include";
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> files_found = fs.get_files_recursive(debug_include_dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
Util::unstable_keep_if(
|
|
|
|
files_found, [&fs](const fs::path& path) { return !fs.is_directory(path) && path.extension() != ".ifc"; });
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (!files_found.empty())
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"Include files should not be duplicated into the /debug/include directory. If this cannot "
|
|
|
|
"be disabled in the project cmake, use\n"
|
|
|
|
" file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
static LintStatus check_for_files_in_debug_share_directory(const Files::Filesystem& fs, const fs::path& package_dir)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path debug_share = package_dir / "debug" / "share";
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(debug_share))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"/debug/share should not exist. Please reorganize any important files, then use\n"
|
2017-03-28 07:32:51 +08:00
|
|
|
" file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/share)");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_folder_lib_cmake(const Files::Filesystem& fs,
|
|
|
|
const fs::path& package_dir,
|
|
|
|
const PackageSpec& spec)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path lib_cmake = package_dir / "lib" / "cmake";
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(lib_cmake))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(
|
|
|
|
System::Color::warning,
|
|
|
|
"The /lib/cmake folder should be merged with /debug/lib/cmake and moved to /share/%s/cmake.",
|
|
|
|
spec.name());
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_for_misplaced_cmake_files(const Files::Filesystem& fs,
|
|
|
|
const fs::path& package_dir,
|
|
|
|
const PackageSpec& spec)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
std::vector<fs::path> dirs = {
|
2017-04-09 11:19:35 +08:00
|
|
|
package_dir / "cmake",
|
|
|
|
package_dir / "debug" / "cmake",
|
|
|
|
package_dir / "lib" / "cmake",
|
|
|
|
package_dir / "debug" / "lib" / "cmake",
|
|
|
|
};
|
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
std::vector<fs::path> misplaced_cmake_files;
|
2017-04-09 11:19:35 +08:00
|
|
|
for (auto&& dir : dirs)
|
|
|
|
{
|
2017-04-13 14:15:02 +08:00
|
|
|
auto files = fs.get_files_recursive(dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
for (auto&& file : files)
|
|
|
|
{
|
|
|
|
if (!fs.is_directory(file) && file.extension() == ".cmake")
|
|
|
|
misplaced_cmake_files.push_back(std::move(file));
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (!misplaced_cmake_files.empty())
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(
|
|
|
|
System::Color::warning,
|
|
|
|
"The following cmake files were found outside /share/%s. Please place cmake files in /share/%s.",
|
|
|
|
spec.name(),
|
|
|
|
spec.name());
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(misplaced_cmake_files);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_folder_debug_lib_cmake(const Files::Filesystem& fs,
|
|
|
|
const fs::path& package_dir,
|
|
|
|
const PackageSpec& spec)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path lib_cmake_debug = package_dir / "debug" / "lib" / "cmake";
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(lib_cmake_debug))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"The /debug/lib/cmake folder should be merged with /lib/cmake into /share/%s",
|
|
|
|
spec.name());
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
static LintStatus check_for_dlls_in_lib_dir(const Files::Filesystem& fs, const fs::path& package_dir)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> dlls = fs.get_files_recursive(package_dir / "lib");
|
2017-04-09 11:19:35 +08:00
|
|
|
Util::unstable_keep_if(dlls, has_extension_pred(fs, ".dll"));
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (!dlls.empty())
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"\nThe following dlls were found in /lib or /debug/lib. Please move them to /bin or "
|
|
|
|
"/debug/bin, respectively.");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(dlls);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_for_copyright_file(const Files::Filesystem& fs,
|
|
|
|
const PackageSpec& spec,
|
|
|
|
const VcpkgPaths& paths)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path packages_dir = paths.packages / spec.dir();
|
|
|
|
const fs::path copyright_file = packages_dir / "share" / spec.name() / "copyright";
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(copyright_file))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
2016-10-04 08:45:01 +08:00
|
|
|
const fs::path current_buildtrees_dir = paths.buildtrees / spec.name();
|
2016-09-19 11:50:08 +08:00
|
|
|
const fs::path current_buildtrees_dir_src = current_buildtrees_dir / "src";
|
|
|
|
|
|
|
|
std::vector<fs::path> potential_copyright_files;
|
2017-04-09 11:19:35 +08:00
|
|
|
// We only search in the root of each unpacked source archive to reduce false positives
|
2017-04-13 14:15:02 +08:00
|
|
|
auto src_dirs = fs.get_files_non_recursive(current_buildtrees_dir_src);
|
2017-04-09 11:19:35 +08:00
|
|
|
for (auto&& src_dir : src_dirs)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
if (!fs.is_directory(src_dir)) continue;
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-13 14:15:02 +08:00
|
|
|
for (auto&& src_file : fs.get_files_non_recursive(src_dir))
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-09 11:19:35 +08:00
|
|
|
const std::string filename = src_file.filename().string();
|
|
|
|
|
|
|
|
if (filename == "LICENSE" || filename == "LICENSE.txt" || filename == "COPYING")
|
|
|
|
{
|
|
|
|
potential_copyright_files.push_back(src_file);
|
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"The software license must be available at ${CURRENT_PACKAGES_DIR}/share/%s/copyright",
|
|
|
|
spec.name());
|
|
|
|
if (potential_copyright_files.size() ==
|
|
|
|
1) // if there is only one candidate, provide the cmake lines needed to place it in the proper location
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
const fs::path found_file = potential_copyright_files[0];
|
2017-04-28 09:08:52 +08:00
|
|
|
const fs::path relative_path = found_file.string().erase(
|
|
|
|
0, current_buildtrees_dir.string().size() + 1); // The +1 is needed to remove the "/"
|
|
|
|
System::println(
|
|
|
|
"\n file(COPY ${CURRENT_BUILDTREES_DIR}/%s DESTINATION ${CURRENT_PACKAGES_DIR}/share/%s)\n"
|
|
|
|
" file(RENAME ${CURRENT_PACKAGES_DIR}/share/%s/%s ${CURRENT_PACKAGES_DIR}/share/%s/copyright)",
|
|
|
|
relative_path.generic_string(),
|
|
|
|
spec.name(),
|
|
|
|
spec.name(),
|
|
|
|
found_file.filename().generic_string(),
|
|
|
|
spec.name());
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
2017-04-09 11:19:35 +08:00
|
|
|
else if (potential_copyright_files.size() > 1)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "The following files are potential copyright files:");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(potential_copyright_files);
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
static LintStatus check_for_exes(const Files::Filesystem& fs, const fs::path& package_dir)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> exes = fs.get_files_recursive(package_dir / "bin");
|
2017-04-09 11:19:35 +08:00
|
|
|
Util::unstable_keep_if(exes, has_extension_pred(fs, ".exe"));
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (!exes.empty())
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(
|
|
|
|
System::Color::warning,
|
|
|
|
"The following EXEs were found in /bin or /debug/bin. EXEs are not valid distribution targets.");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(exes);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
static LintStatus check_exports_of_dlls(const std::vector<fs::path>& dlls, const fs::path& dumpbin_exe)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
std::vector<fs::path> dlls_with_no_exports;
|
|
|
|
for (const fs::path& dll : dlls)
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
const std::wstring cmd_line =
|
|
|
|
Strings::wformat(LR"("%s" /exports "%s")", dumpbin_exe.native(), dll.native());
|
2017-04-04 07:30:11 +08:00
|
|
|
System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line);
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
ec_data.exit_code == 0,
|
|
|
|
"Running command:\n %s\n failed",
|
2017-05-05 05:54:23 +08:00
|
|
|
Strings::to_utf8(cmd_line));
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (ec_data.output.find("ordinal hint RVA name") == std::string::npos)
|
|
|
|
{
|
|
|
|
dlls_with_no_exports.push_back(dll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dlls_with_no_exports.empty())
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "The following DLLs have no exports:");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(dlls_with_no_exports);
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "DLLs without any exports are likely a bug in the build script.");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_uwp_bit_of_dlls(const std::string& expected_system_name,
|
|
|
|
const std::vector<fs::path>& dlls,
|
|
|
|
const fs::path dumpbin_exe)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-05-04 07:33:02 +08:00
|
|
|
if (expected_system_name != "WindowsStore")
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<fs::path> dlls_with_improper_uwp_bit;
|
|
|
|
for (const fs::path& dll : dlls)
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
const std::wstring cmd_line =
|
|
|
|
Strings::wformat(LR"("%s" /headers "%s")", dumpbin_exe.native(), dll.native());
|
2017-04-04 07:30:11 +08:00
|
|
|
System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line);
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
ec_data.exit_code == 0,
|
|
|
|
"Running command:\n %s\n failed",
|
2017-05-05 05:54:23 +08:00
|
|
|
Strings::to_utf8(cmd_line));
|
2016-09-19 11:50:08 +08:00
|
|
|
|
|
|
|
if (ec_data.output.find("App Container") == std::string::npos)
|
|
|
|
{
|
|
|
|
dlls_with_improper_uwp_bit.push_back(dll);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dlls_with_improper_uwp_bit.empty())
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "The following DLLs do not have the App Container bit set:");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(dlls_with_improper_uwp_bit);
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "This bit is required for Windows Store apps.");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:39:48 +08:00
|
|
|
struct FileAndArch
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
|
|
|
fs::path file;
|
|
|
|
std::string actual_arch;
|
|
|
|
};
|
|
|
|
|
2016-10-15 07:52:19 +08:00
|
|
|
static std::string get_actual_architecture(const MachineType& machine_type)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2016-10-15 07:52:19 +08:00
|
|
|
switch (machine_type)
|
|
|
|
{
|
|
|
|
case MachineType::AMD64:
|
2017-04-28 09:08:52 +08:00
|
|
|
case MachineType::IA64: return "x64";
|
|
|
|
case MachineType::I386: return "x86";
|
2016-10-15 07:52:19 +08:00
|
|
|
case MachineType::ARM:
|
2017-04-28 09:08:52 +08:00
|
|
|
case MachineType::ARMNT: return "arm";
|
|
|
|
default: return "Machine Type Code = " + std::to_string(static_cast<uint16_t>(machine_type));
|
2016-10-15 07:52:19 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-11 09:44:18 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static void print_invalid_architecture_files(const std::string& expected_architecture,
|
|
|
|
std::vector<FileAndArch> binaries_with_invalid_architecture)
|
2016-10-15 07:52:19 +08:00
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "The following files were built for an incorrect architecture:");
|
2016-10-15 07:52:19 +08:00
|
|
|
System::println("");
|
2017-04-04 07:39:48 +08:00
|
|
|
for (const FileAndArch& b : binaries_with_invalid_architecture)
|
2016-10-15 07:52:19 +08:00
|
|
|
{
|
|
|
|
System::println(" %s", b.file.generic_string());
|
|
|
|
System::println("Expected %s, but was: %s", expected_architecture, b.actual_arch);
|
|
|
|
System::println("");
|
|
|
|
}
|
|
|
|
}
|
2016-10-11 09:27:47 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_dll_architecture(const std::string& expected_architecture,
|
|
|
|
const std::vector<fs::path>& files)
|
2016-10-15 07:52:19 +08:00
|
|
|
{
|
2017-04-04 07:39:48 +08:00
|
|
|
std::vector<FileAndArch> binaries_with_invalid_architecture;
|
2016-10-11 09:27:47 +08:00
|
|
|
|
2016-10-15 07:52:19 +08:00
|
|
|
for (const fs::path& file : files)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
file.extension() == ".dll",
|
|
|
|
"The file extension was not .dll: %s",
|
|
|
|
file.generic_string());
|
2017-04-04 05:19:13 +08:00
|
|
|
COFFFileReader::DllInfo info = COFFFileReader::read_dll(file);
|
2016-10-15 07:52:19 +08:00
|
|
|
const std::string actual_architecture = get_actual_architecture(info.machine_type);
|
2016-10-11 09:27:47 +08:00
|
|
|
|
2016-10-15 07:52:19 +08:00
|
|
|
if (expected_architecture != actual_architecture)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
binaries_with_invalid_architecture.push_back({file, actual_architecture});
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!binaries_with_invalid_architecture.empty())
|
|
|
|
{
|
2016-10-15 07:52:19 +08:00
|
|
|
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-10-11 09:27:47 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-10-15 07:52:19 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_lib_architecture(const std::string& expected_architecture,
|
|
|
|
const std::vector<fs::path>& files)
|
2016-10-15 07:52:19 +08:00
|
|
|
{
|
2017-04-04 07:39:48 +08:00
|
|
|
std::vector<FileAndArch> binaries_with_invalid_architecture;
|
2016-10-15 07:52:19 +08:00
|
|
|
|
|
|
|
for (const fs::path& file : files)
|
2016-10-11 09:27:47 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
file.extension() == ".lib",
|
|
|
|
"The file extension was not .lib: %s",
|
|
|
|
file.generic_string());
|
2017-04-04 05:19:13 +08:00
|
|
|
COFFFileReader::LibInfo info = COFFFileReader::read_lib(file);
|
2017-05-09 11:52:53 +08:00
|
|
|
|
|
|
|
// This is zero for folly's debug library
|
|
|
|
// TODO: Why?
|
|
|
|
if (info.machine_types.size() == 0) return LintStatus::SUCCESS;
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
info.machine_types.size() == 1,
|
|
|
|
"Found more than 1 architecture in file %s",
|
|
|
|
file.generic_string());
|
2016-10-15 07:52:19 +08:00
|
|
|
|
|
|
|
const std::string actual_architecture = get_actual_architecture(info.machine_types.at(0));
|
|
|
|
if (expected_architecture != actual_architecture)
|
2016-10-11 09:27:47 +08:00
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
binaries_with_invalid_architecture.push_back({file, actual_architecture});
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
2016-10-15 07:52:19 +08:00
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2016-10-15 07:52:19 +08:00
|
|
|
if (!binaries_with_invalid_architecture.empty())
|
|
|
|
{
|
|
|
|
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
static LintStatus check_no_dlls_present(const std::vector<fs::path>& dlls)
|
2016-09-29 04:15:33 +08:00
|
|
|
{
|
|
|
|
if (dlls.empty())
|
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-09-29 04:15:33 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"DLLs should not be present in a static build, but the following DLLs were found:");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(dlls);
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-09-29 04:15:33 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_matching_debug_and_release_binaries(const std::vector<fs::path>& debug_binaries,
|
|
|
|
const std::vector<fs::path>& release_binaries)
|
2016-10-23 11:00:59 +08:00
|
|
|
{
|
|
|
|
const size_t debug_count = debug_binaries.size();
|
|
|
|
const size_t release_count = release_binaries.size();
|
|
|
|
if (debug_count == release_count)
|
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-10-23 11:00:59 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"Mismatching number of debug and release binaries. Found %d for debug but %d for release.",
|
|
|
|
debug_count,
|
|
|
|
release_count);
|
2016-10-23 11:00:59 +08:00
|
|
|
System::println("Debug binaries");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(debug_binaries);
|
2016-10-23 11:00:59 +08:00
|
|
|
|
|
|
|
System::println("Release binaries");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(release_binaries);
|
2016-10-23 11:00:59 +08:00
|
|
|
|
|
|
|
if (debug_count == 0)
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "Debug binaries were not found");
|
2016-10-23 11:00:59 +08:00
|
|
|
}
|
|
|
|
if (release_count == 0)
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "Release binaries were not found");
|
2016-10-23 11:00:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
System::println("");
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-10-23 11:00:59 +08:00
|
|
|
}
|
|
|
|
|
2017-05-24 15:44:00 +08:00
|
|
|
static LintStatus check_lib_files_are_available_if_dlls_are_available(const Build::BuildPolicies& policies,
|
2017-04-29 08:27:07 +08:00
|
|
|
const size_t lib_count,
|
|
|
|
const size_t dll_count,
|
|
|
|
const fs::path& lib_dir)
|
2016-11-22 04:50:23 +08:00
|
|
|
{
|
2017-05-24 15:44:00 +08:00
|
|
|
if (policies.is_enabled(BuildPolicy::DLLS_WITHOUT_LIBS)) return LintStatus::SUCCESS;
|
2017-02-01 10:31:19 +08:00
|
|
|
|
2016-11-22 04:50:23 +08:00
|
|
|
if (lib_count == 0 && dll_count != 0)
|
|
|
|
{
|
2017-04-09 11:19:35 +08:00
|
|
|
System::println(System::Color::warning, "Import libs were not present in %s", lib_dir.u8string());
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning,
|
2017-02-01 10:31:19 +08:00
|
|
|
"If this is intended, add the following line in the portfile:\n"
|
2017-04-28 09:08:52 +08:00
|
|
|
" SET(%s enabled)",
|
2017-05-24 15:44:00 +08:00
|
|
|
to_cmake_variable(BuildPolicy::DLLS_WITHOUT_LIBS));
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-22 04:50:23 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-22 04:50:23 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_bin_folders_are_not_present_in_static_build(const Files::Filesystem& fs,
|
|
|
|
const fs::path& package_dir)
|
2016-11-03 05:38:16 +08:00
|
|
|
{
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path bin = package_dir / "bin";
|
|
|
|
const fs::path debug_bin = package_dir / "debug" / "bin";
|
2016-11-03 05:38:16 +08:00
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
if (!fs.exists(bin) && !fs.exists(debug_bin))
|
2016-11-03 05:38:16 +08:00
|
|
|
{
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-03 05:38:16 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(bin))
|
2016-11-03 05:38:16 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
R"(There should be no bin\ directory in a static build, but %s is present.)",
|
|
|
|
bin.u8string());
|
2016-11-03 05:38:16 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
if (fs.exists(debug_bin))
|
2016-11-03 05:38:16 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
R"(There should be no debug\bin\ directory in a static build, but %s is present.)",
|
|
|
|
debug_bin.u8string());
|
|
|
|
}
|
|
|
|
|
|
|
|
System::println(
|
|
|
|
System::Color::warning,
|
|
|
|
R"(If the creation of bin\ and/or debug\bin\ cannot be disabled, use this in the portfile to remove them)"
|
|
|
|
"\n"
|
|
|
|
"\n"
|
|
|
|
R"###( if(VCPKG_LIBRARY_LINKAGE STREQUAL static))###"
|
|
|
|
"\n"
|
|
|
|
R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/bin ${CURRENT_PACKAGES_DIR}/debug/bin))###"
|
|
|
|
"\n"
|
|
|
|
R"###( endif())###"
|
|
|
|
"\n");
|
2016-11-03 05:38:16 +08:00
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-03 05:38:16 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
static LintStatus check_no_empty_folders(const Files::Filesystem& fs, const fs::path& dir)
|
2016-11-03 05:57:50 +08:00
|
|
|
{
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> empty_directories = fs.get_files_recursive(dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
Util::unstable_keep_if(empty_directories, [&fs](const fs::path& current) {
|
|
|
|
return fs.is_directory(current) && fs.is_empty(current);
|
|
|
|
});
|
2016-11-03 05:57:50 +08:00
|
|
|
|
|
|
|
if (!empty_directories.empty())
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "There should be no empty directories in %s", dir.generic_string());
|
2016-11-03 05:57:50 +08:00
|
|
|
System::println("The following empty directories were found: ");
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(empty_directories);
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(
|
|
|
|
System::Color::warning,
|
|
|
|
"If a directory should be populated but is not, this might indicate an error in the portfile.\n"
|
|
|
|
"If the directories are not needed and their creation cannot be disabled, use something like this in "
|
|
|
|
"the portfile to remove them:\n"
|
|
|
|
"\n"
|
|
|
|
R"###( file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/a/dir ${CURRENT_PACKAGES_DIR}/some/other/dir))###"
|
|
|
|
"\n"
|
|
|
|
"\n");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-03 05:57:50 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-03 05:57:50 +08:00
|
|
|
}
|
|
|
|
|
2016-11-10 10:44:11 +08:00
|
|
|
struct BuildType_and_file
|
2016-11-09 17:27:49 +08:00
|
|
|
{
|
2016-11-10 10:44:11 +08:00
|
|
|
fs::path file;
|
2017-04-26 08:36:15 +08:00
|
|
|
BuildType build_type;
|
2016-11-09 17:27:49 +08:00
|
|
|
};
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static LintStatus check_crt_linkage_of_libs(const BuildType& expected_build_type,
|
|
|
|
const std::vector<fs::path>& libs,
|
|
|
|
const fs::path dumpbin_exe)
|
2016-11-09 17:27:49 +08:00
|
|
|
{
|
2017-04-26 08:36:15 +08:00
|
|
|
std::vector<BuildType> bad_build_types(BuildTypeC::VALUES.cbegin(), BuildTypeC::VALUES.cend());
|
2017-04-28 09:08:52 +08:00
|
|
|
bad_build_types.erase(std::remove(bad_build_types.begin(), bad_build_types.end(), expected_build_type),
|
|
|
|
bad_build_types.end());
|
2016-11-09 17:27:49 +08:00
|
|
|
|
2016-11-10 10:44:11 +08:00
|
|
|
std::vector<BuildType_and_file> libs_with_invalid_crt;
|
2016-11-09 17:27:49 +08:00
|
|
|
|
|
|
|
for (const fs::path& lib : libs)
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
const std::wstring cmd_line =
|
|
|
|
Strings::wformat(LR"("%s" /directives "%s")", dumpbin_exe.native(), lib.native());
|
2017-04-04 07:30:11 +08:00
|
|
|
System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line);
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
ec_data.exit_code == 0,
|
|
|
|
"Running command:\n %s\n failed",
|
2017-05-05 05:54:23 +08:00
|
|
|
Strings::to_utf8(cmd_line));
|
2016-11-09 17:27:49 +08:00
|
|
|
|
2017-04-26 08:36:15 +08:00
|
|
|
for (const BuildType& bad_build_type : bad_build_types)
|
2016-11-09 17:27:49 +08:00
|
|
|
{
|
2016-11-10 10:44:11 +08:00
|
|
|
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), bad_build_type.crt_regex()))
|
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
libs_with_invalid_crt.push_back({lib, bad_build_type});
|
2016-11-10 10:44:11 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-11-09 17:27:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-10 10:44:11 +08:00
|
|
|
if (!libs_with_invalid_crt.empty())
|
2016-11-09 17:27:49 +08:00
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"Expected %s crt linkage, but the following libs had invalid crt linkage:",
|
|
|
|
expected_build_type.to_string());
|
2016-11-10 10:44:11 +08:00
|
|
|
System::println("");
|
|
|
|
for (const BuildType_and_file btf : libs_with_invalid_crt)
|
2016-11-09 17:27:49 +08:00
|
|
|
{
|
2017-04-04 08:08:08 +08:00
|
|
|
System::println(" %s: %s", btf.file.generic_string(), btf.build_type.to_string());
|
2016-11-09 17:27:49 +08:00
|
|
|
}
|
2016-11-10 10:44:11 +08:00
|
|
|
System::println("");
|
2016-11-09 17:27:49 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"To inspect the lib files, use:\n dumpbin.exe /directives mylibfile.lib");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-09 17:27:49 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-09 17:27:49 +08:00
|
|
|
}
|
|
|
|
|
2016-11-11 03:04:33 +08:00
|
|
|
struct OutdatedDynamicCrt_and_file
|
|
|
|
{
|
|
|
|
fs::path file;
|
|
|
|
OutdatedDynamicCrt outdated_crt;
|
2017-02-09 08:01:22 +08:00
|
|
|
|
|
|
|
OutdatedDynamicCrt_and_file() = delete;
|
2016-11-11 03:04:33 +08:00
|
|
|
};
|
|
|
|
|
2017-05-23 10:30:50 +08:00
|
|
|
static LintStatus check_outdated_crt_linkage_of_dlls(const std::vector<fs::path>& dlls,
|
|
|
|
const fs::path dumpbin_exe,
|
|
|
|
const BuildInfo& build_info)
|
2016-11-11 03:04:33 +08:00
|
|
|
{
|
2017-07-25 00:03:03 +08:00
|
|
|
if (build_info.policies.is_enabled(BuildPolicy::ALLOW_OBSOLETE_MSVCRT)) return LintStatus::SUCCESS;
|
2016-11-11 03:04:33 +08:00
|
|
|
|
|
|
|
std::vector<OutdatedDynamicCrt_and_file> dlls_with_outdated_crt;
|
|
|
|
|
|
|
|
for (const fs::path& dll : dlls)
|
|
|
|
{
|
2017-04-28 09:08:52 +08:00
|
|
|
const std::wstring cmd_line =
|
|
|
|
Strings::wformat(LR"("%s" /dependents "%s")", dumpbin_exe.native(), dll.native());
|
2017-04-04 07:30:11 +08:00
|
|
|
System::ExitCodeAndOutput ec_data = System::cmd_execute_and_capture_output(cmd_line);
|
2017-04-28 09:08:52 +08:00
|
|
|
Checks::check_exit(VCPKG_LINE_INFO,
|
|
|
|
ec_data.exit_code == 0,
|
|
|
|
"Running command:\n %s\n failed",
|
2017-05-05 05:54:23 +08:00
|
|
|
Strings::to_utf8(cmd_line));
|
2016-11-11 03:04:33 +08:00
|
|
|
|
2017-07-25 00:03:03 +08:00
|
|
|
for (const OutdatedDynamicCrt& outdated_crt : get_outdated_dynamic_crts())
|
2016-11-11 03:04:33 +08:00
|
|
|
{
|
2017-02-08 14:57:37 +08:00
|
|
|
if (std::regex_search(ec_data.output.cbegin(), ec_data.output.cend(), outdated_crt.regex))
|
2016-11-11 03:04:33 +08:00
|
|
|
{
|
2017-04-29 03:55:50 +08:00
|
|
|
dlls_with_outdated_crt.push_back({dll, outdated_crt});
|
2016-11-11 03:04:33 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dlls_with_outdated_crt.empty())
|
|
|
|
{
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "Detected outdated dynamic CRT in the following files:");
|
2016-11-11 03:04:33 +08:00
|
|
|
System::println("");
|
|
|
|
for (const OutdatedDynamicCrt_and_file btf : dlls_with_outdated_crt)
|
|
|
|
{
|
2017-02-08 14:57:37 +08:00
|
|
|
System::println(" %s: %s", btf.file.generic_string(), btf.outdated_crt.name);
|
2016-11-11 03:04:33 +08:00
|
|
|
}
|
|
|
|
System::println("");
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::warning,
|
|
|
|
"To inspect the dll files, use:\n dumpbin.exe /dependents mydllfile.dll");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-11 03:04:33 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-11 03:04:33 +08:00
|
|
|
}
|
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
static LintStatus check_no_files_in_dir(const Files::Filesystem& fs, const fs::path& dir)
|
2016-11-30 05:07:21 +08:00
|
|
|
{
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> misplaced_files = fs.get_files_non_recursive(dir);
|
2017-04-28 09:08:52 +08:00
|
|
|
Util::unstable_keep_if(misplaced_files, [&fs](const fs::path& path) {
|
|
|
|
const std::string filename = path.filename().generic_string();
|
2017-05-05 06:19:22 +08:00
|
|
|
if (Strings::case_insensitive_ascii_compare(filename.c_str(), "CONTROL") == 0 ||
|
|
|
|
Strings::case_insensitive_ascii_compare(filename.c_str(), "BUILD_INFO") == 0)
|
2017-04-28 09:08:52 +08:00
|
|
|
return false;
|
|
|
|
return !fs.is_directory(path);
|
|
|
|
});
|
2016-11-30 05:07:21 +08:00
|
|
|
|
|
|
|
if (!misplaced_files.empty())
|
|
|
|
{
|
2017-04-09 11:19:35 +08:00
|
|
|
System::println(System::Color::warning, "The following files are placed in\n%s: ", dir.u8string());
|
2016-12-01 06:08:43 +08:00
|
|
|
Files::print_paths(misplaced_files);
|
2017-04-04 07:31:00 +08:00
|
|
|
System::println(System::Color::warning, "Files cannot be present in those directories.\n");
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::ERROR_DETECTED;
|
2016-11-30 05:07:21 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 07:43:30 +08:00
|
|
|
return LintStatus::SUCCESS;
|
2016-11-30 05:07:21 +08:00
|
|
|
}
|
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
static void operator+=(size_t& left, const LintStatus& right) { left += static_cast<size_t>(right); }
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-30 19:09:05 +08:00
|
|
|
static size_t perform_all_checks_and_return_error_count(const PackageSpec& spec,
|
|
|
|
const VcpkgPaths& paths,
|
2017-05-04 07:33:02 +08:00
|
|
|
const PreBuildInfo& pre_build_info,
|
2017-04-30 19:09:05 +08:00
|
|
|
const BuildInfo& build_info)
|
2016-09-19 11:50:08 +08:00
|
|
|
{
|
2017-04-09 11:19:35 +08:00
|
|
|
const auto& fs = paths.get_filesystem();
|
|
|
|
|
2017-04-01 17:08:48 +08:00
|
|
|
// for dumpbin
|
2017-06-03 00:13:12 +08:00
|
|
|
const Toolset& toolset = paths.get_toolset(pre_build_info.platform_toolset);
|
2016-11-30 07:32:44 +08:00
|
|
|
const fs::path package_dir = paths.package_dir(spec);
|
2016-11-09 06:12:49 +08:00
|
|
|
|
2016-10-01 02:22:24 +08:00
|
|
|
size_t error_count = 0;
|
2017-02-08 09:02:57 +08:00
|
|
|
|
2017-05-24 15:44:00 +08:00
|
|
|
if (build_info.policies.is_enabled(BuildPolicy::EMPTY_PACKAGE))
|
2017-02-08 09:02:57 +08:00
|
|
|
{
|
|
|
|
return error_count;
|
|
|
|
}
|
|
|
|
|
2017-04-12 06:16:39 +08:00
|
|
|
error_count += check_for_files_in_include_directory(fs, build_info.policies, package_dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
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_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);
|
|
|
|
error_count += check_for_dlls_in_lib_dir(fs, package_dir);
|
|
|
|
error_count += check_for_dlls_in_lib_dir(fs, package_dir / "debug");
|
|
|
|
error_count += check_for_copyright_file(fs, spec, paths);
|
|
|
|
error_count += check_for_exes(fs, package_dir);
|
|
|
|
error_count += check_for_exes(fs, package_dir / "debug");
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2016-11-30 05:06:42 +08:00
|
|
|
const fs::path debug_lib_dir = package_dir / "debug" / "lib";
|
|
|
|
const fs::path release_lib_dir = package_dir / "lib";
|
|
|
|
const fs::path debug_bin_dir = package_dir / "debug" / "bin";
|
|
|
|
const fs::path release_bin_dir = package_dir / "bin";
|
2016-11-22 04:50:23 +08:00
|
|
|
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> debug_libs = fs.get_files_recursive(debug_lib_dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
Util::unstable_keep_if(debug_libs, has_extension_pred(fs, ".lib"));
|
2017-04-13 14:15:02 +08:00
|
|
|
std::vector<fs::path> release_libs = fs.get_files_recursive(release_lib_dir);
|
2017-04-09 11:19:35 +08:00
|
|
|
Util::unstable_keep_if(release_libs, has_extension_pred(fs, ".lib"));
|
2016-11-09 11:33:50 +08:00
|
|
|
|
|
|
|
error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs);
|
|
|
|
|
2017-04-12 06:16:39 +08:00
|
|
|
{
|
|
|
|
std::vector<fs::path> libs;
|
|
|
|
libs.insert(libs.cend(), debug_libs.cbegin(), debug_libs.cend());
|
|
|
|
libs.insert(libs.cend(), release_libs.cbegin(), release_libs.cend());
|
2016-11-09 11:33:50 +08:00
|
|
|
|
2017-05-04 07:33:02 +08:00
|
|
|
error_count += check_lib_architecture(pre_build_info.target_architecture, libs);
|
2017-04-12 06:16:39 +08:00
|
|
|
}
|
2016-11-09 11:33:50 +08:00
|
|
|
|
2017-07-08 08:19:19 +08:00
|
|
|
std::vector<fs::path> debug_dlls = fs.get_files_recursive(debug_bin_dir);
|
|
|
|
Util::unstable_keep_if(debug_dlls, has_extension_pred(fs, ".dll"));
|
|
|
|
std::vector<fs::path> release_dlls = fs.get_files_recursive(release_bin_dir);
|
|
|
|
Util::unstable_keep_if(release_dlls, has_extension_pred(fs, ".dll"));
|
|
|
|
|
2017-02-10 10:39:03 +08:00
|
|
|
switch (build_info.library_linkage)
|
2016-09-29 04:15:33 +08:00
|
|
|
{
|
2017-06-07 07:30:01 +08:00
|
|
|
case Build::LinkageType::DYNAMIC:
|
2017-04-28 09:08:52 +08:00
|
|
|
{
|
|
|
|
error_count += check_matching_debug_and_release_binaries(debug_dlls, release_dlls);
|
2016-10-23 11:00:59 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
error_count += check_lib_files_are_available_if_dlls_are_available(
|
|
|
|
build_info.policies, debug_libs.size(), debug_dlls.size(), debug_lib_dir);
|
|
|
|
error_count += check_lib_files_are_available_if_dlls_are_available(
|
|
|
|
build_info.policies, release_libs.size(), release_dlls.size(), release_lib_dir);
|
2016-11-22 04:50:23 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
std::vector<fs::path> dlls;
|
|
|
|
dlls.insert(dlls.cend(), debug_dlls.cbegin(), debug_dlls.cend());
|
|
|
|
dlls.insert(dlls.cend(), release_dlls.cbegin(), release_dlls.cend());
|
2016-09-29 04:15:33 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
error_count += check_exports_of_dlls(dlls, toolset.dumpbin);
|
2017-05-04 07:33:02 +08:00
|
|
|
error_count += check_uwp_bit_of_dlls(pre_build_info.cmake_system_name, dlls, toolset.dumpbin);
|
|
|
|
error_count += check_dll_architecture(pre_build_info.target_architecture, dlls);
|
2016-11-11 03:04:33 +08:00
|
|
|
|
2017-05-23 10:30:50 +08:00
|
|
|
error_count += check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin, build_info);
|
2017-04-28 09:08:52 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-06-07 07:30:01 +08:00
|
|
|
case Build::LinkageType::STATIC:
|
2017-04-28 09:08:52 +08:00
|
|
|
{
|
2017-07-08 08:19:19 +08:00
|
|
|
auto dlls = release_dlls;
|
|
|
|
dlls.insert(dlls.end(), debug_dlls.begin(), debug_dlls.end());
|
2017-04-28 09:08:52 +08:00
|
|
|
error_count += check_no_dlls_present(dlls);
|
2016-10-15 07:52:19 +08:00
|
|
|
|
2017-04-28 09:08:52 +08:00
|
|
|
error_count += check_bin_folders_are_not_present_in_static_build(fs, package_dir);
|
2016-11-09 17:27:49 +08:00
|
|
|
|
2017-05-24 15:44:00 +08:00
|
|
|
if (!build_info.policies.is_enabled(BuildPolicy::ONLY_RELEASE_CRT))
|
2017-04-28 09:08:52 +08:00
|
|
|
{
|
2017-06-07 07:30:01 +08:00
|
|
|
error_count +=
|
|
|
|
check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::DEBUG, build_info.crt_linkage),
|
|
|
|
debug_libs,
|
|
|
|
toolset.dumpbin);
|
2017-02-08 14:57:37 +08:00
|
|
|
}
|
2017-04-28 09:08:52 +08:00
|
|
|
error_count +=
|
2017-06-07 07:30:01 +08:00
|
|
|
check_crt_linkage_of_libs(BuildType::value_of(ConfigurationType::RELEASE, build_info.crt_linkage),
|
2017-04-28 09:08:52 +08:00
|
|
|
release_libs,
|
|
|
|
toolset.dumpbin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: Checks::unreachable(VCPKG_LINE_INFO);
|
2016-09-29 04:15:33 +08:00
|
|
|
}
|
2016-09-19 11:50:08 +08:00
|
|
|
|
2017-04-09 11:19:35 +08:00
|
|
|
error_count += check_no_empty_folders(fs, package_dir);
|
|
|
|
error_count += check_no_files_in_dir(fs, package_dir);
|
|
|
|
error_count += check_no_files_in_dir(fs, package_dir / "debug");
|
2016-11-03 05:57:50 +08:00
|
|
|
|
2017-02-08 09:02:57 +08:00
|
|
|
return error_count;
|
|
|
|
}
|
|
|
|
|
2017-05-04 07:33:02 +08:00
|
|
|
size_t perform_all_checks(const PackageSpec& spec,
|
|
|
|
const VcpkgPaths& paths,
|
|
|
|
const PreBuildInfo& pre_build_info,
|
|
|
|
const BuildInfo& build_info)
|
2017-02-08 09:02:57 +08:00
|
|
|
{
|
|
|
|
System::println("-- Performing post-build validation");
|
2017-05-04 07:33:02 +08:00
|
|
|
const size_t error_count = perform_all_checks_and_return_error_count(spec, paths, pre_build_info, build_info);
|
2017-02-08 09:02:57 +08:00
|
|
|
|
2016-09-19 11:50:08 +08:00
|
|
|
if (error_count != 0)
|
|
|
|
{
|
2016-10-04 08:45:01 +08:00
|
|
|
const fs::path portfile = paths.ports / spec.name() / "portfile.cmake";
|
2017-04-28 09:08:52 +08:00
|
|
|
System::println(System::Color::error,
|
|
|
|
"Found %u error(s). Please correct the portfile:\n %s",
|
|
|
|
error_count,
|
|
|
|
portfile.string());
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
|
|
|
|
2017-03-23 04:28:10 +08:00
|
|
|
System::println("-- Performing post-build validation done");
|
|
|
|
|
2017-02-04 10:10:29 +08:00
|
|
|
return error_count;
|
2016-09-19 11:50:08 +08:00
|
|
|
}
|
2017-01-06 06:14:11 +08:00
|
|
|
}
|