Skip to content

Commit

Permalink
Add post build check to verify that the libs on macOS have the right …
Browse files Browse the repository at this point in the history
…architecture
  • Loading branch information
autoantwort committed Aug 18, 2021
1 parent f6e44df commit de502ef
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
11 changes: 11 additions & 0 deletions include/vcpkg/base/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,15 @@ namespace vcpkg
return !Strings::case_insensitive_ascii_equals(target.extension(), ext);
}
};

struct NotExtensionsCaseInsensitive
{
std::initializer_list<StringView> exts;
bool operator()(const Path& target) const
{
return !std::any_of(exts.begin(), exts.end(), [extension = target.extension()](const auto& ext) {
return Strings::case_insensitive_ascii_equals(extension, ext);
});
}
};
}
29 changes: 26 additions & 3 deletions src/vcpkg/postbuildlint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ namespace vcpkg::PostBuildLint
}
#endif

#if defined(_WIN32)
#if defined(_WIN32) or defined(__APPLE__)
static void print_invalid_architecture_files(const std::string& expected_architecture,
std::vector<FileAndArch> binaries_with_invalid_architecture)
{
Expand All @@ -517,6 +517,9 @@ namespace vcpkg::PostBuildLint
"\n\n");
}
}
#endif

#if defined(_WIN32)

static LintStatus check_dll_architecture(const std::string& expected_architecture,
const std::vector<Path>& files,
Expand Down Expand Up @@ -578,6 +581,26 @@ namespace vcpkg::PostBuildLint
}
}

if (!binaries_with_invalid_architecture.empty())
{
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
return LintStatus::ERROR_DETECTED;
}
#elif defined(__APPLE__)
std::vector<FileAndArch> binaries_with_invalid_architecture;
const auto requested_arch = expected_architecture == "x64" ? "x86_64" : expected_architecture;
for (const Path& file : files)
{
auto cmd_line = Command("lipo").string_arg("-archs").path_arg(file);
ExitCodeAndOutput ec_data = cmd_execute_and_capture_output(cmd_line);
Checks::check_exit(
VCPKG_LINE_INFO, ec_data.exit_code == 0, "Running command:\n %s\n failed", cmd_line.command_line());
if (ec_data.output.find(requested_arch) == std::string::npos)
{
binaries_with_invalid_architecture.push_back({file, ec_data.output});
}
}

if (!binaries_with_invalid_architecture.empty())
{
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
Expand Down Expand Up @@ -891,9 +914,9 @@ namespace vcpkg::PostBuildLint
const auto release_bin_dir = package_dir / "bin";

std::vector<Path> debug_libs = fs.get_regular_files_recursive(debug_lib_dir, IgnoreErrors{});
Util::erase_remove_if(debug_libs, NotExtensionCaseInsensitive{".lib"});
Util::erase_remove_if(debug_libs, NotExtensionsCaseInsensitive{{".lib", ".so", ".a", ".dylib"}});
std::vector<Path> release_libs = fs.get_regular_files_recursive(release_lib_dir, IgnoreErrors{});
Util::erase_remove_if(release_libs, NotExtensionCaseInsensitive{".lib"});
Util::erase_remove_if(release_libs, NotExtensionsCaseInsensitive{{".lib", ".so", ".a", ".dylib"}});

if (!pre_build_info.build_type && !build_info.policies.is_enabled(BuildPolicy::MISMATCHED_NUMBER_OF_BINARIES))
error_count += check_matching_debug_and_release_binaries(debug_libs, release_libs);
Expand Down

0 comments on commit de502ef

Please sign in to comment.