mirror of
https://github.com/cemu-project/vcpkg.git
synced 2024-11-30 14:40:24 +00:00
[vcpkg] Save failure logs in tombstone in CI tests
This commit is contained in:
parent
7e8a854a99
commit
92f57e460a
@ -579,28 +579,34 @@ namespace vcpkg::Build
|
||||
#endif
|
||||
}
|
||||
|
||||
static void compress_archive(const VcpkgPaths& paths, const PackageSpec& spec, const fs::path& tmp_archive_path)
|
||||
// Compress the source directory into the destination file.
|
||||
static void compress_directory(const VcpkgPaths& paths, const fs::path& source, const fs::path& destination)
|
||||
{
|
||||
auto& fs = paths.get_filesystem();
|
||||
|
||||
std::error_code ec;
|
||||
|
||||
fs.remove(tmp_archive_path, ec);
|
||||
fs.remove(destination, ec);
|
||||
Checks::check_exit(
|
||||
VCPKG_LINE_INFO, !fs.exists(tmp_archive_path), "Could not remove file: %s", tmp_archive_path.u8string());
|
||||
VCPKG_LINE_INFO, !fs.exists(destination), "Could not remove file: %s", destination.u8string());
|
||||
#if defined(_WIN32)
|
||||
auto&& seven_zip_exe = paths.get_tool_exe(Tools::SEVEN_ZIP);
|
||||
|
||||
System::cmd_execute_clean(Strings::format(R"("%s" a "%s" "%s\*" >nul)",
|
||||
seven_zip_exe.u8string(),
|
||||
tmp_archive_path.u8string(),
|
||||
paths.package_dir(spec).u8string()));
|
||||
destination.u8string(),
|
||||
source.u8string()));
|
||||
#else
|
||||
System::cmd_execute_clean(Strings::format(
|
||||
R"(cd '%s' && zip --quiet -r '%s' *)", paths.package_dir(spec).u8string(), tmp_archive_path.u8string()));
|
||||
R"(cd '%s' && zip --quiet -r '%s' *)", source.u8string(), destination.u8string()));
|
||||
#endif
|
||||
}
|
||||
|
||||
static void compress_archive(const VcpkgPaths& paths, const PackageSpec& spec, const fs::path& destination)
|
||||
{
|
||||
compress_directory(paths, paths.package_dir(spec), destination);
|
||||
}
|
||||
|
||||
ExtendedBuildResult build_package(const VcpkgPaths& paths,
|
||||
const BuildPackageConfig& config,
|
||||
const StatusParagraphs& status_db)
|
||||
@ -711,9 +717,30 @@ namespace vcpkg::Build
|
||||
}
|
||||
else if (result.code == BuildResult::BUILD_FAILED || result.code == BuildResult::POST_BUILD_CHECKS_FAILED)
|
||||
{
|
||||
// Build failed, so store tombstone archive
|
||||
fs.create_directories(archive_tombstone_path.parent_path(), ec);
|
||||
fs.write_contents(archive_tombstone_path, "", ec);
|
||||
if (!fs.exists(archive_tombstone_path))
|
||||
{
|
||||
// Build failed, store all failure logs in the tombstone.
|
||||
const auto tmp_log_path = paths.buildtrees / spec.name() / "tmp_failure_logs";
|
||||
const auto tmp_log_path_destination = tmp_log_path / spec.name();
|
||||
const auto tmp_failure_zip = paths.buildtrees / spec.name() / "failure_logs.zip";
|
||||
fs.create_directories(tmp_log_path_destination, ec);
|
||||
|
||||
for (auto &log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
|
||||
{
|
||||
if (log_file.path().extension() == ".log")
|
||||
{
|
||||
fs.copy_file(log_file.path(), tmp_log_path_destination / log_file.path().filename(), fs::stdfs::copy_options::none, ec);
|
||||
}
|
||||
}
|
||||
|
||||
compress_directory(paths, tmp_log_path, paths.buildtrees / spec.name() / "failure_logs.zip");
|
||||
|
||||
fs.create_directories(archive_tombstone_path.parent_path(), ec);
|
||||
fs.rename_or_copy(tmp_failure_zip, archive_tombstone_path, ".tmp", ec);
|
||||
|
||||
// clean up temporary directory
|
||||
fs.remove_all(tmp_log_path, ec);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user