Skip to content

Commit

Permalink
Fix "build" for already installed ports. (microsoft#492)
Browse files Browse the repository at this point in the history
* Fix "build" for already installed ports.

Resolves microsoft/vcpkg#13933

Rather than attempting to deal with the condition that the plan created thinks the thing we want to build is already installed, this version just "removes" the thing we want to build from the in-memory status database before creating the plan.

* clang-format

* Change the condition to be an error instead of trying to make it work.

* Localize some more build stuff.

* Fix error message searches.

* Robert CRs.

* Fix dependences => dependencies typo.
  • Loading branch information
BillyONeal authored Apr 12, 2022
1 parent f92f59b commit 52dc46e
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 110 deletions.
31 changes: 31 additions & 0 deletions azure-pipelines/end-to-end-tests-dir/build-command.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
. $PSScriptRoot/../end-to-end-tests-prelude.ps1

$CurrentTest = "Build Command"

# Test that the build command fails if dependencies are missing
$out = (Run-Vcpkg -TestArgs ($commonArgs + @("build","vcpkg-hello-world-1","--host-triplet",$Triplet)) | Out-String)
Throw-IfNotFailed
if ($out -notmatch "The build command requires all dependencies to be already installed\.")
{
$out
throw "Expected to fail due to missing dependencies"
}

# Install the dependencies of vcpkg-hello-world-1
Run-Vcpkg -TestArgs ($commonArgs + @("install","vcpkg-cmake","vcpkg-cmake-config","--host-triplet",$Triplet))
Throw-IfFailed

# Test that the build command works
Run-Vcpkg -TestArgs ($commonArgs + @("build","vcpkg-hello-world-1","--host-triplet",$Triplet))
Throw-IfFailed

# Regression test https://github.com/microsoft/vcpkg/issues/13933
Run-Vcpkg -TestArgs ($commonArgs + @("install","vcpkg-hello-world-1","--host-triplet",$Triplet))
Throw-IfFailed
$out = (Run-Vcpkg -TestArgs ($commonArgs + @("build","vcpkg-hello-world-1","--host-triplet",$Triplet)) | Out-String)
Throw-IfNotFailed
if ($out -notmatch "is already installed; please remove")
{
$out
throw "Expected to fail due to already being installed"
}
16 changes: 3 additions & 13 deletions include/vcpkg/base/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,6 @@ namespace vcpkg
tm get_current_date_time_local();
}

template<class Char>
struct fmt::formatter<vcpkg::ElapsedTime, Char>
{
constexpr auto parse(format_parse_context& ctx) const -> decltype(ctx.begin())
{
return vcpkg::basic_format_parse_impl(ctx);
}
template<class FormatContext>
auto format(const vcpkg::ElapsedTime& time, FormatContext& ctx) const -> decltype(ctx.out())
{
return fmt::formatter<std::string, Char>{}.format(time.to_string(), ctx);
}
};
VCPKG_FORMAT_WITH_TO_STRING(vcpkg::ElapsedTime);
VCPKG_FORMAT_WITH_TO_STRING(vcpkg::ElapsedTimer);
VCPKG_FORMAT_WITH_TO_STRING(vcpkg::CTime);
9 changes: 5 additions & 4 deletions include/vcpkg/build.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vcpkg/fwd/portfileprovider.h>

#include <vcpkg/base/files.h>
#include <vcpkg/base/messages.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringview.h>
#include <vcpkg/base/system.process.h>
Expand All @@ -25,6 +26,8 @@ namespace vcpkg
{
struct BinaryCache;
struct Environment;

DECLARE_MESSAGE(ElapsedForPackage, (msg::spec, msg::elapsed), "", "Elapsed time to handle {spec}: {elapsed}");
}

