build_package() modified to return the result of the build
MODIFY
include/PostBuildLint.h
include/PostBuildLint.h
namespace vcpkg::PostBuildLint
{
- void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths);
+ size_t perform_all_checks(const package_spec& spec, const vcpkg_paths& paths);
}

MODIFY
include/vcpkg_Commands.h
include/vcpkg_Commands.h
@@ -11,7 +11,16 @@ namespace vcpkg::Commands
namespace Build
{
- void build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir);
+ enum class BuildResult
+ {
+ BUILD_NOT_STARTED = 0,
+ SUCCESS,
+ CASCADED_DUE_TO_MISSING_DEPENDENCIES,
+ BUILD_FAILED,
+ POST_BUILD_CHECKS_FAILED,
+ };
+
+ BuildResult build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir);
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet);
}

MODIFY
src/PostBuildLint.cpp
src/PostBuildLint.cpp
@@ -619,6 +619,7 @@ namespace vcpkg::PostBuildLint
left += static_cast<size_t>(right);
}
+
static size_t perform_all_checks_and_return_error_count(const package_spec& spec, const vcpkg_paths& paths)
{
const fs::path dumpbin_exe = Environment::get_dumpbin_exe(paths);
@@ -710,19 +711,18 @@ namespace vcpkg::PostBuildLint
return error_count;
}
- void perform_all_checks(const package_spec& spec, const vcpkg_paths& paths)
+ size_t perform_all_checks(const package_spec& spec, const vcpkg_paths& paths)
{
System::println("-- Performing post-build validation");
-
const size_t error_count = perform_all_checks_and_return_error_count(spec, paths);
+ System::println("-- Performing post-build validation done");
if (error_count != 0)
{
const fs::path portfile = paths.ports / spec.name() / "portfile.cmake";
System::println(System::color::error, "Found %u error(s). Please correct the portfile:\n %s", error_count, portfile.string());
- exit(EXIT_FAILURE);
}
- System::println("-- Performing post-build validation done");
+ return error_count;
}
}

MODIFY
src/commands_build.cpp
src/commands_build.cpp
#include "vcpkg_Environment.h"
#include "metrics.h"
#include "vcpkg_info.h"
+#include "vcpkg_Enums.h"
namespace vcpkg::Commands::Build
{
@@ -24,7 +25,7 @@ namespace vcpkg::Commands::Build
std::ofstream(binary_control_file) << bpgh;
}
- void build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir)
+ BuildResult build_package(const SourceParagraph& source_paragraph, const package_spec& spec, const vcpkg_paths& paths, const fs::path& port_dir)
{
Checks::check_exit(spec.name() == source_paragraph.name, "inconsistent arguments to build_internal()");
const triplet& target_triplet = spec.target_triplet();
@@ -58,15 +59,22 @@ namespace vcpkg::Commands::Build
, spec.toString(), Info::version());
TrackProperty("error", "build failed");
TrackProperty("build_error", spec.toString());
- exit(EXIT_FAILURE);
+ return BuildResult::BUILD_FAILED;
}
- PostBuildLint::perform_all_checks(spec, paths);
+ const size_t error_count = PostBuildLint::perform_all_checks(spec, paths);
+
+ if (error_count != 0)
+ {
+ return BuildResult::POST_BUILD_CHECKS_FAILED;
+ }
create_binary_control_file(paths, source_paragraph, target_triplet);
// const fs::path port_buildtrees_dir = paths.buildtrees / spec.name;
// delete_directory(port_buildtrees_dir);
+
+ return BuildResult::SUCCESS;
}
void perform_and_exit(const vcpkg_cmd_arguments& args, const vcpkg_paths& paths, const triplet& default_target_triplet)
@@ -86,7 +94,11 @@ namespace vcpkg::Commands::Build
const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_CHECKS_ONLY});
if (options.find(OPTION_CHECKS_ONLY) != options.end())
{
- PostBuildLint::perform_all_checks(spec, paths);
+ const size_t error_count = PostBuildLint::perform_all_checks(spec, paths);
+ if (error_count > 0)
+ {
+ exit(EXIT_FAILURE);
+ }
exit(EXIT_SUCCESS);
}
@@ -125,7 +137,12 @@ namespace vcpkg::Commands::Build
}
Environment::ensure_utilities_on_path(paths);
- build_package(spgh, spec, paths, paths.port_dir(spec));
+ const BuildResult result = build_package(spgh, spec, paths, paths.port_dir(spec));
+ if (result != BuildResult::SUCCESS)
+ {
+ exit(EXIT_FAILURE);
+ }
+
exit(EXIT_SUCCESS);
}
}

MODIFY
src/commands_build_external.cpp
src/commands_build_external.cpp
@@ -21,7 +21,12 @@ namespace vcpkg::Commands::BuildExternal
const expected<SourceParagraph> maybe_spgh = try_load_port(port_dir);
if (auto spgh = maybe_spgh.get())
{
- Commands::Build::build_package(*spgh, *spec, paths, port_dir);
+ const Build::BuildResult result = Commands::Build::build_package(*spgh, *spec, paths, port_dir);
+ if (result !=Build::BuildResult::SUCCESS)
+ {
+ exit(EXIT_FAILURE);
+ }
+
exit(EXIT_SUCCESS);
}
}

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -214,7 +214,11 @@ namespace vcpkg::Commands::Install
}
else if (action.plan.plan_type == install_plan_type::BUILD_AND_INSTALL)
{
- Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec));
+ const Build::BuildResult result = Commands::Build::build_package(*action.plan.source_pgh, action.spec, paths, paths.port_dir(action.spec));
+ if (result != Build::BuildResult::SUCCESS)
+ {
+ exit(EXIT_FAILURE);
+ }
const BinaryParagraph bpgh = try_load_cached_package(paths, action.spec).get_or_throw();
install_package(paths, bpgh, &status_db);
System::println(System::color::success, "Package %s is installed", action.spec);

build_package() modified to return the result of the build