[vcpkg] Mark many types noexcept. Make certain code patterns more transparent to /analyze. #ifdef-out unused code on non-windows.

This commit is contained in:
Robert Schumacher 2018-04-12 00:47:17 -07:00
parent 8da8f3e5b3
commit a2aeb2f194
34 changed files with 147 additions and 125 deletions

View File

@ -23,6 +23,9 @@ endif()
if(GCC OR CLANG)
add_compile_options(-std=c++1z)
if(WERROR)
add_compile_options(-Wall -Wno-unknown-pragmas -Werror)
endif()
endif()
file(GLOB_RECURSE VCPKGLIB_SOURCES src/vcpkg/*.cpp)

View File

@ -11,8 +11,8 @@ namespace vcpkg::Chrono
using duration = std::chrono::high_resolution_clock::time_point::duration;
public:
constexpr ElapsedTime() : m_duration() {}
constexpr ElapsedTime(duration d) : m_duration(d) {}
constexpr ElapsedTime() noexcept : m_duration() {}
constexpr ElapsedTime(duration d) noexcept : m_duration(d) {}
template<class TimeUnit>
TimeUnit as() const
@ -31,7 +31,7 @@ namespace vcpkg::Chrono
public:
static ElapsedTimer create_started();
constexpr ElapsedTimer() : m_start_tick() {}
constexpr ElapsedTimer() noexcept : m_start_tick() {}
ElapsedTime elapsed() const
{
@ -52,8 +52,8 @@ namespace vcpkg::Chrono
static Optional<CTime> get_current_date_time();
static Optional<CTime> parse(CStringView str);
constexpr CTime() : m_tm{0} {}
explicit constexpr CTime(tm t) : m_tm{t} {}
constexpr CTime() noexcept : m_tm{0} {}
explicit constexpr CTime(tm t) noexcept : m_tm{t} {}
std::string to_string() const;

View File

@ -7,7 +7,7 @@ namespace vcpkg
{
struct CStringView
{
constexpr CStringView() : cstr(nullptr) {}
constexpr CStringView() noexcept : cstr(nullptr) {}
constexpr CStringView(const char* cstr) : cstr(cstr) {}
constexpr CStringView(const CStringView&) = default;
CStringView(const std::string& str) : cstr(str.c_str()) {}
@ -18,19 +18,6 @@ namespace vcpkg
const char* cstr;
};
struct CWStringView
{
constexpr CWStringView() : cstr(nullptr) {}
constexpr CWStringView(const wchar_t* cstr) : cstr(cstr) {}
constexpr CWStringView(const CWStringView&) = default;
CWStringView(const std::wstring& str) : cstr(str.c_str()) {}
constexpr const wchar_t* c_str() const { return cstr; }
private:
const wchar_t* cstr;
};
namespace details
{
inline bool vcpkg_strcmp(const char* l, const char* r) { return strcmp(l, r) == 0; }

View File

@ -64,7 +64,7 @@ namespace vcpkg::Files
Filesystem& get_real_filesystem();
static const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)";
static constexpr const char* FILESYSTEM_INVALID_CHARACTERS = R"(\/:*?"<>|)";
bool has_invalid_chars_for_filesystem(const std::string& s);

View File

@ -9,7 +9,7 @@ namespace vcpkg
int line_number;
const char* file_name;
constexpr LineInfo() : line_number(0), file_name("") {}
constexpr LineInfo() noexcept : line_number(0), file_name("") {}
constexpr LineInfo(const int lineno, const char* filename) : line_number(lineno), file_name(filename) {}
std::string to_string() const;

View File

@ -16,7 +16,7 @@ namespace vcpkg
template<class T>
struct OptionalStorage
{
constexpr OptionalStorage() : m_is_present(false), m_t() {}
constexpr OptionalStorage() noexcept : m_is_present(false), m_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)) {}
@ -33,7 +33,7 @@ namespace vcpkg
template<class T>
struct OptionalStorage<T&>
{
constexpr OptionalStorage() : m_t(nullptr) {}
constexpr OptionalStorage() noexcept : m_t(nullptr) {}
constexpr OptionalStorage(T& t) : m_t(&t) {}
constexpr bool has_value() const { return m_t != nullptr; }
@ -48,7 +48,7 @@ namespace vcpkg
template<class T>
struct Optional
{
constexpr Optional() {}
constexpr Optional() noexcept {}
// Constructors are intentionally implicit
constexpr Optional(NullOpt) {}

View File

@ -19,18 +19,19 @@ namespace vcpkg
using iterator = pointer;
constexpr Span() noexcept : m_ptr(nullptr), m_count(0) {}
constexpr Span(std::nullptr_t) noexcept : Span() {}
constexpr Span(std::nullptr_t) noexcept : m_ptr(nullptr), m_count(0) {}
constexpr Span(pointer ptr, size_t count) noexcept : m_ptr(ptr), m_count(count) {}
constexpr Span(pointer ptr_begin, pointer ptr_end) noexcept : m_ptr(ptr_begin), m_count(ptr_end - ptr_begin) {}
constexpr Span(std::initializer_list<T> l) noexcept : m_ptr(l.begin()), m_count(l.size()) {}
template<size_t N>
constexpr Span(T (&arr)[N]) noexcept : Span(arr, N)
constexpr Span(T (&arr)[N]) noexcept : m_ptr(arr), m_count(N)
{
}
template<size_t N>
constexpr Span(const std::array<std::remove_const_t<T>, N>& arr) noexcept : Span(arr.data(), arr.size())
constexpr Span(const std::array<std::remove_const_t<T>, N>& arr) noexcept
: m_ptr(arr.data()), m_count(arr.size())
{
}

View File

@ -36,7 +36,7 @@ namespace vcpkg::Strings
std::wstring to_utf16(const CStringView& s);
std::string to_utf8(const CWStringView& w);
std::string to_utf8(const wchar_t* w);
std::string escape_string(const CStringView& s, char char_to_escape, char escape_char);

View File

@ -12,7 +12,7 @@ namespace vcpkg
/// </summary>
struct BinaryParagraph
{
BinaryParagraph();
BinaryParagraph() noexcept;
explicit BinaryParagraph(std::unordered_map<std::string, std::string> fields);
BinaryParagraph(const SourceParagraph& spgh, const Triplet& triplet, const std::string& abi_tag);
BinaryParagraph(const SourceParagraph& spgh, const FeatureParagraph& fpgh, const Triplet& triplet);

View File

@ -62,7 +62,7 @@ namespace vcpkg::Build
BUILT_IN,
ARIA2,
};
const std::string& to_string(DownloadTool tool);
const std::string& to_string(DownloadTool tool);
struct BuildPackageOptions
{
@ -203,8 +203,8 @@ namespace vcpkg::Build
struct BuildInfo
{
LinkageType crt_linkage;
LinkageType library_linkage;
LinkageType crt_linkage = LinkageType::DYNAMIC;
LinkageType library_linkage = LinkageType::DYNAMIC;
Optional<std::string> version;

View File

@ -35,7 +35,7 @@ namespace vcpkg::Dependencies
{
static bool compare_by_name(const InstallPlanAction* left, const InstallPlanAction* right);
InstallPlanAction();
InstallPlanAction() noexcept;
InstallPlanAction(InstalledPackageView&& spghs,
const std::set<std::string>& features,
@ -73,7 +73,7 @@ namespace vcpkg::Dependencies
{
static bool compare_by_name(const RemovePlanAction* left, const RemovePlanAction* right);
RemovePlanAction();
RemovePlanAction() noexcept;
RemovePlanAction(const PackageSpec& spec, const RemovePlanType& plan_type, const RequestType& request_type);
PackageSpec spec;
@ -103,7 +103,7 @@ namespace vcpkg::Dependencies
{
static bool compare_by_name(const ExportPlanAction* left, const ExportPlanAction* right);
ExportPlanAction();
ExportPlanAction() noexcept;
ExportPlanAction(const PackageSpec& spec,
InstalledPackageView&& installed_package,
const RequestType& request_type);

View File

@ -17,7 +17,7 @@ namespace vcpkg
template<>
struct ErrorHolder<PackageSpecParseResult>
{
ErrorHolder() : m_err(PackageSpecParseResult::SUCCESS) {}
ErrorHolder() noexcept : m_err(PackageSpecParseResult::SUCCESS) {}
ErrorHolder(PackageSpecParseResult err) : m_err(err) {}
bool has_error() const { return m_err != PackageSpecParseResult::SUCCESS; }

View File

@ -29,7 +29,7 @@ namespace vcpkg
/// </summary>
struct StatusParagraph
{
StatusParagraph();
StatusParagraph() noexcept;
explicit StatusParagraph(std::unordered_map<std::string, std::string>&& fields);
bool is_installed() const { return want == Want::INSTALL && state == InstallState::INSTALLED; }
@ -47,7 +47,7 @@ namespace vcpkg
struct InstalledPackageView
{
InstalledPackageView() : core(nullptr) {}
InstalledPackageView() noexcept : core(nullptr) {}
InstalledPackageView(const StatusParagraph* c, std::vector<const StatusParagraph*>&& fs)
: core(c), features(std::move(fs))

View File

@ -9,7 +9,7 @@ namespace vcpkg
struct Triplet
{
public:
constexpr Triplet() : m_instance(&DEFAULT_INSTANCE) {}
constexpr Triplet() noexcept : m_instance(&DEFAULT_INSTANCE) {}
static Triplet from_canonical_name(const std::string& triplet_as_string);
@ -47,4 +47,4 @@ namespace std
{
size_t operator()(const vcpkg::Triplet& t) const { return t.hash_code(); }
};
}
}

View File

@ -5,7 +5,7 @@ namespace vcpkg
{
struct VersionT
{
VersionT();
VersionT() noexcept;
VersionT(std::string&& value);
VersionT(const std::string& value);
@ -23,7 +23,7 @@ namespace vcpkg
VersionT left;
VersionT right;
VersionDiff();
VersionDiff() noexcept;
VersionDiff(const VersionT& left, const VersionT& right);
std::string to_string() const;

View File

@ -81,7 +81,7 @@ namespace UnitTest1
{
std::unordered_map<std::string, SourceControlFile> map;
Triplet triplet;
PackageSpecMap(const Triplet& t = Triplet::X86_WINDOWS) { triplet = t; }
PackageSpecMap(const Triplet& t = Triplet::X86_WINDOWS) noexcept { triplet = t; }
PackageSpec emplace(const char* name,
const char* depends = "",

View File

@ -223,6 +223,7 @@ static void load_config()
}
}
#if defined(_WIN32)
static std::string trim_path_from_command_line(const std::string& full_command_line)
{
Checks::check_exit(
@ -243,6 +244,7 @@ static std::string trim_path_from_command_line(const std::string& full_command_l
++it;
return std::string(it, full_command_line.cend());
}
#endif
#if defined(_WIN32)
int wmain(const int argc, const wchar_t* const* const argv)

View File

@ -148,17 +148,18 @@ namespace vcpkg::CoffFileReader
{
static OffsetsArray read(fstream& fs, const uint32_t offset_count)
{
static constexpr size_t OFFSET_WIDTH = 4;
static constexpr uint32_t OFFSET_WIDTH = 4;
std::string raw_offsets;
const size_t raw_offset_size = offset_count * OFFSET_WIDTH;
const uint32_t raw_offset_size = offset_count * OFFSET_WIDTH;
raw_offsets.resize(raw_offset_size);
fs.read(&raw_offsets[0], raw_offset_size);
OffsetsArray ret;
for (uint32_t i = 0; i < offset_count; ++i)
{
const std::string value_as_string = raw_offsets.substr(OFFSET_WIDTH * i, OFFSET_WIDTH * (i + 1));
const std::string value_as_string = raw_offsets.substr(OFFSET_WIDTH * static_cast<size_t>(i),
OFFSET_WIDTH * (static_cast<size_t>(i) + 1));
const auto value = reinterpret_bytes<uint32_t>(value_as_string.c_str());
// Ignore offsets that point to offset 0. See vcpkg github #223 #288 #292

View File

@ -22,9 +22,9 @@ namespace vcpkg::Files
auto length = file_stream.tellg();
file_stream.seekg(0, file_stream.beg);
if (length > SIZE_MAX)
if (length == std::streampos(-1))
{
return std::make_error_code(std::errc::file_too_large);
return std::make_error_code(std::errc::io_error);
}
std::string output;
@ -185,12 +185,15 @@ namespace vcpkg::Files
return;
}
auto count = fwrite(data.data(), sizeof(data[0]), data.size(), f);
fclose(f);
if (count != data.size())
if (f != nullptr)
{
ec = std::make_error_code(std::errc::no_space_on_device);
auto count = fwrite(data.data(), sizeof(data[0]), data.size(), f);
fclose(f);
if (count != data.size())
{
ec = std::make_error_code(std::errc::no_space_on_device);
}
}
}
};

View File

@ -39,7 +39,7 @@ namespace vcpkg::Strings::details
_vsnprintf_s_l(&output.at(0), output.size() + 1, output.size(), fmtstr, c_locale(), args);
#else
va_start(args, fmtstr);
auto res = vsnprintf(&output.at(0), output.size() + 1, fmtstr, args);
vsnprintf(&output.at(0), output.size() + 1, fmtstr, args);
#endif
va_end(args);
@ -52,23 +52,25 @@ namespace vcpkg::Strings
std::wstring to_utf16(const CStringView& s)
{
#if defined(_WIN32)
const int size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
std::wstring output;
const size_t size = MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, nullptr, 0);
if (size == 0) return output;
output.resize(size - 1);
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), size - 1);
MultiByteToWideChar(CP_UTF8, 0, s.c_str(), -1, output.data(), static_cast<int>(size) - 1);
return output;
#else
Checks::unreachable(VCPKG_LINE_INFO);
#endif
}
std::string to_utf8(const CWStringView& w)
std::string to_utf8(const wchar_t* w)
{
#if defined(_WIN32)
const int size = WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, nullptr, 0, nullptr, nullptr);
std::string output;
const size_t size = WideCharToMultiByte(CP_UTF8, 0, w, -1, nullptr, 0, nullptr, nullptr);
if (size == 0) return output;
output.resize(size - 1);
WideCharToMultiByte(CP_UTF8, 0, w.c_str(), -1, output.data(), size - 1, nullptr, nullptr);
WideCharToMultiByte(CP_UTF8, 0, w, -1, output.data(), static_cast<int>(size) - 1, nullptr, nullptr);
return output;
#else
Checks::unreachable(VCPKG_LINE_INFO);

View File

@ -214,7 +214,7 @@ namespace vcpkg::System
for (auto&& env_wstring : env_wstrings)
{
const Optional<std::string> value = System::get_environment_variable(Strings::to_utf8(env_wstring));
const Optional<std::string> value = System::get_environment_variable(Strings::to_utf8(env_wstring.c_str()));
const auto v = value.get();
if (!v || v->empty()) continue;
@ -298,17 +298,6 @@ namespace vcpkg::System
return exit_code;
}
// On Win7, output from powershell calls contain a byte order mark, so we strip it out if it is present
static void remove_byte_order_marks(std::wstring* s)
{
const wchar_t* a = s->c_str();
// This is the UTF-8 byte-order mark
while (s->size() >= 3 && a[0] == 0xEF && a[1] == 0xBB && a[2] == 0xBF)
{
s->erase(0, 3);
}
}
ExitCodeAndOutput cmd_execute_and_capture_output(const CStringView cmd_line)
{
// Flush stdout before launching external process
@ -325,7 +314,7 @@ namespace vcpkg::System
const auto pipe = _wpopen(Strings::to_utf16(actual_cmd_line).c_str(), L"r");
if (pipe == nullptr)
{
return {1, Strings::to_utf8(output)};
return {1, Strings::to_utf8(output.c_str())};
}
while (fgetws(buf, 1024, pipe))
{
@ -333,15 +322,22 @@ namespace vcpkg::System
}
if (!feof(pipe))
{
return {1, Strings::to_utf8(output)};
return {1, Strings::to_utf8(output.c_str())};
}
const auto ec = _pclose(pipe);
remove_byte_order_marks(&output);
// On Win7, output from powershell calls contain a utf-8 byte order mark in the utf-16 stream, so we strip it
// out if it is present. 0xEF,0xBB,0xBF is the UTF-8 byte-order mark
const wchar_t* a = output.c_str();
while (output.size() >= 3 && a[0] == 0xEF && a[1] == 0xBB && a[2] == 0xBF)
{
output.erase(0, 3);
}
Debug::println("_pclose() returned %d after %8d us", ec, static_cast<int>(timer.microseconds()));
return {ec, Strings::to_utf8(output)};
return {ec, Strings::to_utf8(output.c_str())};
#else
const auto actual_cmd_line = Strings::format(R"###(%s 2>&1)###", cmd_line);
@ -481,7 +477,7 @@ namespace vcpkg::System
const auto sz2 = GetEnvironmentVariableW(w_varname.c_str(), ret.data(), static_cast<DWORD>(ret.size()));
Checks::check_exit(VCPKG_LINE_INFO, sz2 + 1 == sz);
ret.pop_back();
return Strings::to_utf8(ret);
return Strings::to_utf8(ret.c_str());
#else
auto v = getenv(varname.c_str());
if (!v) return nullopt;
@ -522,7 +518,7 @@ namespace vcpkg::System
return nullopt;
ret.pop_back(); // remove extra trailing null byte
return Strings::to_utf8(ret);
return Strings::to_utf8(ret.c_str());
}
#else
Optional<std::string> get_registry_string(void* base_hkey, const CStringView sub_key, const CStringView valuename)

View File

@ -24,7 +24,7 @@ namespace vcpkg
static const std::string DEFAULTFEATURES = "Default-Features";
}
BinaryParagraph::BinaryParagraph() = default;
BinaryParagraph::BinaryParagraph() noexcept = default;
BinaryParagraph::BinaryParagraph(std::unordered_map<std::string, std::string> fields)
{

View File

@ -330,8 +330,7 @@ namespace vcpkg::Build
const PreBuildInfo& pre_build_info,
const PackageSpec& spec,
const std::string& abi_tag,
const BuildPackageConfig& config,
const StatusParagraphs& status_db)
const BuildPackageConfig& config)
{
auto& fs = paths.get_filesystem();
const Triplet& triplet = spec.triplet();
@ -419,10 +418,9 @@ namespace vcpkg::Build
const PreBuildInfo& pre_build_info,
const PackageSpec& spec,
const std::string& abi_tag,
const BuildPackageConfig& config,
const StatusParagraphs& status_db)
const BuildPackageConfig& config)
{
auto result = do_build_package(paths, pre_build_info, spec, abi_tag, config, status_db);
auto result = do_build_package(paths, pre_build_info, spec, abi_tag, config);
if (config.build_package_options.clean_buildtrees == CleanBuildtrees::YES)
{
@ -564,7 +562,7 @@ namespace vcpkg::Build
auto dep_pspecs = Util::fmap(required_fspecs, [](FeatureSpec const& fspec) { return fspec.spec(); });
Util::sort_unique_erase(dep_pspecs);
// Find all features that aren't installed. This destroys required_fspecs.
// Find all features that aren't installed. This mutates required_fspecs.
Util::unstable_keep_if(required_fspecs, [&](FeatureSpec const& fspec) {
return !status_db.is_installed(fspec) && fspec.name() != name;
});
@ -624,7 +622,7 @@ namespace vcpkg::Build
System::println("Could not locate cached archive: %s", archive_path.u8string());
ExtendedBuildResult result = do_build_package_and_clean_buildtrees(
paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config, status_db);
paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config);
std::error_code ec;
fs.create_directories(paths.package_dir(spec) / "share" / spec.name(), ec);
@ -657,7 +655,7 @@ namespace vcpkg::Build
}
return do_build_package_and_clean_buildtrees(
paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config, status_db);
paths, pre_build_info, spec, maybe_abi_tag_and_file.value_or(AbiTagAndFile{}).tag, config);
}
const std::string& to_string(const BuildResult build_result)

View File

@ -77,11 +77,8 @@ namespace vcpkg::Commands::CI
{
auto triplet = p->spec.triplet();
const Build::BuildPackageConfig build_config{p->source_control_file.value_or_exit(VCPKG_LINE_INFO),
triplet,
paths.port_dir(p->spec),
install_plan_options,
p->feature_list};
const Build::BuildPackageConfig build_config{
*scf, triplet, paths.port_dir(p->spec), install_plan_options, p->feature_list};
auto dependency_abis =
Util::fmap(p->computed_dependencies, [&](const PackageSpec& spec) -> Build::AbiEntry {

View File

@ -9,14 +9,15 @@ namespace vcpkg::Commands::Edit
{
static std::vector<fs::path> find_from_registry()
{
std::vector<fs::path> output;
#if defined(_WIN32)
static const std::array<const char*, 3> REGKEYS = {
R"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{C26E74D1-022E-4238-8B9D-1E7564A36CC9}_is1)",
R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{1287CAD5-7C8D-410D-88B9-0D1EE4A83FF2}_is1)",
R"(SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F8A2A208-72B3-4D61-95FC-8A65D340689B}_is1)",
};
std::vector<fs::path> output;
#if defined(_WIN32)
for (auto&& keypath : REGKEYS)
{
const Optional<std::string> code_installpath =

View File

@ -269,8 +269,6 @@ namespace vcpkg::Commands::Fetch
#endif
static fs::path fetch_tool(const VcpkgPaths& paths, const std::string& tool_name, const ToolData& tool_data)
{
const auto& fs = paths.get_filesystem();
const fs::path& scripts_folder = paths.scripts;
const std::array<int, 3>& version = tool_data.version;
const std::string version_as_string = Strings::format("%d.%d.%d", version[0], version[1], version[2]);
@ -280,7 +278,7 @@ namespace vcpkg::Commands::Fetch
tool_name,
version_as_string);
#if defined(_WIN32)
const fs::path script = scripts_folder / "fetchtool.ps1";
const fs::path script = paths.scripts / "fetchtool.ps1";
const std::string title = Strings::format(
"Fetching %s version %s (No sufficient installed version was found)", tool_name, version_as_string);
const System::PowershellParameter tool_param("tool", tool_name);
@ -300,6 +298,7 @@ namespace vcpkg::Commands::Fetch
actual_downloaded_path.u8string());
return actual_downloaded_path;
#else
const auto& fs = paths.get_filesystem();
if (!fs.exists(tool_data.download_path))
{
System::println("Downloading %s...", tool_name);

View File

@ -127,12 +127,15 @@ namespace vcpkg::Commands::Hash
FILE* file = nullptr;
const auto ec = _wfopen_s(&file, path.c_str(), L"rb");
Checks::check_exit(VCPKG_LINE_INFO, ec == 0, "Failed to open file: %s", path.u8string());
unsigned char buffer[4096];
while (const auto actual_size = fread(buffer, 1, sizeof(buffer), file))
if (file != nullptr)
{
hash_data(hash_handle, buffer, actual_size);
unsigned char buffer[4096];
while (const auto actual_size = fread(buffer, 1, sizeof(buffer), file))
{
hash_data(hash_handle, buffer, actual_size);
}
fclose(file);
}
fclose(file);
return finalize_hash_handle(hash_handle, length_in_bytes);
}

View File

@ -8,6 +8,7 @@
namespace vcpkg::Commands::Integrate
{
#if defined(_WIN32)
static std::string create_appdata_targets_shortcut(const std::string& target_path) noexcept
{
return Strings::format(R"###(
@ -18,7 +19,9 @@ namespace vcpkg::Commands::Integrate
target_path,
target_path);
}
#endif
#if defined(_WIN32)
static std::string create_system_targets_shortcut() noexcept
{
return R"###(
@ -31,7 +34,9 @@ namespace vcpkg::Commands::Integrate
</Project>
)###";
}
#endif
#if defined(_WIN32)
static std::string create_nuget_targets_file_contents(const fs::path& msbuild_vcpkg_targets_file) noexcept
{
const std::string as_string = msbuild_vcpkg_targets_file.string();
@ -47,7 +52,9 @@ namespace vcpkg::Commands::Integrate
as_string,
as_string);
}
#endif
#if defined(_WIN32)
static std::string create_nuget_props_file_contents() noexcept
{
return R"###(
@ -58,7 +65,9 @@ namespace vcpkg::Commands::Integrate
</Project>
)###";
}
#endif
#if defined(_WIN32)
static std::string get_nuget_id(const fs::path& vcpkg_root_dir)
{
std::string dir_id = vcpkg_root_dir.generic_string();
@ -71,7 +80,9 @@ namespace vcpkg::Commands::Integrate
const std::string nuget_id = "vcpkg." + dir_id;
return nuget_id;
}
#endif
#if defined(_WIN32)
static std::string create_nuspec_file_contents(const fs::path& vcpkg_root_dir,
const std::string& nuget_id,
const std::string& nupkg_version)
@ -98,14 +109,15 @@ namespace vcpkg::Commands::Integrate
content = Strings::replace_all(std::move(content), "@VERSION@", nupkg_version);
return content;
}
#endif
#if defined(_WIN32)
enum class ElevationPromptChoice
{
YES,
NO
};
#if defined(_WIN32)
static ElevationPromptChoice elevated_cmd_execute(const std::string& param)
{
SHELLEXECUTEINFOW sh_ex_info{};
@ -272,6 +284,7 @@ CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=%s")",
}
#endif
#if defined(WIN32)
static void integrate_project(const VcpkgPaths& paths)
{
auto& fs = paths.get_filesystem();
@ -319,13 +332,19 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console
Checks::exit_success(VCPKG_LINE_INFO);
}
#endif
#if defined(_WIN32)
const char* const INTEGRATE_COMMAND_HELPSTRING =
" vcpkg integrate install Make installed packages available user-wide. Requires admin privileges on "
"first use\n"
" vcpkg integrate remove Remove user-wide integration\n"
" vcpkg integrate project Generate a referencing nuget package for individual VS project use\n"
" vcpkg integrate powershell Enable PowerShell Tab-Completion\n";
#else
const char* const INTEGRATE_COMMAND_HELPSTRING =
"No user-wide integration methods are available on this platform\n";
#endif
namespace Subcommand
{

View File

@ -22,7 +22,7 @@ namespace vcpkg::Dependencies
struct ClusterSource
{
const SourceControlFile* scf;
const SourceControlFile* scf = nullptr;
std::unordered_map<std::string, std::vector<FeatureSpec>> build_edges;
};
@ -145,7 +145,10 @@ namespace vcpkg::Dependencies
}
}
InstallPlanAction::InstallPlanAction() : plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
InstallPlanAction::InstallPlanAction() noexcept
: plan_type(InstallPlanType::UNKNOWN), request_type(RequestType::UNKNOWN), build_options{}
{
}
InstallPlanAction::InstallPlanAction(const PackageSpec& spec,
const SourceControlFile& scf,
@ -156,6 +159,7 @@ namespace vcpkg::Dependencies
, source_control_file(scf)
, plan_type(InstallPlanType::BUILD_AND_INSTALL)
, request_type(request_type)
, build_options{}
, feature_list(features)
, computed_dependencies(std::move(dependencies))
{
@ -168,6 +172,7 @@ namespace vcpkg::Dependencies
, installed_package(std::move(ipv))
, plan_type(InstallPlanType::ALREADY_INSTALLED)
, request_type(request_type)
, build_options{}
, feature_list(features)
, computed_dependencies(installed_package.get()->dependencies())
{
@ -189,7 +194,10 @@ namespace vcpkg::Dependencies
return left->spec.name() < right->spec.name();
}
RemovePlanAction::RemovePlanAction() : plan_type(RemovePlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
RemovePlanAction::RemovePlanAction() noexcept
: plan_type(RemovePlanType::UNKNOWN), request_type(RequestType::UNKNOWN)
{
}
RemovePlanAction::RemovePlanAction(const PackageSpec& spec,
const RemovePlanType& plan_type,
@ -218,7 +226,10 @@ namespace vcpkg::Dependencies
return left->spec.name() < right->spec.name();
}
ExportPlanAction::ExportPlanAction() : plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN) {}
ExportPlanAction::ExportPlanAction() noexcept
: plan_type(ExportPlanType::UNKNOWN), request_type(RequestType::UNKNOWN)
{
}
ExportPlanAction::ExportPlanAction(const PackageSpec& spec,
InstalledPackageView&& installed_package,
@ -506,14 +517,14 @@ namespace vcpkg::Dependencies
{
if (auto p_source = cluster.source.get())
{
for (auto&& feature : p_source->scf->feature_paragraphs)
for (auto&& fpgh : p_source->scf->feature_paragraphs)
{
auto res = mark_plus(feature->name, cluster, graph, graph_plan, prevent_default_features);
auto res = mark_plus(fpgh->name, cluster, graph, graph_plan, prevent_default_features);
Checks::check_exit(VCPKG_LINE_INFO,
res == MarkPlusResult::SUCCESS,
"Error: Unable to locate feature %s in %s",
feature->name,
fpgh->name,
cluster.spec);
}

View File

@ -247,12 +247,12 @@ namespace vcpkg::Export
struct ExportArguments
{
bool dry_run;
bool raw;
bool nuget;
bool ifw;
bool zip;
bool seven_zip;
bool dry_run = false;
bool raw = false;
bool nuget = false;
bool ifw = false;
bool zip = false;
bool seven_zip = false;
Optional<std::string> maybe_output;

View File

@ -245,12 +245,6 @@ namespace vcpkg::Metrics
bool get_compiled_metrics_enabled() { return DISABLE_METRICS == 0; }
static fs::path get_vcpkg_root()
{
return Files::get_real_filesystem().find_file_recursively_up(
fs::stdfs::absolute(System::get_exe_path_of_current_process()), ".vcpkg-root");
}
std::string get_MAC_user()
{
#if defined(_WIN32)

View File

@ -361,6 +361,7 @@ namespace vcpkg::PostBuildLint
std::string actual_arch;
};
#if defined(_WIN32)
static std::string get_actual_architecture(const MachineType& machine_type)
{
switch (machine_type)
@ -374,7 +375,9 @@ namespace vcpkg::PostBuildLint
default: return "Machine Type Code = " + std::to_string(static_cast<uint16_t>(machine_type));
}
}
#endif
#if defined(_WIN32)
static void print_invalid_architecture_files(const std::string& expected_architecture,
std::vector<FileAndArch> binaries_with_invalid_architecture)
{
@ -391,7 +394,6 @@ namespace vcpkg::PostBuildLint
static LintStatus check_dll_architecture(const std::string& expected_architecture,
const std::vector<fs::path>& files)
{
#if defined(_WIN32)
std::vector<FileAndArch> binaries_with_invalid_architecture;
for (const fs::path& file : files)
@ -414,10 +416,10 @@ namespace vcpkg::PostBuildLint
print_invalid_architecture_files(expected_architecture, binaries_with_invalid_architecture);
return LintStatus::ERROR_DETECTED;
}
#endif
return LintStatus::SUCCESS;
}
#endif
static LintStatus check_lib_architecture(const std::string& expected_architecture,
const std::vector<fs::path>& files)
@ -802,7 +804,9 @@ namespace vcpkg::PostBuildLint
check_outdated_crt_linkage_of_dlls(dlls, toolset.dumpbin, build_info, pre_build_info);
}
#if defined(_WIN32)
error_count += check_dll_architecture(pre_build_info.target_architecture, dlls);
#endif
break;
}
case Build::LinkageType::STATIC:

View File

@ -12,7 +12,7 @@ namespace vcpkg
static const std::string STATUS = "Status";
}
StatusParagraph::StatusParagraph() : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE) {}
StatusParagraph::StatusParagraph() noexcept : want(Want::ERROR_STATE), state(InstallState::ERROR_STATE) {}
void serialize(const StatusParagraph& pgh, std::string& out_str)
{
@ -25,6 +25,7 @@ namespace vcpkg
}
StatusParagraph::StatusParagraph(std::unordered_map<std::string, std::string>&& fields)
: want(Want::ERROR_STATE), state(InstallState::ERROR_STATE)
{
auto status_it = fields.find(BinaryParagraphRequiredField::STATUS);
Checks::check_exit(VCPKG_LINE_INFO, status_it != fields.end(), "Expected 'Status' field in status paragraph");

View File

@ -5,7 +5,7 @@
namespace vcpkg
{
VersionT::VersionT() : value("0.0.0") {}
VersionT::VersionT() noexcept : value("0.0.0") {}
VersionT::VersionT(std::string&& value) : value(std::move(value)) {}
VersionT::VersionT(const std::string& value) : value(value) {}
const std::string& VersionT::to_string() const { return value; }
@ -13,7 +13,7 @@ namespace vcpkg
bool operator!=(const VersionT& left, const VersionT& right) { return left.to_string() != right.to_string(); }
std::string to_printf_arg(const VersionT& version) { return version.to_string(); }
VersionDiff::VersionDiff() : left(), right() {}
VersionDiff::VersionDiff() noexcept : left(), right() {}
VersionDiff::VersionDiff(const VersionT& left, const VersionT& right) : left(left), right(right) {}
std::string VersionDiff::to_string() const