namespace vcpkg::Build
Expand Down Expand Up @@ -56,15 +59,13 @@ namespace vcpkg::Build
int perform_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
Triplet host_triplet,
const SourceControlFileAndLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
BinaryCache& binary_cache,
const IBuildLogsRecorder& build_logs_recorder,
const VcpkgPaths& paths);
void perform_and_exit_ex(const VcpkgCmdArguments& args,
const FullPackageSpec& full_spec,
Triplet host_triplet,
const SourceControlFileAndLocation& scfl,
const PortFileProvider::PathsPortFileProvider& provider,
BinaryCache& binary_cache,
const IBuildLogsRecorder& build_logs_recorder,
Expand Down Expand Up @@ -213,8 +214,8 @@ namespace vcpkg::Build

StringLiteral to_string_locale_invariant(const BuildResult build_result);
LocalizedString to_string(const BuildResult build_result);
std::string create_user_troubleshooting_message(const Dependencies::InstallPlanAction& action,
const VcpkgPaths& paths);
LocalizedString 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
Expand Down
2 changes: 2 additions & 0 deletions include/vcpkg/statusparagraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ namespace vcpkg
std::vector<PackageSpec> dependencies() const;
std::map<std::string, std::vector<FeatureSpec>> feature_dependencies() const;

std::vector<StatusParagraph> all_status_paragraphs() const;

const StatusParagraph* core;
std::vector<const StatusParagraph*> features;
};
Expand Down
6 changes: 6 additions & 0 deletions locales/messages.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"AlreadyInstalledNotHead": "{spec} is already installed -- not building from HEAD",
"AttemptingToFetchPackagesFromVendor": "Attempting to fetch {count} package(s) from {vendor}",
"BothYesAndNoOptionSpecifiedError": "error: cannot specify both --no-{option} and --{option}.",
"BuildAlreadyInstalled": "{spec} is already installed; please remove {spec} before attempting to build it.",
"BuildDependenciesMissing": "The build command requires all dependencies to be already installed.\nThe following dependencies are missing:\n\n",
"BuildResultBuildFailed": "BUILD_FAILED",
"BuildResultCacheMissing": "CACHE_MISSING",
"BuildResultCascadeDueToMissingDependencies": "CASCADED_DUE_TO_MISSING_DEPENDENCIES",
Expand All @@ -21,6 +23,9 @@
"BuildResultSucceeded": "SUCCEEDED",
"BuildResultSummaryHeader": "SUMMARY FOR {triplet}",
"BuildResultSummaryLine": " {build_result}: {count}",
"BuildTroubleshootingMessage1": "Please ensure you're using the latest port files with `git pull` and `vcpkg update`.\nThen check for known issues at:",
"BuildTroubleshootingMessage2": "You can submit a new issue at:",
"BuildTroubleshootingMessage3": "Include '[{package_name}] Build error' in your bug report title, the following version information in your bug description, and attach any relevant failure logs from above.",
"BuildingFromHead": "Building {spec} from HEAD...",
"BuildingPackage": "Building {spec}...",
"BuildingPackageFailed": "building {spec} failed with: {build_result}",
Expand Down Expand Up @@ -105,6 +110,7 @@
"RestoredPackagesFromVendor": "Restored {count} package(s) from {vendor} in {elapsed}",
"ResultsHeader": "RESULTS",
"SeeURL": "See {url} for more information.",
"SourceFieldPortNameMismatch": "The 'Source' field inside the CONTROL file, or \"name\" field inside the vcpkg.json file has the name {package_name} and does not match the port directory {path}.",
"SuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse `--{option}` to disable this check.",
"UnexpectedErrorDuringBulkDownload": "an unexpected error occurred during bulk download.",
"UnknownBaselineFileContent": "unrecognizable baseline entry; expected 'port:triplet=(fail|skip)'",
Expand Down
11 changes: 11 additions & 0 deletions locales/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
"_AttemptingToFetchPackagesFromVendor.comment": "example of {count} is '42'.\nexample of {vendor} is 'Azure'.\n",
"BothYesAndNoOptionSpecifiedError": "error: cannot specify both --no-{option} and --{option}.",
"_BothYesAndNoOptionSpecifiedError.comment": "example of {option} is 'editable'.\n",
"BuildAlreadyInstalled": "{spec} is already installed; please remove {spec} before attempting to build it.",
"_BuildAlreadyInstalled.comment": "example of {spec} is 'zlib:x64-windows'.\n",
"BuildDependenciesMissing": "The build command requires all dependencies to be already installed.\nThe following dependencies are missing:\n\n",
"BuildResultBuildFailed": "BUILD_FAILED",
"_BuildResultBuildFailed.comment": "Printed after the name of an installed entity to indicate that it failed to build.\n",
"BuildResultCacheMissing": "CACHE_MISSING",
Expand All @@ -42,6 +45,12 @@
"_BuildResultSummaryHeader.comment": "Displayed before a list of a summary installation results.\nexample of {triplet} is 'x64-windows'.\n",
"BuildResultSummaryLine": " {build_result}: {count}",
"_BuildResultSummaryLine.comment": "Displayed to show a count of results of a build_result in a summary.\nexample of {build_result} is 'One of the BuildResultXxx messages (such as BuildResultSucceeded/SUCCEEDED)'.\nexample of {count} is '42'.\n",
"BuildTroubleshootingMessage1": "Please ensure you're using the latest port files with `git pull` and `vcpkg update`.\nThen check for known issues at:",
"_BuildTroubleshootingMessage1.comment": "First part of build troubleshooting message, printed before the URI to look for existing bugs.\n",
"BuildTroubleshootingMessage2": "You can submit a new issue at:",
"_BuildTroubleshootingMessage2.comment": "Second part of build troubleshooting message, printed after the URI to look for existing bugs but before the URI to file one.\n",
"BuildTroubleshootingMessage3": "Include '[{package_name}] Build error' in your bug report title, the following version information in your bug description, and attach any relevant failure logs from above.",
"_BuildTroubleshootingMessage3.comment": "Third part of build troubleshooting message, printed after the URI to file a bug but before version information about vcpkg itself.\nexample of {package_name} is 'zlib'.\n",
"BuildingFromHead": "Building {spec} from HEAD...",
"_BuildingFromHead.comment": "'HEAD' means the most recent version of source code\nexample of {spec} is 'zlib:x64-windows'.\n",
"BuildingPackage": "Building {spec}...",
Expand Down Expand Up @@ -179,6 +188,8 @@
"_ResultsHeader.comment": "Displayed before a list of installation results.\n",
"SeeURL": "See {url} for more information.",
"_SeeURL.comment": "example of {url} is 'https://github.com/microsoft/vcpkg'.\n",
"SourceFieldPortNameMismatch": "The 'Source' field inside the CONTROL file, or \"name\" field inside the vcpkg.json file has the name {package_name} and does not match the port directory {path}.",
"_SourceFieldPortNameMismatch.comment": "{package_name} and {path} are both names of installable ports/packages. 'Source', 'CONTROL', 'vcpkg.json', and 'name' references are locale-invariant.\nexample of {package_name} is 'zlib'.\nexample of {path} is '/foo/bar'.\n",
"SuggestNewVersionScheme": "Use the version scheme \"{new_scheme}\" instead of \"{old_scheme}\" in port \"{package_name}\".\nUse `--{option}` to disable this check.",
"_SuggestNewVersionScheme.comment": "example of {new_scheme} is 'version'.\nexample of {old_scheme} is 'version-string'.\nexample of {package_name} is 'zlib'.\nexample of {option} is 'editable'.\n",
"UnexpectedErrorDuringBulkDownload": "an unexpected error occurred during bulk download.",
Expand Down
Loading

0 comments on commit 52dc46e

Please sign in to comment.