From 17623739df4796353d5eb4c9a2ec513c679022e0 Mon Sep 17 00:00:00 2001 From: Sean Warren Date: Thu, 23 May 2019 14:24:02 -0400 Subject: [PATCH] [toolsrc] Optionally allow vcpkg to clean after each build (#6522) * [toolsrc] Optionally allow vcpkg to clean packages, buildtrees and downloads after each build Adds switch --clean-after-build * [toolsrc] Clarify that --clean-after-build deletes downloads * [toolsrc] Revert changes to ci download caching behaviour --- toolsrc/include/vcpkg/build.h | 7 +++++++ toolsrc/src/vcpkg/build.cpp | 1 + toolsrc/src/vcpkg/commands.ci.cpp | 2 ++ toolsrc/src/vcpkg/commands.upgrade.cpp | 1 + toolsrc/src/vcpkg/export.cpp | 1 + toolsrc/src/vcpkg/install.cpp | 20 +++++++++++++++++--- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/toolsrc/include/vcpkg/build.h b/toolsrc/include/vcpkg/build.h index f27e9d67bf1..9044cb5566d 100644 --- a/toolsrc/include/vcpkg/build.h +++ b/toolsrc/include/vcpkg/build.h @@ -51,6 +51,12 @@ namespace vcpkg::Build YES }; + enum class CleanDownloads + { + NO = 0, + YES + }; + enum class ConfigurationType { DEBUG, @@ -82,6 +88,7 @@ namespace vcpkg::Build AllowDownloads allow_downloads; CleanBuildtrees clean_buildtrees; CleanPackages clean_packages; + CleanDownloads clean_downloads; DownloadTool download_tool; BinaryCaching binary_caching; FailOnTombstone fail_on_tombstone; diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp index c5f145052fa..1f28e9f30c2 100644 --- a/toolsrc/src/vcpkg/build.cpp +++ b/toolsrc/src/vcpkg/build.cpp @@ -70,6 +70,7 @@ namespace vcpkg::Build::Command Build::AllowDownloads::YES, Build::CleanBuildtrees::NO, Build::CleanPackages::NO, + Build::CleanDownloads::NO, Build::DownloadTool::BUILT_IN, GlobalState::g_binary_caching ? Build::BinaryCaching::YES : Build::BinaryCaching::NO, Build::FailOnTombstone::NO, diff --git a/toolsrc/src/vcpkg/commands.ci.cpp b/toolsrc/src/vcpkg/commands.ci.cpp index 10cb7d9fe71..4d31c4fbefd 100644 --- a/toolsrc/src/vcpkg/commands.ci.cpp +++ b/toolsrc/src/vcpkg/commands.ci.cpp @@ -229,6 +229,7 @@ namespace vcpkg::Commands::CI Build::AllowDownloads::YES, Build::CleanBuildtrees::YES, Build::CleanPackages::YES, + Build::CleanDownloads::NO, Build::DownloadTool::BUILT_IN, GlobalState::g_binary_caching ? Build::BinaryCaching::YES : Build::BinaryCaching::NO, Build::FailOnTombstone::YES, @@ -372,6 +373,7 @@ namespace vcpkg::Commands::CI Build::AllowDownloads::YES, Build::CleanBuildtrees::YES, Build::CleanPackages::YES, + Build::CleanDownloads::NO, Build::DownloadTool::BUILT_IN, GlobalState::g_binary_caching ? Build::BinaryCaching::YES : Build::BinaryCaching::NO, Build::FailOnTombstone::YES, diff --git a/toolsrc/src/vcpkg/commands.upgrade.cpp b/toolsrc/src/vcpkg/commands.upgrade.cpp index 29627db3da4..29815ca9490 100644 --- a/toolsrc/src/vcpkg/commands.upgrade.cpp +++ b/toolsrc/src/vcpkg/commands.upgrade.cpp @@ -155,6 +155,7 @@ namespace vcpkg::Commands::Upgrade Build::AllowDownloads::YES, Build::CleanBuildtrees::NO, Build::CleanPackages::NO, + Build::CleanDownloads::NO, Build::DownloadTool::BUILT_IN, GlobalState::g_binary_caching ? Build::BinaryCaching::YES : Build::BinaryCaching::NO, Build::FailOnTombstone::NO, diff --git a/toolsrc/src/vcpkg/export.cpp b/toolsrc/src/vcpkg/export.cpp index 870d2c49e84..f6a95b61fd3 100644 --- a/toolsrc/src/vcpkg/export.cpp +++ b/toolsrc/src/vcpkg/export.cpp @@ -75,6 +75,7 @@ namespace vcpkg::Export Build::AllowDownloads::YES, Build::CleanBuildtrees::NO, Build::CleanPackages::NO, + Build::CleanDownloads::NO, Build::DownloadTool::BUILT_IN, Build::BinaryCaching::NO, Build::FailOnTombstone::NO, diff --git a/toolsrc/src/vcpkg/install.cpp b/toolsrc/src/vcpkg/install.cpp index 6e7ad274dac..7fb304c17da 100644 --- a/toolsrc/src/vcpkg/install.cpp +++ b/toolsrc/src/vcpkg/install.cpp @@ -367,6 +367,16 @@ namespace vcpkg::Install fs.remove_all(package_dir, ec); } + if (action.build_options.clean_downloads == Build::CleanDownloads::YES) + { + auto& fs = paths.get_filesystem(); + const fs::path download_dir = paths.downloads; + std::error_code ec; + for(auto& p: fs.get_files_non_recursive(download_dir)) + if (!fs.is_directory(p)) + fs.remove(p); + } + return {code, std::move(bcf)}; } @@ -463,14 +473,16 @@ namespace vcpkg::Install static constexpr StringLiteral OPTION_KEEP_GOING = "--keep-going"; static constexpr StringLiteral OPTION_XUNIT = "--x-xunit"; static constexpr StringLiteral OPTION_USE_ARIA2 = "--x-use-aria2"; + static constexpr StringLiteral OPTION_CLEAN_AFTER_BUILD = "--clean-after-build"; - static constexpr std::array INSTALL_SWITCHES = {{ + static constexpr std::array INSTALL_SWITCHES = {{ {OPTION_DRY_RUN, "Do not actually build or install"}, {OPTION_USE_HEAD_VERSION, "Install the libraries on the command line using the latest upstream sources"}, {OPTION_NO_DOWNLOADS, "Do not download new sources"}, {OPTION_RECURSE, "Allow removal of packages as part of installation"}, {OPTION_KEEP_GOING, "Continue installing packages on failure"}, {OPTION_USE_ARIA2, "Use aria2 to perform download tasks"}, + {OPTION_CLEAN_AFTER_BUILD, "Clean buildtrees, packages and downloads after building each package"}, }}; static constexpr std::array INSTALL_SETTINGS = {{ {OPTION_XUNIT, "File to output results in XUnit format (Internal use)"}, @@ -623,6 +635,7 @@ namespace vcpkg::Install const bool no_downloads = Util::Sets::contains(options.switches, (OPTION_NO_DOWNLOADS)); const bool is_recursive = Util::Sets::contains(options.switches, (OPTION_RECURSE)); const bool use_aria2 = Util::Sets::contains(options.switches, (OPTION_USE_ARIA2)); + const bool clean_after_build = Util::Sets::contains(options.switches, (OPTION_CLEAN_AFTER_BUILD)); const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING)); // create the plan @@ -634,8 +647,9 @@ namespace vcpkg::Install const Build::BuildPackageOptions install_plan_options = { Util::Enum::to_enum(use_head_version), Util::Enum::to_enum(!no_downloads), - Build::CleanBuildtrees::NO, - Build::CleanPackages::NO, + clean_after_build ? Build::CleanBuildtrees::YES : Build::CleanBuildtrees::NO, + clean_after_build ? Build::CleanPackages::YES : Build::CleanPackages::NO, + clean_after_build ? Build::CleanDownloads::YES : Build::CleanDownloads::NO, download_tool, GlobalState::g_binary_caching ? Build::BinaryCaching::YES : Build::BinaryCaching::NO, Build::FailOnTombstone::NO,