user_troubleshooting_message: Include git commit of the vcpkg repo and suggest updating with `git pull`
MODIFY
include/vcpkg/build.h
include/vcpkg/build.h
@@ -205,7 +205,8 @@ namespace vcpkg::Build
const std::string& to_string(const BuildResult build_result);
std::string create_error_message(const BuildResult build_result, const PackageSpec& spec);
- std::string create_user_troubleshooting_message(const Dependencies::InstallPlanAction& action);
+ std::string create_user_troubleshooting_message(const Dependencies::InstallPlanAction& action,
+ const VcpkgPaths& paths);
/// <summary>
/// Settings from the triplet file which impact the build environment and post-build checks

MODIFY
include/vcpkg/vcpkgpaths.h
include/vcpkg/vcpkgpaths.h
@@ -135,6 +135,7 @@ namespace vcpkg
ExpectedS<Path> git_checkout_baseline(StringView commit_sha) const;
ExpectedS<Path> git_checkout_port(StringView port_name, StringView git_tree, const Path& dot_git_dir) const;
ExpectedS<std::string> git_show(const std::string& treeish, const Path& dot_git_dir) const;
+ ExpectedS<std::string> git_describe_head() const;
const Downloads::DownloadManager& get_download_manager() const;

MODIFY
src/vcpkg/build.cpp
src/vcpkg/build.cpp
@@ -163,7 +163,7 @@ namespace vcpkg::Build
if (result.code != BuildResult::SUCCEEDED)
{
print2(Color::error, Build::create_error_message(result.code, spec), '\n');
- print2(Build::create_user_troubleshooting_message(*action), '\n');
+ print2(Build::create_user_troubleshooting_message(*action, paths), '\n');
return 1;
}
@@ -1315,7 +1315,7 @@ namespace vcpkg::Build
return Strings::format("Error: Building package %s failed with: %s", spec, Build::to_string(build_result));
}
- std::string create_user_troubleshooting_message(const InstallPlanAction& action)
+ std::string create_user_troubleshooting_message(const InstallPlanAction& action, const VcpkgPaths& paths)
{
#if defined(_WIN32)
auto vcpkg_update_cmd = ".\\vcpkg";
@@ -1328,16 +1328,19 @@ namespace vcpkg::Build
{
Strings::append(package, " -> ", scfl->to_versiont());
}
-
- return Strings::format("Please ensure you're using the latest portfiles with `%s update`, then\n"
+ auto description = paths.git_describe_head();
+ return Strings::format("Please ensure you're using the latest portfiles with `git pull` and `%s update`, then\n"
"submit an issue at https://github.com/Microsoft/vcpkg/issues including:\n"
- " Package: %s\n"
- " Vcpkg version: %s\n"
+ " package: %s\n"
+ " vcpkg version: %s\n"
+ " vcpkg-tool version: %s\n"
"\n"
"Additionally, attach any relevant sections from the log files above.",
vcpkg_update_cmd,
package,
- Commands::Version::version());
+ Commands::Version::version(),
+ description.has_value() ? description.value_or_exit(VCPKG_LINE_INFO)
+ : "Failed to get HEAD: " + description.error());
}
static BuildInfo inner_create_buildinfo(Parse::Paragraph pgh)

MODIFY
src/vcpkg/install.cpp
src/vcpkg/install.cpp
@@ -494,7 +494,7 @@ namespace vcpkg::Install
perform_install_plan_action(args, paths, action, status_db, binary_cache, build_logs_recorder);
if (result.code != BuildResult::SUCCEEDED && keep_going == KeepGoing::NO)
{
- print2(Build::create_user_troubleshooting_message(action), '\n');
+ print2(Build::create_user_troubleshooting_message(action, paths), '\n');
Checks::exit_fail(VCPKG_LINE_INFO);
}

MODIFY
src/vcpkg/vcpkgpaths.cpp
src/vcpkg/vcpkgpaths.cpp
@@ -661,6 +661,25 @@ namespace vcpkg
}
}
+ ExpectedS<std::string> VcpkgPaths::git_describe_head() const
+ {
+ // All git commands are run with: --git-dir={dot_git_dir} --work-tree={work_tree_temp}
+ const auto dot_git_dir = root / ".git";
+ Command showcmd = git_cmd_builder(dot_git_dir, dot_git_dir)
+ .string_arg("show")
+ .string_arg("--pretty=format:%h %cd (%cr)")
+ .string_arg("-s")
+ .string_arg("--date=short")
+ .string_arg("HEAD");
+
+ auto output = cmd_execute_and_capture_output(showcmd);
+ if (output.exit_code == 0)
+ {
+ return {std::move(output.output), expected_left_tag};
+ }
+ return {std::move(output.output), expected_right_tag};
+ }
+
ExpectedS<std::map<std::string, std::string, std::less<>>> VcpkgPaths::git_get_local_port_treeish_map() const
{
const auto local_repo = this->root / ".git";

user_troubleshooting_message: Include git commit of the vcpkg repo and suggest updating with `git pull` (#197)