Skip to content

Commit

Permalink
[vcpkg] Apply clang format (#6826)
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft authored Jun 9, 2019
1 parent 2ca3476 commit 8045248
Show file tree
Hide file tree
Showing 22 changed files with 167 additions and 204 deletions.
4 changes: 2 additions & 2 deletions toolsrc/include/vcpkg/base/chrono.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ namespace vcpkg::Chrono
static Optional<CTime> get_current_date_time();
static Optional<CTime> parse(CStringView str);

constexpr CTime() noexcept : m_tm {0} {}
explicit constexpr CTime(tm t) noexcept : m_tm {t} {}
constexpr CTime() noexcept : m_tm{0} {}
explicit constexpr CTime(tm t) noexcept : m_tm{t} {}

CTime add_hours(const int hours) const;

Expand Down
11 changes: 5 additions & 6 deletions toolsrc/include/vcpkg/base/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace vcpkg::Strings::details
t.to_string(into);
}

template<class T, class=void, class = decltype(to_string(std::declval<std::string&>(), std::declval<const T&>()))>
template<class T, class = void, class = decltype(to_string(std::declval<std::string&>(), std::declval<const T&>()))>
void append_internal(std::string& into, const T& t)
{
to_string(into, t);
Expand All @@ -66,7 +66,8 @@ namespace vcpkg::Strings
}

