[vcpkg] Improve vcpkg::Files::Filesystem error handling (#6919)

* [vcpkg] Modify Filesystem::remove and Filesystem::rename to not throw.

* [.gitignore] Ignore new VS2019 CMake integration default location

* [.gitignore] Ignore CMakeSettings.json in toolsrc

* [vcpkg] Time external processes called with System::cmd_execute

* [vcpkg] Work around VS2019 CMake bug

* [vcpkg] Fix several unused variable warnings.

* [vcpkg] Improve error handling in vcpkg::Files::Filesystem

Always require either std::error_code or LineInfo to print better errors.

* [vcpkg] Fixup missing return value.

Drive by fix: silence warnings in tests.

* [vcpkg] Fix exiting in error_code overload

Drive by fixes for /analyze with VS2019
This commit is contained in:
Robert Schumacher 2019-06-19 11:49:57 -07:00 committed by GitHub
parent df0b8d9e55
commit e5b92a3911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 181 additions and 101 deletions

3
.gitignore vendored
View File

@ -11,6 +11,9 @@
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
toolsrc/out
toolsrc/CMakeSettings.json
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs

View File

@ -20,7 +20,7 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang") elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
set(CLANG 1) set(CLANG 1)
elseif(MSVC) elseif(MSVC)
add_compile_options(/std:c++17) add_compile_options(/std:c++17 /FC)
else() else()
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}") message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
endif() endif()

View File

