Skip to content

Commit

Permalink
user_troubleshooting_message: Include git commit of the vcpkg repo an…
Browse files Browse the repository at this point in the history
…d suggest updating with `git pull`
  • Loading branch information
autoantwort committed Sep 19, 2021
1 parent 733e90d commit 4328535
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ 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 PackageSpec& spec);
std::string create_user_troubleshooting_message(const PackageSpec& spec, const VcpkgPaths& paths);

/// <summary>
/// Settings from the triplet file which impact the build environment and post-build checks
Expand Down
1 change: 1 addition & 0 deletions include/vcpkg/vcpkgpaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 8 additions & 4 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(spec), '\n');
print2(Build::create_user_troubleshooting_message(spec, paths), '\n');
return 1;
}

Expand Down Expand Up @@ -1315,22 +1315,26 @@ 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 PackageSpec& spec)
std::string create_user_troubleshooting_message(const PackageSpec& spec, const VcpkgPaths& paths)
{
#if defined(_WIN32)
auto vcpkg_update_cmd = ".\\vcpkg";
#else
auto vcpkg_update_cmd = "./vcpkg";
#endif
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-tool version: %s\n"
" Vcpkg version: %s\n"
"\n"
"Additionally, attach any relevant sections from the log files above.",
vcpkg_update_cmd,
spec,
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)
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,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.spec), '\n');
print2(Build::create_user_troubleshooting_message(action.spec, paths), '\n');
Checks::exit_fail(VCPKG_LINE_INFO);
}

Expand Down
19 changes: 19 additions & 0 deletions src/vcpkg/vcpkgpaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 4328535

Please sign in to comment.