template<class... Args>
[[nodiscard]] std::string concat(const Args&... args) {
[[nodiscard]] std::string concat(const Args&... args)
{
std::string ret;
append(ret, args...);
return ret;
Expand Down Expand Up @@ -113,8 +114,7 @@ namespace vcpkg::Strings
bool starts_with(StringView s, StringView pattern);

template<class InputIterator, class Transformer>
std::string join(const char* delimiter, InputIterator begin, InputIterator end,
Transformer transformer)
std::string join(const char* delimiter, InputIterator begin, InputIterator end, Transformer transformer)
{
if (begin == end)
{
Expand Down Expand Up @@ -145,8 +145,7 @@ namespace vcpkg::Strings
std::string join(const char* delimiter, InputIterator begin, InputIterator end)
{
using Element = decltype(*begin);
return join(delimiter, begin, end,
[](const Element& x) -> const Element& { return x; });
return join(delimiter, begin, end, [](const Element& x) -> const Element& { return x; });
}

template<class Container>
Expand Down
8 changes: 4 additions & 4 deletions toolsrc/src/tests.arguments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ namespace UnitTest1

TEST_METHOD(create_from_arg_sequence_valued_options)
{
std::array<CommandSetting, 1> settings = { {{"--a", ""}} };
CommandStructure cmdstruct = { "", 0, SIZE_MAX, {{}, settings }, nullptr };
std::array<CommandSetting, 1> settings = {{{"--a", ""}}};
CommandStructure cmdstruct = {"", 0, SIZE_MAX, {{}, settings}, nullptr};

std::vector<std::string> t = {"--a=b", "command", "argument"};
auto v = VcpkgCmdArguments::create_from_arg_sequence(t.data(), t.data() + t.size());
Expand All @@ -47,8 +47,8 @@ namespace UnitTest1

TEST_METHOD(create_from_arg_sequence_valued_options2)
{
std::array<CommandSwitch, 2> switches = { {{"--a", ""}, {"--c", ""}} };
std::array<CommandSetting, 2> settings = { { {"--b", ""}, {"--d", ""}} };
std::array<CommandSwitch, 2> switches = {{{"--a", ""}, {"--c", ""}}};
std::array<CommandSetting, 2> settings = {{{"--b", ""}, {"--d", ""}}};
CommandStructure cmdstruct = {"", 0, SIZE_MAX, {switches, settings}, nullptr};

std::vector<std::string> t = {"--a", "--b=c"};
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,6 @@ int main(const int argc, const char* const* const argv)
}
fflush(stdout);

//It is expected that one of the sub-commands will exit cleanly before we get here.
// It is expected that one of the sub-commands will exit cleanly before we get here.
Checks::exit_fail(VCPKG_LINE_INFO);
}
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg/archives.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "pch.h"

#include <vcpkg/archives.h>
#include <vcpkg/commands.h>
#include <vcpkg/base/system.process.h>
#include <vcpkg/commands.h>

namespace vcpkg::Archives
{
Expand Down
10 changes: 5 additions & 5 deletions toolsrc/src/vcpkg/base/chrono.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace vcpkg::Chrono

static tm to_local_time(const std::time_t& t)
{
tm parts {};
tm parts{};
#if defined(_WIN32)
localtime_s(&parts, &t);
#else
Expand All @@ -33,7 +33,7 @@ namespace vcpkg::Chrono

static Optional<tm> to_utc_time(const std::time_t& t)
{
tm parts {};
tm parts{};
#if defined(_WIN32)
const errno_t err = gmtime_s(&parts, &t);
if (err)
Expand Down Expand Up @@ -127,7 +127,7 @@ namespace vcpkg::Chrono
const Optional<tm> opt = to_utc_time(ct);
if (auto p_tm = opt.get())
{
return CTime {*p_tm};
return CTime{*p_tm};
}

return nullopt;
Expand Down Expand Up @@ -160,11 +160,11 @@ namespace vcpkg::Chrono
return ret;
}

CTime CTime::add_hours(const int hours) const { return CTime {date_plus_hours(&this->m_tm, hours)}; }
CTime CTime::add_hours(const int hours) const { return CTime{date_plus_hours(&this->m_tm, hours)}; }

std::string CTime::to_string() const
{
std::array<char, 80> date {};
std::array<char, 80> date{};
strftime(&date[0], date.size(), "%Y-%m-%dT%H:%M:%S.0Z", &m_tm);
return &date[0];
}
Expand Down
22 changes: 12 additions & 10 deletions toolsrc/src/vcpkg/base/downloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,20 @@ namespace vcpkg::Downloads
Checks::check_exit(VCPKG_LINE_INFO, hSession, "WinHttpOpen() failed: %d", GetLastError());

// Win7 IE Proxy fallback
if (IsWindows7OrGreater() && !IsWindows8Point1OrGreater()) {
if (IsWindows7OrGreater() && !IsWindows8Point1OrGreater())
{
// First check if any proxy has been found automatically
WINHTTP_PROXY_INFO proxyInfo;
DWORD proxyInfoSize = sizeof(WINHTTP_PROXY_INFO);
auto noProxyFound =
!WinHttpQueryOption(hSession, WINHTTP_OPTION_PROXY, &proxyInfo, &proxyInfoSize)
|| proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY;

// If no proxy was found automatically, use IE's proxy settings, if any
if (noProxyFound) {
WINHTTP_PROXY_INFO proxyInfo;
DWORD proxyInfoSize = sizeof(WINHTTP_PROXY_INFO);
auto noProxyFound = !WinHttpQueryOption(hSession, WINHTTP_OPTION_PROXY, &proxyInfo, &proxyInfoSize) ||
proxyInfo.dwAccessType == WINHTTP_ACCESS_TYPE_NO_PROXY;

// If no proxy was found automatically, use IE's proxy settings, if any
if (noProxyFound)
{
WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxy;
if (WinHttpGetIEProxyConfigForCurrentUser(&ieProxy) && ieProxy.lpszProxy != nullptr) {
if (WinHttpGetIEProxyConfigForCurrentUser(&ieProxy) && ieProxy.lpszProxy != nullptr)
{
WINHTTP_PROXY_INFO proxy;
proxy.dwAccessType = WINHTTP_ACCESS_TYPE_NAMED_PROXY;
proxy.lpszProxy = ieProxy.lpszProxy;
Expand Down
2 changes: 1 addition & 1 deletion toolsrc/src/vcpkg/base/files.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@

#if defined(__linux__) || defined(__APPLE__)
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#endif
#if defined(__linux__)
#include <sys/sendfile.h>
Expand Down
7 changes: 4 additions & 3 deletions toolsrc/src/vcpkg/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ namespace vcpkg
}

std::string System::make_cmake_cmd(const fs::path& cmake_exe,
const fs::path& cmake_script,
const std::vector<CMakeVariable>& pass_variables)
const fs::path& cmake_script,
const std::vector<CMakeVariable>& pass_variables)
{
const std::string cmd_cmake_pass_variables = Strings::join(" ", pass_variables, [](auto&& v) { return v.s; });
return Strings::format(
Expand Down Expand Up @@ -345,7 +345,8 @@ namespace vcpkg
}
#endif

int System::cmd_execute_clean(const ZStringView cmd_line, const std::unordered_map<std::string, std::string>& extra_env)
int System::cmd_execute_clean(const ZStringView cmd_line,
const std::unordered_map<std::string, std::string>& extra_env)
{
auto timer = Chrono::ElapsedTimer::create_started();
#if defined(_WIN32)
Expand Down
26 changes: 11 additions & 15 deletions toolsrc/src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#include <vcpkg/base/hash.h>
#include <vcpkg/base/optional.h>
#include <vcpkg/base/stringliteral.h>
#include <vcpkg/base/system.debug.h>
#include <vcpkg/base/system.print.h>
#include <vcpkg/base/system.process.h>
#include <vcpkg/base/system.debug.h>

#include <vcpkg/build.h>
#include <vcpkg/commands.h>
Expand Down Expand Up @@ -360,14 +360,13 @@ namespace vcpkg::Build

const Toolset& toolset = paths.get_toolset(pre_build_info);

std::vector<System::CMakeVariable> variables {
std::vector<System::CMakeVariable> variables{
{"CMD", "BUILD"},
{"PORT", config.scf.core_paragraph->name},
{"CURRENT_PORT_DIR", config.port_dir},
{"TARGET_TRIPLET", spec.triplet().canonical_name()},
{"VCPKG_PLATFORM_TOOLSET", toolset.version.c_str()},
{"VCPKG_USE_HEAD_VERSION",
Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"VCPKG_USE_HEAD_VERSION", Util::Enum::to_bool(config.build_package_options.use_head_version) ? "1" : "0"},
{"DOWNLOADS", paths.downloads},
{"_VCPKG_NO_DOWNLOADS", !Util::Enum::to_bool(config.build_package_options.allow_downloads) ? "1" : "0"},
{"_VCPKG_DOWNLOAD_TOOL", to_string(config.build_package_options.download_tool)},
Expand All @@ -380,10 +379,7 @@ namespace vcpkg::Build
variables.push_back({"GIT", git_exe_path});
}

const std::string cmd_launch_cmake = System::make_cmake_cmd(
cmake_exe_path,
paths.ports_cmake,
variables);
const std::string cmd_launch_cmake = System::make_cmake_cmd(cmake_exe_path, paths.ports_cmake, variables);

auto command = make_build_env_cmd(pre_build_info, toolset);
if (!command.empty())
Expand Down Expand Up @@ -484,14 +480,14 @@ namespace vcpkg::Build

// the order of recursive_directory_iterator is undefined so save the names to sort
std::vector<fs::path> port_files;
for (auto &port_file : fs::stdfs::recursive_directory_iterator(config.port_dir))
for (auto& port_file : fs::stdfs::recursive_directory_iterator(config.port_dir))
{
if (fs::is_regular_file(status(port_file)))
{
port_files.push_back(port_file);
if (port_files.size() > max_port_file_count)
{
abi_tag_entries.emplace_back(AbiEntry{ "no_hash_max_portfile", "" });
abi_tag_entries.emplace_back(AbiEntry{"no_hash_max_portfile", ""});
break;
}
}
Expand All @@ -502,7 +498,7 @@ namespace vcpkg::Build
std::sort(port_files.begin(), port_files.end());

int counter = 0;
for (auto & port_file : port_files)
for (auto& port_file : port_files)
{
// When vcpkg takes a dependency on C++17 it can use fs::relative,
// which will give a stable ordering and better names in the key entry.
Expand All @@ -512,7 +508,7 @@ namespace vcpkg::Build
{
System::print2("[DEBUG] mapping ", key, " from ", port_file.u8string(), "\n");
}
abi_tag_entries.emplace_back(AbiEntry{ key, vcpkg::Hash::get_file_hash(fs, port_file, "SHA1") });
abi_tag_entries.emplace_back(AbiEntry{key, vcpkg::Hash::get_file_hash(fs, port_file, "SHA1")});
}
}

Expand Down Expand Up @@ -602,8 +598,8 @@ namespace vcpkg::Build
System::cmd_execute_clean(Strings::format(
R"("%s" a "%s" "%s\*" >nul)", seven_zip_exe.u8string(), destination.u8string(), source.u8string()));
#else
System::cmd_execute_clean(Strings::format(
R"(cd '%s' && zip --quiet -r '%s' *)", source.u8string(), destination.u8string()));
System::cmd_execute_clean(
Strings::format(R"(cd '%s' && zip --quiet -r '%s' *)", source.u8string(), destination.u8string()));
#endif
}

Expand Down Expand Up @@ -730,7 +726,7 @@ namespace vcpkg::Build
const auto tmp_failure_zip = paths.buildtrees / spec.name() / "failure_logs.zip";
fs.create_directories(tmp_log_path_destination, ec);

for (auto &log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
for (auto& log_file : fs::stdfs::directory_iterator(paths.buildtrees / spec.name()))
{
if (log_file.path().extension() == ".log")
{
Expand Down
Loading

0 comments on commit 8045248

Please sign in to comment.