Skip to content

Commit 20d0806

Browse files
Deduplicate 'already installed' / HEAD message. (#1683)
Improve console output when installing packages by deduplicating 'already installed' message, --head warning, and merging the 'green success' message into the total elapsed time part. Cherry picked from #1514 Co-authored-by: Robert Schumacher <[email protected]>
1 parent e4f8eff commit 20d0806

File tree

11 files changed

+128
-82
lines changed

11 files changed

+128
-82
lines changed

azure-pipelines/end-to-end-tests-dir/build-test-ports.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ The following packages are already installed:
6464

6565
$output = Run-VcpkgAndCaptureOutput @commonArgs --overlay-ports="$PSScriptRoot/../e2e-ports" install vcpkg-internal-e2e-test-port3 --head
6666
Throw-IfFailed
67-
if ($output -notmatch 'vcpkg-internal-e2e-test-port3:[^ ]+ is already installed -- not building from HEAD') {
68-
throw 'Wrong already installed message for --head'
69-
}
67+
Throw-IfNonContains -Expected @"
68+
The following packages are already installed, but were requested at --head version. Their installed contents will not be changed. To get updated versions, remove these packages first:
69+
vcpkg-internal-e2e-test-port3:$Triplet@1.0.0
70+
"@ -Actual $output
7071

7172
Refresh-TestRoot
7273
$output = Run-VcpkgAndCaptureOutput @commonArgs --x-builtin-ports-root="$PSScriptRoot/../e2e-ports" install vcpkg-bad-spdx-license

include/vcpkg/base/message-data.inc.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,9 @@ DECLARE_MESSAGE(AllFormatArgsUnbalancedBraces,
130130
(msg::value),
131131
"example of {value} is 'foo bar {'",
132132
"unbalanced brace in format string \"{value}\"")
133-
DECLARE_MESSAGE(AllPackagesAreUpdated, (), "", "All installed packages are up-to-date.")
133+
DECLARE_MESSAGE(AllPackagesAreUpdated, (), "", "No action taken because all installed packages are up-to-date.")
134134
DECLARE_MESSAGE(AllShasValid, (), "sha = sha512 of url", "All checked sha's are valid.")
135135
DECLARE_MESSAGE(AlreadyInstalled, (msg::spec), "", "{spec} is already installed")
136-
DECLARE_MESSAGE(AlreadyInstalledNotHead,
137-
(msg::spec),
138-
"'HEAD' means the most recent version of source code",
139-
"{spec} is already installed -- not building from HEAD")
140136
DECLARE_MESSAGE(AManifest, (), "", "a manifest")
141137
DECLARE_MESSAGE(AMaximumOfOneAssetReadUrlCanBeSpecified, (), "", "a maximum of one asset read url can be specified.")
142138
DECLARE_MESSAGE(AMaximumOfOneAssetWriteUrlCanBeSpecified, (), "", "a maximum of one asset write url can be specified.")
@@ -1787,6 +1783,11 @@ DECLARE_MESSAGE(InstallCopiedFile,
17871783
"{path_source} -> {path_destination} done")
17881784
DECLARE_MESSAGE(InstalledBy, (msg::path), "", "Installed by {path}")
17891785
DECLARE_MESSAGE(InstalledPackages, (), "", "The following packages are already installed:")
1786+
DECLARE_MESSAGE(InstalledPackagesHead,
1787+
(),
1788+
"",
1789+
"The following packages are already installed, but were requested at --head version. Their installed "
1790+
"contents will not be changed. To get updated versions, remove these packages first:")
17901791
DECLARE_MESSAGE(InstalledRequestedPackages, (), "", "All requested packages are currently installed.")
17911792
DECLARE_MESSAGE(InstallFailed, (msg::path, msg::error_msg), "", "failed: {path}: {error_msg}")
17921793
DECLARE_MESSAGE(InstallingFromFilesystemRegistry, (), "", "installing from filesystem registry here")
@@ -2812,6 +2813,10 @@ DECLARE_MESSAGE(ToRemovePackages,
28122813
"",
28132814
"To only remove outdated packages, run\n{command_name} remove --outdated")
28142815
DECLARE_MESSAGE(TotalInstallTime, (msg::elapsed), "", "Total install time: {elapsed}")
2816+
DECLARE_MESSAGE(TotalInstallTimeSuccess,
2817+
(msg::elapsed),
2818+
"",
2819+
"All requested installations completed successfully in: {elapsed}")
28152820
DECLARE_MESSAGE(ToUpdatePackages,
28162821
(msg::command_name),
28172822
"",

include/vcpkg/commands.install.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ namespace vcpkg
4949
{
5050
std::vector<SpecSummary> results;
5151
ElapsedTime elapsed;
52+
bool failed = false;
5253

53-
LocalizedString format() const;
54+
LocalizedString format_results() const;
5455
void print_failed() const;
55-
std::string xunit_results() const;
56-
bool failed() const;
56+
void print_complete_message() const;
5757
};
5858

5959
struct InstallDir

include/vcpkg/dependencies.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ namespace vcpkg
208208
struct FormattedPlan
209209
{
210210
bool has_removals = false;
211-
LocalizedString text;
211+
LocalizedString warning_text;
212+
LocalizedString normal_text;
213+
214+
LocalizedString all_text() const;
212215
};
213216

214217
FormattedPlan format_plan(const ActionPlan& action_plan);

locales/messages.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,11 @@
114114
"_AllFormatArgsRawArgument.comment": "example of {value} is 'foo {} bar'",
115115
"AllFormatArgsUnbalancedBraces": "unbalanced brace in format string \"{value}\"",
116116
"_AllFormatArgsUnbalancedBraces.comment": "example of {value} is 'foo bar {'",
117-
"AllPackagesAreUpdated": "All installed packages are up-to-date.",
117+
"AllPackagesAreUpdated": "No action taken because all installed packages are up-to-date.",
118118
"AllShasValid": "All checked sha's are valid.",
119119
"_AllShasValid.comment": "sha = sha512 of url",
120120
"AlreadyInstalled": "{spec} is already installed",
121121
"_AlreadyInstalled.comment": "An example of {spec} is zlib:x64-windows.",
122-
"AlreadyInstalledNotHead": "{spec} is already installed -- not building from HEAD",
123-
"_AlreadyInstalledNotHead.comment": "'HEAD' means the most recent version of source code An example of {spec} is zlib:x64-windows.",
124122
"AmbiguousConfigDeleteConfigFile": "Ambiguous vcpkg configuration provided by both manifest and configuration file.\n-- Delete configuration file {path}",
125123
"_AmbiguousConfigDeleteConfigFile.comment": "An example of {path} is /foo/bar.",
126124
"AnArrayOfDefaultFeatures": "an array of default features",
@@ -1003,6 +1001,7 @@
10031001
"InstalledBy": "Installed by {path}",
10041002
"_InstalledBy.comment": "An example of {path} is /foo/bar.",
10051003
"InstalledPackages": "The following packages are already installed:",
1004+
"InstalledPackagesHead": "The following packages are already installed, but were requested at --head version. Their installed contents will not be changed. To get updated versions, remove these packages first:",
10061005
"InstalledRequestedPackages": "All requested packages are currently installed.",
10071006
"InstallingFromFilesystemRegistry": "installing from filesystem registry here",
10081007
"InstallingFromGitRegistry": "installing from git registry",
@@ -1486,6 +1485,8 @@
14861485
"_ToolOfVersionXNotFound.comment": "An example of {tool_name} is signtool. An example of {version} is 1.3.8.",
14871486
"TotalInstallTime": "Total install time: {elapsed}",
14881487
"_TotalInstallTime.comment": "An example of {elapsed} is 3.532 min.",
1488+
"TotalInstallTimeSuccess": "All requested installations completed successfully in: {elapsed}",
1489+
"_TotalInstallTimeSuccess.comment": "An example of {elapsed} is 3.532 min.",
14891490
"TrailingCommaInArray": "Trailing comma in array",
14901491
"TrailingCommaInObj": "Trailing comma in an object",
14911492
"TripletFileNotFound": "Triplet file {triplet}.cmake not found",

src/vcpkg-test/dependencies.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2444,41 +2444,41 @@ TEST_CASE ("formatting plan 1", "[dependencies]")
24442444
{
24452445
auto formatted = format_plan(plan);
24462446
CHECK_FALSE(formatted.has_removals);
2447-
CHECK(formatted.text == "All requested packages are currently installed.\n");
2447+
CHECK(formatted.all_text() == "All requested packages are currently installed.\n");
24482448
}
24492449

24502450
plan.remove_actions.push_back(remove_b);
24512451
{
24522452
auto formatted = format_plan(plan);
24532453
CHECK(formatted.has_removals);
2454-
CHECK(formatted.text == "The following packages will be removed:\n"
2455-
" b:x64-osx\n");
2454+
CHECK(formatted.all_text() == "The following packages will be removed:\n"
2455+
" b:x64-osx\n");
24562456
}
24572457

24582458
plan.remove_actions.push_back(remove_a);
2459-
REQUIRE_LINES(format_plan(plan).text,
2459+
REQUIRE_LINES(format_plan(plan).all_text(),
24602460
"The following packages will be removed:\n"
24612461
" a:x64-osx\n"
24622462
" b:x64-osx\n");
24632463

24642464
plan.install_actions.push_back(std::move(install_c));
2465-
REQUIRE_LINES(format_plan(plan).text,
2465+
REQUIRE_LINES(format_plan(plan).all_text(),
24662466
"The following packages will be removed:\n"
24672467
" a:x64-osx\n"
24682468
" b:x64-osx\n"
24692469
"The following packages will be built and installed:\n"
24702470
" c:x64-osx@1 -- c\n");
24712471

24722472
plan.remove_actions.push_back(remove_c);
2473-
REQUIRE_LINES(format_plan(plan).text,
2473+
REQUIRE_LINES(format_plan(plan).all_text(),
24742474
"The following packages will be removed:\n"
24752475
" a:x64-osx\n"
24762476
" b:x64-osx\n"
24772477
"The following packages will be rebuilt:\n"
24782478
" c:x64-osx@1 -- c\n");
24792479

24802480
plan.install_actions.push_back(std::move(install_b));
2481-
REQUIRE_LINES(format_plan(plan).text,
2481+
REQUIRE_LINES(format_plan(plan).all_text(),
24822482
"The following packages will be removed:\n"
24832483
" a:x64-osx\n"
24842484
"The following packages will be rebuilt:\n"
@@ -2492,7 +2492,7 @@ TEST_CASE ("formatting plan 1", "[dependencies]")
24922492
{
24932493
auto formatted = format_plan(plan);
24942494
CHECK(formatted.has_removals);
2495-
REQUIRE_LINES(formatted.text,
2495+
REQUIRE_LINES(formatted.all_text(),
24962496
"The following packages are already installed:\n"
24972497
" * d:x86-windows@1\n"
24982498
" e:x86-windows@1\n"
@@ -2504,7 +2504,7 @@ TEST_CASE ("formatting plan 1", "[dependencies]")
25042504
}
25052505

25062506
plan.install_actions.push_back(std::move(install_f));
2507-
REQUIRE_LINES(format_plan(plan).text,
2507+
REQUIRE_LINES(format_plan(plan).all_text(),
25082508
"The following packages are excluded:\n"
25092509
" f:x64-osx@1 -- git+https://github.com/microsoft/vcpkg:f54a99d43e600ceea175205850560f6dd37ea6cf\n"
25102510
"The following packages are already installed:\n"

src/vcpkg/commands.ci.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ namespace vcpkg
513513
.append_raw(' ')
514514
.append_raw(target_triplet)
515515
.append_raw('\n')
516-
.append(summary.format()));
516+
.append(summary.format_results()));
517517
const bool any_regressions = print_regressions(summary.results,
518518
split_specs->known,
519519
cidata,

src/vcpkg/commands.install.cpp

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,6 @@ namespace vcpkg
330330
const InstallPlanType& plan_type = action.plan_type;
331331
if (plan_type == InstallPlanType::ALREADY_INSTALLED)
332332
{
333-
if (action.use_head_version == UseHeadVersion::Yes)
334-
msg::println(Color::warning, msgAlreadyInstalledNotHead, msg::spec = action.spec);
335-
else
336-
msg::println(Color::success, msgAlreadyInstalled, msg::spec = action.spec);
337333
return ExtendedBuildResult{BuildResult::Succeeded};
338334
}
339335

@@ -438,7 +434,7 @@ namespace vcpkg
438434
.append_raw(result.timing.to_string());
439435
}
440436

441-
LocalizedString InstallSummary::format() const
437+
LocalizedString InstallSummary::format_results() const
442438
{
443439
LocalizedString to_print;
444440
to_print.append(msgResultsHeader).append_raw('\n');
@@ -478,26 +474,16 @@ namespace vcpkg
478474
msg::print(output);
479475
}
480476

481-
bool InstallSummary::failed() const
477+
void InstallSummary::print_complete_message() const
482478
{
483-
for (const auto& result : this->results)
479+
if (failed)
484480
{
485-
switch (result.build_result.value_or_exit(VCPKG_LINE_INFO).code)
486-
{
487-
case BuildResult::Succeeded:
488-
case BuildResult::Removed:
489-
case BuildResult::Downloaded:
490-
case BuildResult::Excluded: continue;
491-
case BuildResult::BuildFailed:
492-
case BuildResult::PostBuildChecksFailed:
493-
case BuildResult::FileConflicts:
494-
case BuildResult::CascadedDueToMissingDependencies:
495-
case BuildResult::CacheMissing: return true;
496-
default: Checks::unreachable(VCPKG_LINE_INFO);
497-
}
481+
msg::println(msgTotalInstallTime, msg::elapsed = elapsed);
482+
}
483+
else
484+
{
485+
msg::println(Color::success, msgTotalInstallTimeSuccess, msg::elapsed = elapsed);
498486
}
499-
500-
return false;
501487
}
502488

503489
struct TrackedPackageInstallGuard
@@ -580,29 +566,29 @@ namespace vcpkg
580566
const IBuildLogsRecorder& build_logs_recorder,
581567
bool include_manifest_in_github_issue)
582568
{
583-
const ElapsedTimer timer;
584-
std::vector<SpecSummary> results;
569+
ElapsedTimer timer;
570+
InstallSummary summary;
585571
const size_t action_count = action_plan.remove_actions.size() + action_plan.install_actions.size();
586572
size_t action_index = 1;
587573

588574
auto& fs = paths.get_filesystem();
589575
for (auto&& action : action_plan.remove_actions)
590576
{
591-
TrackedPackageInstallGuard this_install(action_index++, action_count, results, action);
577+
TrackedPackageInstallGuard this_install(action_index++, action_count, summary.results, action);
592578
remove_package(fs, paths.installed(), action.spec, status_db);
593-
results.back().build_result.emplace(BuildResult::Removed);
579+
summary.results.back().build_result.emplace(BuildResult::Removed);
594580
}
595581

596582
for (auto&& action : action_plan.already_installed)
597583
{
598-
results.emplace_back(action).build_result.emplace(perform_install_plan_action(
584+
summary.results.emplace_back(action).build_result.emplace(perform_install_plan_action(
599585
args, paths, host_triplet, build_options, action, status_db, binary_cache, build_logs_recorder));
600586
}
601587

602588
for (auto&& action : action_plan.install_actions)
603589
{
604590
binary_cache.print_updates();
605-
TrackedPackageInstallGuard this_install(action_index++, action_count, results, action);
591+
TrackedPackageInstallGuard this_install(action_index++, action_count, summary.results, action);
606592
auto result = perform_install_plan_action(
607593
args, paths, host_triplet, build_options, action, status_db, binary_cache, build_logs_recorder);
608594
if (result.code != BuildResult::Succeeded && build_options.keep_going == KeepGoing::No)
@@ -625,11 +611,25 @@ namespace vcpkg
625611
Checks::exit_fail(VCPKG_LINE_INFO);
626612
}
627613

614+
switch (result.code)
615+
{
616+
case BuildResult::Succeeded:
617+
case BuildResult::Removed:
618+
case BuildResult::Downloaded:
619+
case BuildResult::Excluded: break;
620+
case BuildResult::BuildFailed:
621+
case BuildResult::PostBuildChecksFailed:
622+
case BuildResult::FileConflicts:
623+
case BuildResult::CascadedDueToMissingDependencies:
624+
case BuildResult::CacheMissing: summary.failed = true; break;
625+
default: Checks::unreachable(VCPKG_LINE_INFO);
626+
}
628627
this_install.current_summary.build_result.emplace(std::move(result));
629628
}
630629

631630
database_load_collapse(fs, paths.installed());
632-
return InstallSummary{std::move(results), timer.elapsed()};
631+
summary.elapsed = timer.elapsed();
632+
return summary;
633633
}
634634

635635
static constexpr CommandSwitch INSTALL_SWITCHES[] = {
@@ -1384,7 +1384,7 @@ namespace vcpkg
13841384
// success.
13851385
if (keep_going == KeepGoing::Yes)
13861386
{
1387-
msg::print(summary.format());
1387+
msg::print(summary.format_results());
13881388
}
13891389

13901390
auto it_xunit = options.settings.find(SwitchXXUnit);
@@ -1419,7 +1419,8 @@ namespace vcpkg
14191419
}
14201420
}
14211421
binary_cache.wait_for_async_complete_and_join();
1422-
Checks::exit_with_code(VCPKG_LINE_INFO, summary.failed());
1422+
summary.print_complete_message();
1423+
Checks::exit_with_code(VCPKG_LINE_INFO, summary.failed);
14231424
}
14241425

14251426
SpecSummary::SpecSummary(const InstallPlanAction& action)

src/vcpkg/commands.set-installed.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,19 @@ namespace vcpkg
168168
specs_installed.erase(action.spec);
169169
}
170170

171-
Util::erase_remove_if(action_plan.install_actions, [&](const InstallPlanAction& ipa) {
172-
return Util::Sets::contains(specs_installed, ipa.spec);
171+
Util::erase_remove_if(action_plan.install_actions, [&](InstallPlanAction& ipa) {
172+
if (Util::Sets::contains(specs_installed, ipa.spec))
173+
{
174+
// convert the 'to install' entry to an already installed entry
175+
ipa.installed_package = status_db.get_installed_package_view(ipa.spec);
176+
ipa.plan_type = InstallPlanType::ALREADY_INSTALLED;
177+
action_plan.already_installed.push_back(std::move(ipa));
178+
return true;
179+
}
180+
181+
return false;
173182
});
183+
174184
return specs_installed;
175185
}
176186

@@ -269,8 +279,7 @@ namespace vcpkg
269279
null_build_logs_recorder,
270280
include_manifest_in_github_issue);
271281

272-
msg::println(msgTotalInstallTime, msg::elapsed = summary.elapsed);
273-
if (build_options.keep_going == KeepGoing::Yes && summary.failed())
282+
if (build_options.keep_going == KeepGoing::Yes && summary.failed)
274283
{
275284
summary.print_failed();
276285
if (build_options.only_downloads == OnlyDownloads::No)
@@ -308,6 +317,7 @@ namespace vcpkg
308317
}
309318

310319
binary_cache.wait_for_async_complete_and_join();
320+
summary.print_complete_message();
311321
Checks::exit_success(VCPKG_LINE_INFO);
312322
}
313323

src/vcpkg/commands.upgrade.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,11 @@ namespace vcpkg
216216
msg::println(msgTotalInstallTime, msg::elapsed = summary.elapsed);
217217
if (keep_going == KeepGoing::Yes)
218218
{
219-
msg::print(summary.format());
219+
msg::print(summary.format_results());
220220
}
221221

222222
binary_cache.wait_for_async_complete_and_join();
223+
summary.print_complete_message();
223224
Checks::exit_success(VCPKG_LINE_INFO);
224225
}
225226
} // namespace vcpkg

0 commit comments

Comments
 (0)