Fix --keep-going to exit with nonzero if a failure occurred (#670)

* Fix --keep-going to exit with nonzero if a failure occurred

* PR comments
This commit is contained in:
Robert Schumacher 2022-08-23 12:43:32 -07:00 коммит произвёл GitHub
Родитель 47c9449a34
Коммит e4f0750dd5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,9 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1
# Test keep-going to not report an error
Run-Vcpkg -TestArgs ($commonArgs + @("install", "vcpkg-empty-port", "--keep-going"))
Throw-IfFailed
# Test keep-going to report an error
Run-Vcpkg -TestArgs ($commonArgs + @("install", "vcpkg-fail-if-depended-upon", "--keep-going"))
Throw-IfNotFailed

Просмотреть файл

@ -48,6 +48,7 @@ namespace vcpkg
void print() const;
std::string xunit_results() const;
bool failed() const;
};
struct InstallDir

Просмотреть файл

@ -431,6 +431,18 @@ namespace vcpkg
}
}
bool InstallSummary::failed() const
{
for (const auto& result : this->results)
{
if (result.build_result.value_or_exit(VCPKG_LINE_INFO).code != BuildResult::SUCCEEDED)
{
return true;
}
}
return false;
}
struct TrackedPackageInstallGuard
{
SpecSummary* current_summary = nullptr;
@ -1209,13 +1221,14 @@ namespace vcpkg
{
if (!result.is_user_requested_install()) continue;
auto bpgh = result.get_binary_paragraph();
assert(bpgh);
// If a package failed to build, don't attempt to print usage.
// e.g. --keep-going
if (!bpgh) continue;
Install::print_usage_information(*bpgh, printed_usages, fs, paths.installed());
}
}
Checks::exit_success(VCPKG_LINE_INFO);
Checks::exit_with_code(VCPKG_LINE_INFO, summary.failed());
}
void InstallCommand::perform_and_exit(const VcpkgCmdArguments& args,