@ -13,7 +13,7 @@
namespace Microsoft::VisualStudio::CppUnitTestFramework namespace Microsoft::VisualStudio::CppUnitTestFramework
{ {
template<> template<>
std::wstring ToString<vcpkg::Dependencies::InstallPlanType>(const vcpkg::Dependencies::InstallPlanType& t) inline std::wstring ToString<vcpkg::Dependencies::InstallPlanType>(const vcpkg::Dependencies::InstallPlanType& t)
{ {
switch (t) switch (t)
{ {
@ -26,7 +26,7 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
} }
template<> template<>
std::wstring ToString<vcpkg::Dependencies::RequestType>(const vcpkg::Dependencies::RequestType& t) inline std::wstring ToString<vcpkg::Dependencies::RequestType>(const vcpkg::Dependencies::RequestType& t)
{ {
switch (t) switch (t)
{ {
@ -38,13 +38,13 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
} }
template<> template<>
std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t) inline std::wstring ToString<vcpkg::PackageSpecParseResult>(const vcpkg::PackageSpecParseResult& t)
{ {
return ToString(static_cast<uint32_t>(t)); return ToString(static_cast<uint32_t>(t));
} }
template<> template<>
std::wstring ToString<vcpkg::PackageSpec>(const vcpkg::PackageSpec& t) inline std::wstring ToString<vcpkg::PackageSpec>(const vcpkg::PackageSpec& t)
{ {
return ToString(t.to_string()); return ToString(t.to_string());
} }

View File

@ -27,21 +27,25 @@ namespace vcpkg::Files
{ {
struct Filesystem struct Filesystem
{ {
std::string read_contents(const fs::path& file_path, LineInfo linfo) const;
virtual Expected<std::string> read_contents(const fs::path& file_path) const = 0; virtual Expected<std::string> read_contents(const fs::path& file_path) const = 0;
virtual Expected<std::vector<std::string>> read_lines(const fs::path& file_path) const = 0; virtual Expected<std::vector<std::string>> read_lines(const fs::path& file_path) const = 0;
virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0; virtual fs::path find_file_recursively_up(const fs::path& starting_dir, const std::string& filename) const = 0;
virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const = 0; virtual std::vector<fs::path> get_files_recursive(const fs::path& dir) const = 0;
virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const = 0; virtual std::vector<fs::path> get_files_non_recursive(const fs::path& dir) const = 0;
void write_lines(const fs::path& file_path, const std::vector<std::string>& lines, LineInfo linfo);
virtual void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 0; virtual void write_lines(const fs::path& file_path,
const std::vector<std::string>& lines,
std::error_code& ec) = 0;
void write_contents(const fs::path& path, const std::string& data, LineInfo linfo);
virtual void write_contents(const fs::path& file_path, const std::string& data, std::error_code& ec) = 0; virtual void write_contents(const fs::path& file_path, const std::string& data, std::error_code& ec) = 0;
virtual void rename(const fs::path& oldpath, const fs::path& newpath) = 0; void rename(const fs::path& oldpath, const fs::path& newpath, LineInfo linfo);
virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) = 0; virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) = 0;
virtual void rename_or_copy(const fs::path& oldpath, virtual void rename_or_copy(const fs::path& oldpath,
const fs::path& newpath, const fs::path& newpath,
StringLiteral temp_suffix, StringLiteral temp_suffix,
std::error_code& ec) = 0; std::error_code& ec) = 0;
virtual bool remove(const fs::path& path) = 0; bool remove(const fs::path& path, LineInfo linfo);
virtual bool remove(const fs::path& path, std::error_code& ec) = 0; virtual bool remove(const fs::path& path, std::error_code& ec) = 0;
virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0; virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 0;
virtual bool exists(const fs::path& path) const = 0; virtual bool exists(const fs::path& path) const = 0;
@ -60,8 +64,6 @@ namespace vcpkg::Files
virtual fs::file_status symlink_status(const fs::path& path, std::error_code& ec) const = 0; virtual fs::file_status symlink_status(const fs::path& path, std::error_code& ec) const = 0;
virtual std::vector<fs::path> find_from_PATH(const std::string& name) const = 0; virtual std::vector<fs::path> find_from_PATH(const std::string& name) const = 0;
void write_contents(const fs::path& file_path, const std::string& data);
}; };
Filesystem& get_real_filesystem(); Filesystem& get_real_filesystem();

View File

@ -44,9 +44,9 @@ namespace vcpkg::Graphs
void shuffle(Container& c, Randomizer* r) void shuffle(Container& c, Randomizer* r)
{ {
if (!r) return; if (!r) return;
for (int i = static_cast<int>(c.size()); i > 1; --i) for (auto i = c.size(); i > 1; --i)
{ {
auto j = r->random(i); auto j = r->random(static_cast<int>(i));
if (j != i - 1) if (j != i - 1)
{ {
std::swap(c[i - 1], c[j]); std::swap(c[i - 1], c[j]);

View File

@ -19,6 +19,9 @@ namespace vcpkg
template<class T, bool B = std::is_copy_constructible<T>::value> template<class T, bool B = std::is_copy_constructible<T>::value>
struct OptionalStorage struct OptionalStorage
{ {
#if defined(_WIN32)
#pragma warning(suppress : 26495)
#endif
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {} constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
constexpr OptionalStorage(const T& t) : m_is_present(true), m_t(t) {} constexpr OptionalStorage(const T& t) : m_is_present(true), m_t(t) {}
constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {} constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {}
@ -28,12 +31,18 @@ namespace vcpkg
if (m_is_present) m_t.~T(); if (m_is_present) m_t.~T();
} }
#if defined(_WIN32)
#pragma warning(suppress : 26495)
#endif
OptionalStorage(const OptionalStorage& o) : m_is_present(o.m_is_present), m_inactive() OptionalStorage(const OptionalStorage& o) : m_is_present(o.m_is_present), m_inactive()
{ {
if (m_is_present) new (&m_t) T(o.m_t); if (m_is_present) new (&m_t) T(o.m_t);
} }
OptionalStorage(OptionalStorage&& o) : m_is_present(o.m_is_present), m_inactive() #if defined(_WIN32)
#pragma warning(suppress : 26495)
#endif
OptionalStorage(OptionalStorage&& o) noexcept : m_is_present(o.m_is_present), m_inactive()
{ {
if (m_is_present) if (m_is_present)
{ {
@ -59,7 +68,7 @@ namespace vcpkg
return *this; return *this;
} }
OptionalStorage& operator=(OptionalStorage&& o) OptionalStorage& operator=(OptionalStorage&& o) noexcept
{ {
if (m_is_present && o.m_is_present) if (m_is_present && o.m_is_present)
{ {
@ -100,6 +109,9 @@ namespace vcpkg
template<class T> template<class T>
struct OptionalStorage<T, false> struct OptionalStorage<T, false>
{ {
#if defined(_WIN32)
#pragma warning(suppress : 26495)
#endif
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {} constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {} constexpr OptionalStorage(T&& t) : m_is_present(true), m_t(std::move(t)) {}
@ -108,7 +120,10 @@ namespace vcpkg
if (m_is_present) m_t.~T(); if (m_is_present) m_t.~T();
} }
OptionalStorage(OptionalStorage&& o) : m_is_present(o.m_is_present), m_inactive() #if defined(_WIN32)
#pragma warning(suppress : 26495)
#endif
OptionalStorage(OptionalStorage&& o) noexcept : m_is_present(o.m_is_present), m_inactive()
{ {
if (m_is_present) if (m_is_present)
{ {
@ -116,7 +131,7 @@ namespace vcpkg
} }
} }
OptionalStorage& operator=(OptionalStorage&& o) OptionalStorage& operator=(OptionalStorage&& o) noexcept
{ {
if (m_is_present && o.m_is_present) if (m_is_present && o.m_is_present)
{ {

View File

@ -163,7 +163,7 @@ namespace vcpkg::Strings
std::vector<std::string> split(const std::string& s, const std::string& delimiter); std::vector<std::string> split(const std::string& s, const std::string& delimiter);
std::vector<std::string> split(const std::string& s, const std::string& delimiter, int max_count); std::vector<std::string> split(const std::string& s, const std::string& delimiter, size_t max_count);
std::vector<StringView> find_all_enclosed(StringView input, StringView left_delim, StringView right_delim); std::vector<StringView> find_all_enclosed(StringView input, StringView left_delim, StringView right_delim);

View File

@ -105,7 +105,7 @@ namespace vcpkg::Downloads
bResults = WinHttpQueryDataAvailable(hRequest, &dwSize); bResults = WinHttpQueryDataAvailable(hRequest, &dwSize);
Checks::check_exit(VCPKG_LINE_INFO, bResults, "WinHttpQueryDataAvailable() failed: %d", GetLastError()); Checks::check_exit(VCPKG_LINE_INFO, bResults, "WinHttpQueryDataAvailable() failed: %d", GetLastError());
if (buf.size() < dwSize) buf.resize(dwSize * 2); if (buf.size() < dwSize) buf.resize(static_cast<size_t>(dwSize) * 2);
bResults = WinHttpReadData(hRequest, (LPVOID)buf.data(), dwSize, &downloaded_size); bResults = WinHttpReadData(hRequest, (LPVOID)buf.data(), dwSize, &downloaded_size);
Checks::check_exit(VCPKG_LINE_INFO, bResults, "WinHttpReadData() failed: %d", GetLastError()); Checks::check_exit(VCPKG_LINE_INFO, bResults, "WinHttpReadData() failed: %d", GetLastError());
@ -157,9 +157,10 @@ namespace vcpkg::Downloads
const std::string& sha512) const std::string& sha512)
{ {
const std::string download_path_part = download_path.u8string() + ".part"; const std::string download_path_part = download_path.u8string() + ".part";
auto download_path_part_path = fs::u8path(download_path_part);
std::error_code ec; std::error_code ec;
fs.remove(download_path, ec); fs.remove(download_path, ec);
fs.remove(download_path_part, ec); fs.remove(download_path_part_path, ec);
#if defined(_WIN32) #if defined(_WIN32)
auto url_no_proto = url.substr(8); // drop https:// auto url_no_proto = url.substr(8); // drop https://
auto path_begin = Util::find(url_no_proto, '/'); auto path_begin = Util::find(url_no_proto, '/');
@ -173,14 +174,7 @@ namespace vcpkg::Downloads
Checks::check_exit(VCPKG_LINE_INFO, code == 0, "Could not download %s", url); Checks::check_exit(VCPKG_LINE_INFO, code == 0, "Could not download %s", url);
#endif #endif
verify_downloaded_file_hash(fs, url, download_path_part, sha512); verify_downloaded_file_hash(fs, url, download_path_part_path, sha512);
fs.rename(download_path_part, download_path, ec); fs.rename(download_path_part_path, download_path, VCPKG_LINE_INFO);
Checks::check_exit(VCPKG_LINE_INFO,
!ec,
"Failed to do post-download rename-in-place.\n"
"fs.rename(%s, %s, %s)",
download_path_part,
download_path.u8string(),
ec.message());
} }
} }

View File

@ -24,12 +24,43 @@ namespace vcpkg::Files
{ {
static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])"); static const std::regex FILESYSTEM_INVALID_CHARACTERS_REGEX = std::regex(R"([\/:*?"<>|])");
void Filesystem::write_contents(const fs::path& file_path, const std::string& data) std::string Filesystem::read_contents(const fs::path& path, LineInfo linfo) const
{
auto maybe_contents = this->read_contents(path);
if (auto p = maybe_contents.get())
return std::move(*p);
else
Checks::exit_with_message(
linfo, "error reading file: %s: %s", path.u8string(), maybe_contents.error().message());
}
void Filesystem::write_contents(const fs::path& path, const std::string& data, LineInfo linfo)
{ {
std::error_code ec; std::error_code ec;
write_contents(file_path, data, ec); this->write_contents(path, data, ec);
Checks::check_exit( if (ec) Checks::exit_with_message(linfo, "error writing file: %s: %s", path.u8string(), ec.message());
VCPKG_LINE_INFO, !ec, "error while writing file: %s: %s", file_path.u8string(), ec.message()); }
void Filesystem::rename(const fs::path& oldpath, const fs::path& newpath, LineInfo linfo)
{
std::error_code ec;
this->rename(oldpath, newpath, ec);
if (ec)
Checks::exit_with_message(
linfo, "error renaming file: %s: %s: %s", oldpath.u8string(), newpath.u8string(), ec.message());
}
bool Filesystem::remove(const fs::path& path, LineInfo linfo)
{
std::error_code ec;
auto r = this->remove(path, ec);
if (ec) Checks::exit_with_message(linfo, "error removing file: %s: %s", path.u8string(), ec.message());
return r;
}
void Filesystem::write_lines(const fs::path& path, const std::vector<std::string>& lines, LineInfo linfo)
{
std::error_code ec;
this->write_lines(path, lines, ec);
if (ec) Checks::exit_with_message(linfo, "error writing lines: %s: %s", path.u8string(), ec.message());
} }
struct RealFilesystem final : Filesystem struct RealFilesystem final : Filesystem
@ -147,30 +178,39 @@ namespace vcpkg::Files
return ret; return ret;
} }
virtual void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) override virtual void write_lines(const fs::path& file_path,
const std::vector<std::string>& lines,
std::error_code& ec) override
{ {
std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc); std::fstream output(file_path, std::ios_base::out | std::ios_base::binary | std::ios_base::trunc);
if (!output)
{
ec.assign(errno, std::generic_category());
return;
}
for (const std::string& line : lines) for (const std::string& line : lines)
{ {
output << line << "\n"; output << line << "\n";
if (!output)
{
output.close();
ec.assign(errno, std::generic_category());
return;
}
} }
output.close(); output.close();
} }
virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) override virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) override
{ {
fs::stdfs::rename(oldpath, newpath, ec); fs::stdfs::rename(oldpath, newpath, ec);
} }
virtual void rename(const fs::path& oldpath, const fs::path& newpath) override
{
fs::stdfs::rename(oldpath, newpath);
}
virtual void rename_or_copy(const fs::path& oldpath, virtual void rename_or_copy(const fs::path& oldpath,
const fs::path& newpath, const fs::path& newpath,
StringLiteral temp_suffix, StringLiteral temp_suffix,
std::error_code& ec) override std::error_code& ec) override
{ {
this->rename(oldpath, newpath, ec); this->rename(oldpath, newpath, ec);
Util::unused(temp_suffix);
#if defined(__linux__) || defined(__APPLE__) #if defined(__linux__) || defined(__APPLE__)
if (ec) if (ec)
{ {
@ -213,7 +253,6 @@ namespace vcpkg::Files
} }
#endif #endif
} }
virtual bool remove(const fs::path& path) override { return fs::stdfs::remove(path); }
virtual bool remove(const fs::path& path, std::error_code& ec) override { return fs::stdfs::remove(path, ec); } virtual bool remove(const fs::path& path, std::error_code& ec) override { return fs::stdfs::remove(path, ec); }
virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) override virtual std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) override
{ {

View File

@ -185,7 +185,7 @@ std::vector<std::string> Strings::split(const std::string& s, const std::string&
return output; return output;
} }
std::vector<std::string> Strings::split(const std::string& s, const std::string& delimiter, int max_count) std::vector<std::string> Strings::split(const std::string& s, const std::string& delimiter, size_t max_count)
{ {
std::vector<std::string> output; std::vector<std::string> output;

View File

@ -388,6 +388,7 @@ namespace vcpkg
// Flush stdout before launching external process // Flush stdout before launching external process
fflush(nullptr); fflush(nullptr);
auto timer = Chrono::ElapsedTimer::create_started();
#if defined(_WIN32) #if defined(_WIN32)
// We are wrap the command line in quotes to cause cmd.exe to correctly process it // We are wrap the command line in quotes to cause cmd.exe to correctly process it
auto actual_cmd_line = Strings::concat('"', cmd_line, '"'); auto actual_cmd_line = Strings::concat('"', cmd_line, '"');
@ -395,11 +396,19 @@ namespace vcpkg
g_ctrl_c_state.transition_to_spawn_process(); g_ctrl_c_state.transition_to_spawn_process();
const int exit_code = _wsystem(Strings::to_utf16(actual_cmd_line).c_str()); const int exit_code = _wsystem(Strings::to_utf16(actual_cmd_line).c_str());
g_ctrl_c_state.transition_from_spawn_process(); g_ctrl_c_state.transition_from_spawn_process();
Debug::print("_wsystem() returned ", exit_code, '\n'); Debug::print("_wsystem() returned ",
exit_code,
" after ",
Strings::format("%8d", static_cast<int>(timer.microseconds())),
" us\n");
#else #else
Debug::print("_system(", cmd_line, ")\n"); Debug::print("_system(", cmd_line, ")\n");
const int exit_code = system(cmd_line.c_str()); const int exit_code = system(cmd_line.c_str());
Debug::print("_system() returned ", exit_code, '\n'); Debug::print("_system() returned ",
exit_code,
" after ",
Strings::format("%8d", static_cast<int>(timer.microseconds())),
" us\n");
#endif #endif
return exit_code; return exit_code;
} }

View File

@ -280,7 +280,7 @@ namespace vcpkg::Build
start += "\n" + Strings::serialize(feature); start += "\n" + Strings::serialize(feature);
} }
const fs::path binary_control_file = paths.packages / bcf.core_paragraph.dir() / "CONTROL"; const fs::path binary_control_file = paths.packages / bcf.core_paragraph.dir() / "CONTROL";
paths.get_filesystem().write_contents(binary_control_file, start); paths.get_filesystem().write_contents(binary_control_file, start, VCPKG_LINE_INFO);
} }
static std::vector<FeatureSpec> compute_required_feature_specs(const BuildPackageConfig& config, static std::vector<FeatureSpec> compute_required_feature_specs(const BuildPackageConfig& config,
@ -336,16 +336,16 @@ namespace vcpkg::Build
static int get_concurrency() static int get_concurrency()
{ {
static int concurrency = []{ static int concurrency = [] {
auto user_defined_concurrency = System::get_environment_variable("VCPKG_MAX_CONCURRENCY"); auto user_defined_concurrency = System::get_environment_variable("VCPKG_MAX_CONCURRENCY");
if (user_defined_concurrency) if (user_defined_concurrency)
{ {
return std::stoi(user_defined_concurrency.value_or_exit(VCPKG_LINE_INFO)); return std::stoi(user_defined_concurrency.value_or_exit(VCPKG_LINE_INFO));
} }
else else
{ {
return System::get_num_logical_cores() + 1; return System::get_num_logical_cores() + 1;
} }
}(); }();
return concurrency; return concurrency;
@ -565,7 +565,7 @@ namespace vcpkg::Build
std::error_code ec; std::error_code ec;
fs.create_directories(paths.buildtrees / name, ec); fs.create_directories(paths.buildtrees / name, ec);
const auto abi_file_path = paths.buildtrees / name / (triplet.canonical_name() + ".vcpkg_abi_info.txt"); const auto abi_file_path = paths.buildtrees / name / (triplet.canonical_name() + ".vcpkg_abi_info.txt");
fs.write_contents(abi_file_path, full_abi_info); fs.write_contents(abi_file_path, full_abi_info, VCPKG_LINE_INFO);
return AbiTagAndFile{Hash::get_file_hash(fs, abi_file_path, "SHA1"), abi_file_path}; return AbiTagAndFile{Hash::get_file_hash(fs, abi_file_path, "SHA1"), abi_file_path};
} }

View File

@ -485,11 +485,11 @@ namespace vcpkg::Commands::CI
System::print2("Total elapsed time: ", result.summary.total_elapsed_time, "\n"); System::print2("Total elapsed time: ", result.summary.total_elapsed_time, "\n");
result.summary.print(); result.summary.print();
} }
auto& fs = paths.get_filesystem();
auto it_xunit = options.settings.find(OPTION_XUNIT); auto it_xunit = options.settings.find(OPTION_XUNIT);
if (it_xunit != options.settings.end()) if (it_xunit != options.settings.end())
{ {
paths.get_filesystem().write_contents(fs::u8path(it_xunit->second), xunitTestResults.build_xml()); fs.write_contents(fs::u8path(it_xunit->second), xunitTestResults.build_xml(), VCPKG_LINE_INFO);
} }
Checks::exit_success(VCPKG_LINE_INFO); Checks::exit_success(VCPKG_LINE_INFO);

View File

@ -106,7 +106,8 @@ namespace vcpkg::Export::IFW
create_release_date(), create_release_date(),
action.spec.name(), action.spec.name(),
action.spec.triplet().canonical_name(), action.spec.triplet().canonical_name(),
deps)); deps),
VCPKG_LINE_INFO);
// Return dir path for export package data // Return dir path for export package data
return ifw_packages_dir_path / return ifw_packages_dir_path /
@ -138,7 +139,8 @@ namespace vcpkg::Export::IFW
<ReleaseDate>%s</ReleaseDate> <ReleaseDate>%s</ReleaseDate>
</Package> </Package>
)###", )###",
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
for (const auto& unique_package : unique_packages) for (const auto& unique_package : unique_packages)
{ {
@ -167,7 +169,8 @@ namespace vcpkg::Export::IFW
action.spec.name(), action.spec.name(),
safe_rich_from_plain_text(binary_paragraph.description), safe_rich_from_plain_text(binary_paragraph.description),
binary_paragraph.version, binary_paragraph.version,
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
} }
} }
@ -195,7 +198,8 @@ namespace vcpkg::Export::IFW
<ReleaseDate>%s</ReleaseDate> <ReleaseDate>%s</ReleaseDate>
</Package> </Package>
)###", )###",
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
for (const std::string& triplet : unique_triplets) for (const std::string& triplet : unique_triplets)
{ {
@ -217,7 +221,8 @@ namespace vcpkg::Export::IFW
</Package> </Package>
)###", )###",
triplet, triplet,
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
} }
} }
@ -243,7 +248,8 @@ namespace vcpkg::Export::IFW
<ReleaseDate>%s</ReleaseDate> <ReleaseDate>%s</ReleaseDate>
</Package> </Package>
)###", )###",
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
} }
void export_config(const std::string& export_id, const Options& ifw_options, const VcpkgPaths& paths) void export_config(const std::string& export_id, const Options& ifw_options, const VcpkgPaths& paths)
@ -283,7 +289,8 @@ namespace vcpkg::Export::IFW
<TargetDir>@RootDir@/src/vcpkg</TargetDir>%s <TargetDir>@RootDir@/src/vcpkg</TargetDir>%s
</Installer> </Installer>
)###", )###",
formatted_repo_url)); formatted_repo_url),
VCPKG_LINE_INFO);
} }
void export_maintenance_tool(const fs::path& ifw_packages_dir_path, const VcpkgPaths& paths) void export_maintenance_tool(const fs::path& ifw_packages_dir_path, const VcpkgPaths& paths)
@ -325,7 +332,8 @@ namespace vcpkg::Export::IFW
<ForcedInstallation>true</ForcedInstallation> <ForcedInstallation>true</ForcedInstallation>
</Package> </Package>
)###", )###",
create_release_date())); create_release_date()),
VCPKG_LINE_INFO);
const fs::path script_source = paths.root / "scripts" / "ifw" / "maintenance.qs"; const fs::path script_source = paths.root / "scripts" / "ifw" / "maintenance.qs";
const fs::path script_destination = ifw_packages_dir_path / "maintenance" / "meta" / "maintenance.qs"; const fs::path script_destination = ifw_packages_dir_path / "maintenance" / "meta" / "maintenance.qs";
fs.copy_file(script_source, script_destination, fs::copy_options::overwrite_existing, ec); fs.copy_file(script_source, script_destination, fs::copy_options::overwrite_existing, ec);

