Add internal option to clean packages\<port> after the build
MODIFY
include/vcpkg/build.h
include/vcpkg/build.h
@@ -44,6 +44,12 @@ namespace vcpkg::Build
YES
};
+ enum class CleanPackages
+ {
+ NO = 0,
+ YES
+ };
+
enum class ConfigurationType
{
DEBUG,
@@ -55,6 +61,7 @@ namespace vcpkg::Build
UseHeadVersion use_head_version;
AllowDownloads allow_downloads;
CleanBuildtrees clean_buildtrees;
+ CleanPackages clean_packages;
};
enum class BuildResult

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -61,8 +61,10 @@ namespace vcpkg::Build::Command
spec.name());
const StatusParagraphs status_db = database_load_check(paths);
- const Build::BuildPackageOptions build_package_options{
- Build::UseHeadVersion::NO, Build::AllowDownloads::YES, Build::CleanBuildtrees::NO};
+ const Build::BuildPackageOptions build_package_options{Build::UseHeadVersion::NO,
+ Build::AllowDownloads::YES,
+ Build::CleanBuildtrees::NO,
+ Build::CleanPackages::NO};
const std::unordered_set<std::string> features_as_set(full_spec.features.begin(), full_spec.features.end());
@@ -385,7 +387,7 @@ namespace vcpkg::Build
if (config.build_package_options.clean_buildtrees == CleanBuildtrees::YES)
{
auto& fs = paths.get_filesystem();
- auto buildtrees_dir = paths.buildtrees / config.scf.core_paragraph->name;
+ const fs::path buildtrees_dir = paths.buildtrees / config.scf.core_paragraph->name;
auto buildtree_files = fs.get_files_non_recursive(buildtrees_dir);
for (auto&& file : buildtree_files)
{
@@ -397,6 +399,16 @@ namespace vcpkg::Build
}
}
+ if (config.build_package_options.clean_packages == CleanPackages::YES)
+ {
+ auto& fs = paths.get_filesystem();
+ const PackageSpec spec = PackageSpec::from_name_and_triplet(config.scf.core_paragraph->name, config.triplet)
+ .value_or_exit(VCPKG_LINE_INFO);
+ const fs::path package_dir = paths.package_dir(spec);
+ std::error_code ec;
+ fs.remove_all(package_dir, ec);
+ }
+
return result;
}

MODIFY
src/vcpkg/commands.ci.cpp
src/vcpkg/commands.ci.cpp
@@ -24,17 +24,16 @@ namespace vcpkg::Commands::CI
{
Input::check_triplet(triplet, paths);
std::vector<PackageSpec> specs = PackageSpec::to_package_specs(ports, triplet);
- auto featurespecs = Util::fmap(specs, [](auto& spec) { return FeatureSpec(spec, ""); });
+ const auto featurespecs = Util::fmap(specs, [](auto& spec) { return FeatureSpec(spec, ""); });
StatusParagraphs status_db = database_load_check(paths);
const auto& paths_port_file = Dependencies::PathsPortFileProvider(paths);
auto action_plan = Dependencies::create_feature_install_plan(paths_port_file, featurespecs, status_db);
- const Build::BuildPackageOptions install_plan_options = {
- Build::UseHeadVersion::NO,
+ const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO,
Build::AllowDownloads::YES,
Build::CleanBuildtrees::YES,
- };
+ Build::CleanPackages::YES};
for (auto&& action : action_plan)
{

MODIFY
src/vcpkg/commands.upgrade.cpp
src/vcpkg/commands.upgrade.cpp
@@ -141,11 +141,10 @@ namespace vcpkg::Commands::Upgrade
Checks::check_exit(VCPKG_LINE_INFO, !plan.empty());
- const Build::BuildPackageOptions install_plan_options = {
- Build::UseHeadVersion::NO,
+ const Build::BuildPackageOptions install_plan_options = {Build::UseHeadVersion::NO,
Build::AllowDownloads::YES,
Build::CleanBuildtrees::NO,
- };
+ Build::CleanPackages::NO};
// Set build settings for all install actions
for (auto&& action : plan)

MODIFY
src/vcpkg/install.cpp
src/vcpkg/install.cpp
@@ -547,7 +547,7 @@ namespace vcpkg::Install
Util::Enum::to_enum<Build::UseHeadVersion>(use_head_version),
Util::Enum::to_enum<Build::AllowDownloads>(!no_downloads),
Build::CleanBuildtrees::NO,
- };
+ Build::CleanPackages::NO};
// Note: action_plan will hold raw pointers to SourceControlFiles from this map
std::vector<AnyAction> action_plan;

Add internal option to clean packages\<port> after the build