mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-26 09:31:08 +08:00
[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:
parent
df0b8d9e55
commit
e5b92a3911
3
.gitignore
vendored
3
.gitignore
vendored
@ -11,6 +11,9 @@
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
|
||||
toolsrc/out
|
||||
toolsrc/CMakeSettings.json
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
|
@ -20,7 +20,7 @@ If you would like to try anyway, pass --allowAppleClang to bootstrap.sh.")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang")
|
||||
set(CLANG 1)
|
||||
elseif(MSVC)
|
||||
add_compile_options(/std:c++17)
|
||||
add_compile_options(/std:c++17 /FC)
|
||||
else()
|
||||
message(FATAL_ERROR "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}")
|
||||
endif()
|
||||
|
@ -13,7 +13,7 @@
|
||||
namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -26,7 +26,7 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -38,13 +38,13 @@ namespace Microsoft::VisualStudio::CppUnitTestFramework
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
@ -27,21 +27,25 @@ namespace vcpkg::Files
|
||||
{
|
||||
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::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 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 void write_lines(const fs::path& file_path, const std::vector<std::string>& lines) = 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,
|
||||
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 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_or_copy(const fs::path& oldpath,
|
||||
const fs::path& newpath,
|
||||
StringLiteral temp_suffix,
|
||||
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 std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) = 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 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();
|
||||
|
@ -44,9 +44,9 @@ namespace vcpkg::Graphs
|
||||
void shuffle(Container& c, Randomizer* r)
|
||||
{
|
||||
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)
|
||||
{
|
||||
std::swap(c[i - 1], c[j]);
|
||||
|
@ -19,6 +19,9 @@ namespace vcpkg
|
||||
template<class T, bool B = std::is_copy_constructible<T>::value>
|
||||
struct OptionalStorage
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#pragma warning(suppress : 26495)
|
||||
#endif
|
||||
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
|
||||
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)) {}
|
||||
@ -28,12 +31,18 @@ namespace vcpkg
|
||||
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()
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -59,7 +68,7 @@ namespace vcpkg
|
||||
return *this;
|
||||
}
|
||||
|
||||
OptionalStorage& operator=(OptionalStorage&& o)
|
||||
OptionalStorage& operator=(OptionalStorage&& o) noexcept
|
||||
{
|
||||
if (m_is_present && o.m_is_present)
|
||||
{
|
||||
@ -100,6 +109,9 @@ namespace vcpkg
|
||||
template<class T>
|
||||
struct OptionalStorage<T, false>
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#pragma warning(suppress : 26495)
|
||||
#endif
|
||||
constexpr OptionalStorage() noexcept : m_is_present(false), m_inactive() {}
|
||||
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();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@ -116,7 +131,7 @@ namespace vcpkg
|
||||
}
|
||||
}
|
||||
|
||||
OptionalStorage& operator=(OptionalStorage&& o)
|
||||
OptionalStorage& operator=(OptionalStorage&& o) noexcept
|
||||
{
|
||||
if (m_is_present && o.m_is_present)
|
||||
{
|
||||
|
@ -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, 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);
|
||||
|
||||
|
@ -105,7 +105,7 @@ namespace vcpkg::Downloads
|
||||
bResults = WinHttpQueryDataAvailable(hRequest, &dwSize);
|
||||
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);
|
||||
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 download_path_part = download_path.u8string() + ".part";
|
||||
auto download_path_part_path = fs::u8path(download_path_part);
|
||||
std::error_code ec;
|
||||
fs.remove(download_path, ec);
|
||||
fs.remove(download_path_part, ec);
|
||||
fs.remove(download_path_part_path, ec);
|
||||
#if defined(_WIN32)
|
||||
auto url_no_proto = url.substr(8); // drop https://
|
||||
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);
|
||||
#endif
|
||||
|
||||
verify_downloaded_file_hash(fs, url, download_path_part, sha512);
|
||||
fs.rename(download_path_part, download_path, ec);
|
||||
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());
|
||||
verify_downloaded_file_hash(fs, url, download_path_part_path, sha512);
|
||||
fs.rename(download_path_part_path, download_path, VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,43 @@ namespace vcpkg::Files
|
||||
{
|
||||
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;
|
||||
write_contents(file_path, data, ec);
|
||||
Checks::check_exit(
|
||||
VCPKG_LINE_INFO, !ec, "error while writing file: %s: %s", file_path.u8string(), ec.message());
|
||||
this->write_contents(path, data, ec);
|
||||
if (ec) Checks::exit_with_message(linfo, "error writing file: %s: %s", 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
|
||||
@ -147,30 +178,39 @@ namespace vcpkg::Files
|
||||
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);
|
||||
if (!output)
|
||||
{
|
||||
ec.assign(errno, std::generic_category());
|
||||
return;
|
||||
}
|
||||
for (const std::string& line : lines)
|
||||
{
|
||||
output << line << "\n";
|
||||
if (!output)
|
||||
{
|
||||
output.close();
|
||||
ec.assign(errno, std::generic_category());
|
||||
return;
|
||||
}
|
||||
}
|
||||
output.close();
|
||||
}
|
||||
|
||||
virtual void rename(const fs::path& oldpath, const fs::path& newpath, std::error_code& ec) override
|
||||
{
|
||||
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,
|
||||
const fs::path& newpath,
|
||||
StringLiteral temp_suffix,
|
||||
std::error_code& ec) override
|
||||
{
|
||||
this->rename(oldpath, newpath, ec);
|
||||
Util::unused(temp_suffix);
|
||||
#if defined(__linux__) || defined(__APPLE__)
|
||||
if (ec)
|
||||
{
|
||||
@ -213,7 +253,6 @@ namespace vcpkg::Files
|
||||
}
|
||||
#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 std::uintmax_t remove_all(const fs::path& path, std::error_code& ec) override
|
||||
{
|
||||
|
@ -185,7 +185,7 @@ std::vector<std::string> Strings::split(const std::string& s, const std::string&
|
||||
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;
|
||||
|
||||
|
@ -388,6 +388,7 @@ namespace vcpkg
|
||||
// Flush stdout before launching external process
|
||||
fflush(nullptr);
|
||||
|
||||
auto timer = Chrono::ElapsedTimer::create_started();
|
||||
#if defined(_WIN32)
|
||||
// We are wrap the command line in quotes to cause cmd.exe to correctly process it
|
||||
auto actual_cmd_line = Strings::concat('"', cmd_line, '"');
|
||||
@ -395,11 +396,19 @@ namespace vcpkg
|
||||
g_ctrl_c_state.transition_to_spawn_process();
|
||||
const int exit_code = _wsystem(Strings::to_utf16(actual_cmd_line).c_str());
|
||||
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
|
||||
Debug::print("_system(", cmd_line, ")\n");
|
||||
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
|
||||
return exit_code;
|
||||
}
|
||||
|
@ -280,7 +280,7 @@ namespace vcpkg::Build
|
||||
start += "\n" + Strings::serialize(feature);
|
||||
}
|
||||
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,
|
||||
@ -336,16 +336,16 @@ namespace vcpkg::Build
|
||||
|
||||
static int get_concurrency()
|
||||
{
|
||||
static int concurrency = []{
|
||||
auto user_defined_concurrency = System::get_environment_variable("VCPKG_MAX_CONCURRENCY");
|
||||
if (user_defined_concurrency)
|
||||
{
|
||||
return std::stoi(user_defined_concurrency.value_or_exit(VCPKG_LINE_INFO));
|
||||
}
|
||||
else
|
||||
{
|
||||
return System::get_num_logical_cores() + 1;
|
||||
}
|
||||
static int concurrency = [] {
|
||||
auto user_defined_concurrency = System::get_environment_variable("VCPKG_MAX_CONCURRENCY");
|
||||
if (user_defined_concurrency)
|
||||
{
|
||||
return std::stoi(user_defined_concurrency.value_or_exit(VCPKG_LINE_INFO));
|
||||
}
|
||||
else
|
||||
{
|
||||
return System::get_num_logical_cores() + 1;
|
||||
}
|
||||
}();
|
||||
|
||||
return concurrency;
|
||||
@ -565,7 +565,7 @@ namespace vcpkg::Build
|
||||
std::error_code ec;
|
||||
fs.create_directories(paths.buildtrees / name, ec);
|
||||
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};
|
||||
}
|
||||
|
@ -485,11 +485,11 @@ namespace vcpkg::Commands::CI
|
||||
System::print2("Total elapsed time: ", result.summary.total_elapsed_time, "\n");
|
||||
result.summary.print();
|
||||
}
|
||||
|
||||
auto& fs = paths.get_filesystem();
|
||||
auto it_xunit = options.settings.find(OPTION_XUNIT);
|
||||
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);
|
||||
|
@ -106,7 +106,8 @@ namespace vcpkg::Export::IFW
|
||||
create_release_date(),
|
||||
action.spec.name(),
|
||||
action.spec.triplet().canonical_name(),
|
||||
deps));
|
||||
deps),
|
||||
VCPKG_LINE_INFO);
|
||||
|
||||
// Return dir path for export package data
|
||||
return ifw_packages_dir_path /
|
||||
@ -138,7 +139,8 @@ namespace vcpkg::Export::IFW
|
||||
<ReleaseDate>%s</ReleaseDate>
|
||||
</Package>
|
||||
)###",
|
||||
create_release_date()));
|
||||
create_release_date()),
|
||||
VCPKG_LINE_INFO);
|
||||
|
||||
for (const auto& unique_package : unique_packages)
|
||||
{
|
||||
@ -167,7 +169,8 @@ namespace vcpkg::Export::IFW
|
||||
action.spec.name(),
|
||||
safe_rich_from_plain_text(binary_paragraph.description),
|
||||
binary_paragraph.version,
|
||||
create_release_date()));
|
||||
create_release_date()),
|
||||
VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -195,7 +198,8 @@ namespace vcpkg::Export::IFW
|
||||
<ReleaseDate>%s</ReleaseDate>
|
||||
</Package>
|
||||
)###",
|
||||
create_release_date()));
|
||||
create_release_date()),
|
||||
VCPKG_LINE_INFO);
|
||||
|
||||
for (const std::string& triplet : unique_triplets)
|
||||
{
|
||||
@ -217,7 +221,8 @@ namespace vcpkg::Export::IFW
|
||||
</Package>
|
||||
)###",
|
||||
triplet,
|
||||
create_release_date()));
|
||||
create_release_date()),
|
||||
VCPKG_LINE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +248,8 @@ namespace vcpkg::Export::IFW
|
||||
<ReleaseDate>%s</ReleaseDate>
|
||||
</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)
|
||||
@ -283,7 +289,8 @@ namespace vcpkg::Export::IFW
|
||||
<TargetDir>@RootDir@/src/vcpkg</TargetDir>%s
|
||||
</Installer>
|
||||
)###",
|
||||
formatted_repo_url));
|
||||
formatted_repo_url),
|
||||
VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
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>
|
||||
</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_destination = ifw_packages_dir_path / "maintenance" / "meta" / "maintenance.qs";
|
||||
fs.copy_file(script_source, script_destination, fs::copy_options::overwrite_existing, ec);
|
||||
|
@ -89,7 +89,7 @@ namespace vcpkg::Commands::Import
|
||||
place_library_files_in(paths.get_filesystem(), include_directory, project_directory, library_destination_path);
|
||||
|
||||
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 = {
|
||||
|
@ -209,7 +209,7 @@ namespace vcpkg::Commands::Integrate
|
||||
if (should_install_system)
|
||||
{
|
||||
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)",
|
||||
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";
|
||||
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();
|
||||
|
||||
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();
|
||||
std::error_code ec;
|
||||
fs.write_contents(pathtxt, paths.root.generic_u8string(), ec);
|
||||
if (ec)
|
||||
{
|
||||
System::print2(System::Color::error, "Error: Failed to write file: ", pathtxt.u8string(), "\n");
|
||||
Checks::exit_fail(VCPKG_LINE_INFO);
|
||||
}
|
||||
fs.write_contents(pathtxt, paths.root.generic_u8string(), VCPKG_LINE_INFO);
|
||||
|
||||
System::print2(System::Color::success, "Applied user-wide integration for this vcpkg root.\n");
|
||||
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 nupkg_version = "1.0.0";
|
||||
|
||||
fs.write_contents(targets_file_path, create_nuget_targets_file_contents(paths.buildsystems_msbuild_targets));
|
||||
fs.write_contents(props_file_path, create_nuget_props_file_contents());
|
||||
fs.write_contents(nuspec_file_path, create_nuspec_file_contents(paths.root, nuget_id, nupkg_version));
|
||||
fs.write_contents(
|
||||
targets_file_path, create_nuget_targets_file_contents(paths.buildsystems_msbuild_targets), VCPKG_LINE_INFO);
|
||||
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
|
||||
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());
|
||||
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);
|
||||
}
|
||||
#endif
|
||||
|
@ -488,11 +488,12 @@ namespace vcpkg::Dependencies
|
||||
if (plus) return MarkPlusResult::SUCCESS;
|
||||
plus = true;
|
||||
|
||||
auto p_source = cluster.source.get();
|
||||
Checks::check_exit(VCPKG_LINE_INFO,
|
||||
p_source != nullptr,
|
||||
"Error: Cannot find definition for package `%s`.",
|
||||
cluster.spec.name());
|
||||
const auto p_source = cluster.source.get();
|
||||
if (p_source == nullptr)
|
||||
{
|
||||
Checks::exit_with_message(
|
||||
VCPKG_LINE_INFO, "Error: Cannot find definition for package `%s`.", cluster.spec.name());
|
||||
}
|
||||
|
||||
if (feature.empty())
|
||||
{
|
||||
|
@ -141,12 +141,12 @@ namespace vcpkg::Export
|
||||
std::error_code 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 =
|
||||
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";
|
||||
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"
|
||||
const auto cmd_line = Strings::format(R"("%s" pack -OutputDirectory "%s" "%s" -NoDefaultExcludes > nul)",
|
||||
|
@ -137,7 +137,7 @@ namespace vcpkg::Help
|
||||
|
||||
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())
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ namespace vcpkg::Install
|
||||
|
||||
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(
|
||||
@ -364,7 +364,12 @@ namespace vcpkg::Install
|
||||
const fs::path download_dir = paths.downloads;
|
||||
std::error_code ec;
|
||||
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)};
|
||||
@ -628,6 +633,8 @@ namespace vcpkg::Install
|
||||
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));
|
||||
|
||||
auto& fs = paths.get_filesystem();
|
||||
|
||||
// create the plan
|
||||
StatusParagraphs status_db = database_load_check(paths);
|
||||
|
||||
@ -645,7 +652,7 @@ namespace vcpkg::Install
|
||||
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;
|
||||
for (auto&& port : all_ports)
|
||||
scf_map[port->core_paragraph->name] = std::move(*port);
|
||||
@ -703,7 +710,7 @@ namespace vcpkg::Install
|
||||
xunit_doc += summary.xunit_results();
|
||||
|
||||
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)
|
||||
|
@ -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)
|
||||
|
@ -131,7 +131,10 @@ namespace vcpkg
|
||||
virtual const std::string& exe_stem() 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;
|
||||
};
|
||||
|
||||
@ -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
|
||||
{
|
||||
Util::unused(out_candidate_paths);
|
||||
// TODO: Uncomment later
|
||||
// const std::vector<fs::path> from_path = Files::find_from_PATH("installerbase");
|
||||
// candidate_paths.insert(candidate_paths.end(), from_path.cbegin(), from_path.cend());
|
||||
|
@ -52,7 +52,7 @@ namespace vcpkg::Update
|
||||
|
||||
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");
|
||||
|
||||
const StatusParagraphs status_db = database_load_check(paths);
|
||||
|
@ -21,7 +21,7 @@ namespace vcpkg
|
||||
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);
|
||||
@ -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)
|
||||
{
|
||||
if (!fs.is_regular_file(file)) continue;
|
||||
|
||||
fs.remove(file);
|
||||
fs.remove(file, VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
return current_status_db;
|
||||
@ -95,8 +95,8 @@ namespace vcpkg
|
||||
const auto tmp_update_filename = paths.vcpkg_dir_updates / "incomplete";
|
||||
const auto update_filename = paths.vcpkg_dir_updates / Strings::format("%010d", my_update_id);
|
||||
|
||||
fs.write_contents(tmp_update_filename, Strings::serialize(p));
|
||||
fs.rename(tmp_update_filename, update_filename);
|
||||
fs.write_contents(tmp_update_filename, Strings::serialize(p), VCPKG_LINE_INFO);
|
||||
fs.rename(tmp_update_filename, update_filename, VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
static void upgrade_to_slash_terminated_sorted_format(Files::Filesystem& fs,
|
||||
@ -165,8 +165,8 @@ namespace vcpkg
|
||||
|
||||
// Replace the listfile on disk
|
||||
const fs::path updated_listfile_path = listfile_path.generic_string() + "_updated";
|
||||
fs.write_lines(updated_listfile_path, *lines);
|
||||
fs.rename(updated_listfile_path, listfile_path);
|
||||
fs.write_lines(updated_listfile_path, *lines, VCPKG_LINE_INFO);
|
||||
fs.rename(updated_listfile_path, listfile_path, VCPKG_LINE_INFO);
|
||||
}
|
||||
|
||||
std::vector<InstalledPackageView> get_installed_ports(const StatusParagraphs& status_db)
|
||||
|
Loading…
x
Reference in New Issue
Block a user