View File

@ -89,7 +89,7 @@ namespace vcpkg::Commands::Import
place_library_files_in(paths.get_filesystem(), include_directory, project_directory, library_destination_path); place_library_files_in(paths.get_filesystem(), include_directory, project_directory, library_destination_path);
const fs::path control_file_path = library_destination_path / "CONTROL"; const fs::path control_file_path = library_destination_path / "CONTROL";
fs.write_contents(control_file_path, Strings::serialize(control_file_data)); fs.write_contents(control_file_path, Strings::serialize(control_file_data), VCPKG_LINE_INFO);
} }
const CommandStructure COMMAND_STRUCTURE = { const CommandStructure COMMAND_STRUCTURE = {

View File

@ -209,7 +209,7 @@ namespace vcpkg::Commands::Integrate
if (should_install_system) if (should_install_system)
{ {
const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets"; const fs::path sys_src_path = tmp_dir / "vcpkg.system.targets";
fs.write_contents(sys_src_path, create_system_targets_shortcut()); fs.write_contents(sys_src_path, create_system_targets_shortcut(), VCPKG_LINE_INFO);
const std::string param = Strings::format(R"(/c mkdir "%s" & copy "%s" "%s" /Y > nul)", const std::string param = Strings::format(R"(/c mkdir "%s" & copy "%s" "%s" /Y > nul)",
SYSTEM_WIDE_TARGETS_FILE.parent_path().string(), SYSTEM_WIDE_TARGETS_FILE.parent_path().string(),
@ -248,7 +248,8 @@ namespace vcpkg::Commands::Integrate
const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets"; const fs::path appdata_src_path = tmp_dir / "vcpkg.user.targets";
fs.write_contents(appdata_src_path, fs.write_contents(appdata_src_path,
create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.u8string())); create_appdata_targets_shortcut(paths.buildsystems_msbuild_targets.u8string()),
VCPKG_LINE_INFO);
auto appdata_dst_path = get_appdata_targets_path(); auto appdata_dst_path = get_appdata_targets_path();
const auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec); const auto rc = fs.copy_file(appdata_src_path, appdata_dst_path, fs::copy_options::overwrite_existing, ec);
@ -268,12 +269,7 @@ namespace vcpkg::Commands::Integrate
const auto pathtxt = get_path_txt_path(); const auto pathtxt = get_path_txt_path();
std::error_code ec; std::error_code ec;
fs.write_contents(pathtxt, paths.root.generic_u8string(), ec); fs.write_contents(pathtxt, paths.root.generic_u8string(), VCPKG_LINE_INFO);
if (ec)
{
System::print2(System::Color::error, "Error: Failed to write file: ", pathtxt.u8string(), "\n");
Checks::exit_fail(VCPKG_LINE_INFO);
}
System::print2(System::Color::success, "Applied user-wide integration for this vcpkg root.\n"); System::print2(System::Color::success, "Applied user-wide integration for this vcpkg root.\n");
const fs::path cmake_toolchain = paths.buildsystems / "vcpkg.cmake"; const fs::path cmake_toolchain = paths.buildsystems / "vcpkg.cmake";
@ -344,9 +340,11 @@ CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s"
const std::string nuget_id = get_nuget_id(paths.root); const std::string nuget_id = get_nuget_id(paths.root);
const std::string nupkg_version = "1.0.0"; const std::string nupkg_version = "1.0.0";
fs.write_contents(targets_file_path, create_nuget_targets_file_contents(paths.buildsystems_msbuild_targets)); fs.write_contents(
fs.write_contents(props_file_path, create_nuget_props_file_contents()); targets_file_path, create_nuget_targets_file_contents(paths.buildsystems_msbuild_targets), VCPKG_LINE_INFO);
fs.write_contents(nuspec_file_path, create_nuspec_file_contents(paths.root, nuget_id, nupkg_version)); fs.write_contents(props_file_path, create_nuget_props_file_contents(), VCPKG_LINE_INFO);
fs.write_contents(
nuspec_file_path, create_nuspec_file_contents(paths.root, nuget_id, nupkg_version), VCPKG_LINE_INFO);
// Using all forward slashes for the command line // Using all forward slashes for the command line
const std::string cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" > nul)", const std::string cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" > nul)",
@ -449,7 +447,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
System::printf("Adding vcpkg completion entry to %s\n", bashrc_path.u8string()); System::printf("Adding vcpkg completion entry to %s\n", bashrc_path.u8string());
bashrc_content.push_back(Strings::format("source %s", completion_script_path.u8string())); bashrc_content.push_back(Strings::format("source %s", completion_script_path.u8string()));
fs.write_contents(bashrc_path, Strings::join("\n", bashrc_content) + '\n'); fs.write_contents(bashrc_path, Strings::join("\n", bashrc_content) + '\n', VCPKG_LINE_INFO);
Checks::exit_success(VCPKG_LINE_INFO); Checks::exit_success(VCPKG_LINE_INFO);
} }
#endif #endif

View File

@ -488,11 +488,12 @@ namespace vcpkg::Dependencies
if (plus) return MarkPlusResult::SUCCESS; if (plus) return MarkPlusResult::SUCCESS;
plus = true; plus = true;
auto p_source = cluster.source.get(); const auto p_source = cluster.source.get();
Checks::check_exit(VCPKG_LINE_INFO, if (p_source == nullptr)
p_source != nullptr, {
"Error: Cannot find definition for package `%s`.", Checks::exit_with_message(
cluster.spec.name()); VCPKG_LINE_INFO, "Error: Cannot find definition for package `%s`.", cluster.spec.name());
}
if (feature.empty()) if (feature.empty())
{ {

View File

@ -141,12 +141,12 @@ namespace vcpkg::Export
std::error_code ec; std::error_code ec;
fs.create_directories(paths.buildsystems / "tmp", ec); fs.create_directories(paths.buildsystems / "tmp", ec);
fs.write_contents(targets_redirect, targets_redirect_content); fs.write_contents(targets_redirect, targets_redirect_content, VCPKG_LINE_INFO);
const std::string nuspec_file_content = const std::string nuspec_file_content =
create_nuspec_file_contents(raw_exported_dir.string(), targets_redirect.string(), nuget_id, nuget_version); create_nuspec_file_contents(raw_exported_dir.string(), targets_redirect.string(), nuget_id, nuget_version);
const fs::path nuspec_file_path = paths.buildsystems / "tmp" / "vcpkg.export.nuspec"; const fs::path nuspec_file_path = paths.buildsystems / "tmp" / "vcpkg.export.nuspec";
fs.write_contents(nuspec_file_path, nuspec_file_content); fs.write_contents(nuspec_file_path, nuspec_file_content, VCPKG_LINE_INFO);
// -NoDefaultExcludes is needed for ".vcpkg-root" // -NoDefaultExcludes is needed for ".vcpkg-root"
const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)", const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)",

View File

@ -137,7 +137,7 @@ namespace vcpkg::Help
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{ {
args.parse_arguments(COMMAND_STRUCTURE); Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
if (args.command_arguments.empty()) if (args.command_arguments.empty())
{ {

View File

@ -138,7 +138,7 @@ namespace vcpkg::Install
std::sort(output.begin(), output.end()); std::sort(output.begin(), output.end());
fs.write_lines(listfile, output); fs.write_lines(listfile, output, VCPKG_LINE_INFO);
} }
static std::vector<file_pack> extract_files_in_triplet( static std::vector<file_pack> extract_files_in_triplet(
@ -364,7 +364,12 @@ namespace vcpkg::Install
const fs::path download_dir = paths.downloads; const fs::path download_dir = paths.downloads;
std::error_code ec; std::error_code ec;
for (auto& p : fs.get_files_non_recursive(download_dir)) for (auto& p : fs.get_files_non_recursive(download_dir))
if (!fs.is_directory(p)) fs.remove(p); {
if (!fs.is_directory(p))
{
fs.remove(p, VCPKG_LINE_INFO);
}
}
} }
return {code, std::move(bcf)}; return {code, std::move(bcf)};
@ -628,6 +633,8 @@ namespace vcpkg::Install
const bool clean_after_build = Util::Sets::contains(options.switches, (OPTION_CLEAN_AFTER_BUILD)); const bool clean_after_build = Util::Sets::contains(options.switches, (OPTION_CLEAN_AFTER_BUILD));
const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING)); const KeepGoing keep_going = to_keep_going(Util::Sets::contains(options.switches, OPTION_KEEP_GOING));
auto& fs = paths.get_filesystem();
// create the plan // create the plan
StatusParagraphs status_db = database_load_check(paths); StatusParagraphs status_db = database_load_check(paths);
@ -645,7 +652,7 @@ namespace vcpkg::Install
Build::FailOnTombstone::NO, Build::FailOnTombstone::NO,
}; };
auto all_ports = Paragraphs::load_all_ports(paths.get_filesystem(), paths.ports); auto all_ports = Paragraphs::load_all_ports(fs, paths.ports);
std::unordered_map<std::string, SourceControlFile> scf_map; std::unordered_map<std::string, SourceControlFile> scf_map;
for (auto&& port : all_ports) for (auto&& port : all_ports)
scf_map[port->core_paragraph->name] = std::move(*port); scf_map[port->core_paragraph->name] = std::move(*port);
@ -703,7 +710,7 @@ namespace vcpkg::Install
xunit_doc += summary.xunit_results(); xunit_doc += summary.xunit_results();
xunit_doc += "</collection></assembly></assemblies>\n"; xunit_doc += "</collection></assembly></assemblies>\n";
paths.get_filesystem().write_contents(fs::u8path(it_xunit->second), xunit_doc); fs.write_contents(fs::u8path(it_xunit->second), xunit_doc, VCPKG_LINE_INFO);
} }
for (auto&& result : summary.results) for (auto&& result : summary.results)

