[vcpkg] Add support for installing from HEAD
MODIFY
include/vcpkg_Build.h
include/vcpkg_Build.h
#include "StatusParagraphs.h"
#include "VcpkgPaths.h"
#include "vcpkg_Files.h"
+#include "vcpkg_optional.h"
#include <map>
#include <string>
#include <unordered_map>
@@ -50,6 +51,9 @@ namespace vcpkg::Build
const SourceParagraph& src;
const Triplet& triplet;
fs::path port_dir;
+
+ bool use_head_version;
+ bool no_downloads;
};
ExtendedBuildResult build_package(const VcpkgPaths& paths,
@@ -63,6 +67,8 @@ namespace vcpkg::Build
PostBuildLint::LinkageType crt_linkage;
PostBuildLint::LinkageType library_linkage;
+ Optional<std::string> version;
+
std::map<PostBuildLint::BuildPolicies, bool> policies;
};

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -265,6 +265,8 @@ namespace vcpkg::Commands::Install
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths, const Triplet& default_triplet)
{
static const std::string OPTION_DRY_RUN = "--dry-run";
+ static const std::string OPTION_USE_HEAD_VERSION = "--head";
+ static const std::string OPTION_NO_DOWNLOADS = "--no-downloads";
// input sanitization
static const std::string example =
@@ -277,8 +279,11 @@ namespace vcpkg::Commands::Install
for (auto&& spec : specs)
Input::check_triplet(spec.triplet(), paths);
- const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments({OPTION_DRY_RUN});
+ const std::unordered_set<std::string> options = args.check_and_get_optional_command_arguments(
+ {OPTION_DRY_RUN, OPTION_USE_HEAD_VERSION, OPTION_NO_DOWNLOADS});
const bool dryRun = options.find(OPTION_DRY_RUN) != options.cend();
+ const bool use_head_version = options.find(OPTION_USE_HEAD_VERSION) != options.cend();
+ const bool no_downloads = options.find(OPTION_NO_DOWNLOADS) != options.cend();
// create the plan
StatusParagraphs status_db = database_load_check(paths);
@@ -319,17 +324,34 @@ namespace vcpkg::Commands::Install
switch (action.plan_type)
{
case InstallPlanType::ALREADY_INSTALLED:
+ if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
+ {
+ System::println(System::Color::warning,
+ "Package %s is already installed -- not building from HEAD",
+ display_name);
+ }
+ else
+ {
System::println(System::Color::success, "Package %s is already installed", display_name);
+ }
break;
case InstallPlanType::BUILD_AND_INSTALL:
{
- System::println("Building package %s... ", display_name);
Build::BuildPackageConfig build_config{
action.any_paragraph.source_paragraph.value_or_exit(VCPKG_LINE_INFO),
action.spec.triplet(),
paths.port_dir(action.spec),
};
+ build_config.use_head_version =
+ use_head_version && action.request_type == RequestType::USER_REQUESTED;
+ build_config.no_downloads = no_downloads;
+
+ if (build_config.use_head_version)
+ System::println("Building package %s from HEAD... ", display_name);
+ else
+ System::println("Building package %s... ", display_name);
+
const auto result = Build::build_package(paths, build_config, status_db);
if (result.code != Build::BuildResult::SUCCEEDED)
{
@@ -348,6 +370,12 @@ namespace vcpkg::Commands::Install
break;
}
case InstallPlanType::INSTALL:
+ if (use_head_version && action.request_type == RequestType::USER_REQUESTED)
+ {
+ System::println(System::Color::warning,
+ "Package %s is already built -- not building from HEAD",
+ display_name);
+ }
System::println("Installing package %s... ", display_name);
install_package(
paths, action.any_paragraph.binary_paragraph.value_or_exit(VCPKG_LINE_INFO), &status_db);

MODIFY
src/vcpkg_Build.cpp
src/vcpkg_Build.cpp
@@ -43,7 +43,11 @@ namespace vcpkg::Build
const Triplet& triplet,
const BuildInfo& build_info)
{
- const BinaryParagraph bpgh = BinaryParagraph(source_paragraph, triplet);
+ BinaryParagraph bpgh = BinaryParagraph(source_paragraph, triplet);
+ if (auto p_ver = build_info.version.get())
+ {
+ bpgh.version = *p_ver;
+ }
const fs::path binary_control_file = paths.packages / bpgh.dir() / "CONTROL";
paths.get_filesystem().write_contents(binary_control_file, Strings::serialize(bpgh));
}
@@ -88,6 +92,8 @@ namespace vcpkg::Build
{L"CURRENT_PORT_DIR", config.port_dir / "/."},
{L"TARGET_TRIPLET", triplet.canonical_name()},
{L"VCPKG_PLATFORM_TOOLSET", toolset.version},
+ {L"VCPKG_USE_HEAD_VERSION", config.use_head_version ? L"1" : L"0"},
+ {L"_VCPKG_NO_DOWNLOADS", config.no_downloads ? L"1" : L"0"},
{L"GIT", git_exe_path}});
const std::wstring command = Strings::wformat(LR"(%s && %s)", cmd_set_environment, cmd_launch_cmake);
@@ -177,6 +183,13 @@ namespace vcpkg::Build
"Invalid library linkage type: [%s]",
library_linkage_as_string);
+ auto it_version = pgh.find("Version");
+ if (it_version != pgh.end())
+ {
+ build_info.version = it_version->second;
+ pgh.erase(it_version);
+ }
+
// The remaining entries are policies
for (const std::unordered_map<std::string, std::string>::value_type& p : pgh)
{

[vcpkg] Add support for installing from HEAD