View File

@ -111,7 +111,7 @@ namespace vcpkg::Remove
} }
} }
fs.remove(paths.listfile_path(ipv.core->package)); fs.remove(paths.listfile_path(ipv.core->package), VCPKG_LINE_INFO);
} }
for (auto&& spgh : spghs) for (auto&& spgh : spghs)

View File

@ -131,7 +131,10 @@ namespace vcpkg
virtual const std::string& exe_stem() const = 0; virtual const std::string& exe_stem() const = 0;
virtual std::array<int, 3> default_min_version() const = 0; virtual std::array<int, 3> default_min_version() const = 0;
virtual void add_special_paths(std::vector<fs::path>& out_candidate_paths) const {} virtual void add_special_paths(std::vector<fs::path>& out_candidate_paths) const
{
Util::unused(out_candidate_paths);
}
virtual Optional<std::string> get_version(const fs::path& path_to_exe) const = 0; virtual Optional<std::string> get_version(const fs::path& path_to_exe) const = 0;
}; };
@ -406,6 +409,7 @@ git version 2.17.1.windows.2
virtual void add_special_paths(std::vector<fs::path>& out_candidate_paths) const override virtual void add_special_paths(std::vector<fs::path>& out_candidate_paths) const override
{ {
Util::unused(out_candidate_paths);
// TODO: Uncomment later // TODO: Uncomment later
// const std::vector<fs::path> from_path = Files::find_from_PATH("installerbase"); // const std::vector<fs::path> from_path = Files::find_from_PATH("installerbase");
// candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend()); // candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());

View File

@ -52,7 +52,7 @@ namespace vcpkg::Update
void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths) void perform_and_exit(const VcpkgCmdArguments& args, const VcpkgPaths& paths)
{ {
args.parse_arguments(COMMAND_STRUCTURE); Util::unused(args.parse_arguments(COMMAND_STRUCTURE));
System::print2("Using local portfile versions. To update the local portfiles, use `git pull`.\n"); System::print2("Using local portfile versions. To update the local portfiles, use `git pull`.\n");
const StatusParagraphs status_db = database_load_check(paths); const StatusParagraphs status_db = database_load_check(paths);

View File

@ -21,7 +21,7 @@ namespace vcpkg
return StatusParagraphs(); return StatusParagraphs();
} }
fs.rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file); fs.rename(vcpkg_dir_status_file_old, vcpkg_dir_status_file, VCPKG_LINE_INFO);
} }
auto pghs = Paragraphs::get_paragraphs(fs, vcpkg_dir_status_file).value_or_exit(VCPKG_LINE_INFO); auto pghs = Paragraphs::get_paragraphs(fs, vcpkg_dir_status_file).value_or_exit(VCPKG_LINE_INFO);
@ -72,15 +72,15 @@ namespace vcpkg
} }
} }
fs.write_contents(status_file_new, Strings::serialize(current_status_db)); fs.write_contents(status_file_new, Strings::serialize(current_status_db), VCPKG_LINE_INFO);
fs.rename(status_file_new, status_file); fs.rename(status_file_new, status_file, VCPKG_LINE_INFO);
for (auto&& file : update_files) for (auto&& file : update_files)
{ {
if (!fs.is_regular_file(file)) continue; if (!fs.is_regular_file(file)) continue;
fs.remove(file); fs.remove(file, VCPKG_LINE_INFO);
} }
return current_status_db; return current_status_db;
@ -95,8 +95,8 @@ namespace vcpkg
const auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete"; const auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete";
const auto update_filename = paths.vcpkg_dir_updates / Strings::format("%010d", my_update_id); const auto update_filename = paths.vcpkg_dir_updates / Strings::format("%010d", my_update_id);
fs.write_contents(tmp_update_filename, Strings::serialize(p)); fs.write_contents(tmp_update_filename, Strings::serialize(p), VCPKG_LINE_INFO);
fs.rename(tmp_update_filename, update_filename); fs.rename(tmp_update_filename, update_filename, VCPKG_LINE_INFO);
} }
static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs, static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs,
@ -165,8 +165,8 @@ namespace vcpkg
// Replace the listfile on disk // Replace the listfile on disk
const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated"; const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated";
fs.write_lines(updated_listfile_path, *lines); fs.write_lines(updated_listfile_path, *lines, VCPKG_LINE_INFO);
fs.rename(updated_listfile_path, listfile_path); fs.rename(updated_listfile_path, listfile_path, VCPKG_LINE_INFO);
} }
std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db) std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db)