diff --git a/.clang-format b/.clang-format index f98b4df5f7..089b83cd17 100644 --- a/.clang-format +++ b/.clang-format @@ -7,8 +7,6 @@ IndentWidth: 4 ColumnLimit: 120 PointerAlignment: Left -BreakBeforeBraces: Allman - AllowShortBlocksOnASingleLine: false AllowShortCaseLabelsOnASingleLine: true AllowShortFunctionsOnASingleLine: All @@ -34,6 +32,27 @@ SpaceBeforeCpp11BracedList: false DeriveLineEnding: false UseCRLF: false +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + AfterExternBlock: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true + IncludeBlocks: Regroup IncludeCategories: - Regex: '^(|"pch\.h")$' diff --git a/include/vcpkg/base/files.h b/include/vcpkg/base/files.h index 7477910720..178b87bcaf 100644 --- a/include/vcpkg/base/files.h +++ b/include/vcpkg/base/files.h @@ -154,7 +154,7 @@ namespace vcpkg { #if defined(_WIN32) return ::_fseeki64(m_fs, static_cast(offset), origin); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv Checks::check_exit(VCPKG_LINE_INFO, offset < LLONG_MAX); return ::fseek(m_fs, offset, origin); #endif // ^^^ !_WIN32 @@ -163,7 +163,7 @@ namespace vcpkg { #if defined(_WIN32) return ::_fseeki64(m_fs, offset, origin); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv return ::fseek(m_fs, offset, origin); #endif // ^^^ !_WIN32 } diff --git a/src/tls12-download.c b/src/tls12-download.c index c145014ec9..dd3216c1e9 100644 --- a/src/tls12-download.c +++ b/src/tls12-download.c @@ -161,7 +161,7 @@ static void set_delete_on_close_flag(const HANDLE std_out, const HANDLE target, #ifndef NDEBUG int main() -#else // ^^^ debug // !debug vvv +#else // ^^^ debug // !debug vvv int __stdcall entry() #endif // ^^^ !debug { diff --git a/src/vcpkg-test/files.cpp b/src/vcpkg-test/files.cpp index d609c3e150..0009dc94e2 100644 --- a/src/vcpkg-test/files.cpp +++ b/src/vcpkg-test/files.cpp @@ -199,7 +199,7 @@ TEST_CASE ("vcpkg Path generic", "[filesystem][files]") Path bp("some\\path\\/\\/with\\backslashes"); #if defined(_WIN32) CHECK(bp.generic_u8string() == StringView("some/path////with/backslashes")); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv CHECK(bp.generic_u8string() == StringView("some\\path\\/\\/with\\backslashes")); #endif // _WIN32 } @@ -227,7 +227,7 @@ TEST_CASE ("vcpkg Path::operator/", "[filesystem][files]") test_op_slash("C:/a/b", "D:/c/d", "D:/c/d"); test_op_slash("C:/a/b", "D:c/d", "D:c/d"); test_op_slash("C:/a/b", "C:c/d", "C:/a/b\\c/d"); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv test_op_slash("C:/a/b", "c/d", "C:/a/b/c/d"); test_op_slash("C:a/b", "c/d", "C:a/b/c/d"); test_op_slash("C:a/b", "/c/d", "/c/d"); @@ -283,7 +283,7 @@ TEST_CASE ("vcpkg Path::preferred and Path::make_preferred", "[filesystem][files #if defined(_WIN32) test_preferred(R"(\\server/share\a/b)", R"(\\server\share\a\b)"); test_preferred(R"(//server/share\a/b)", R"(\\server\share\a\b)"); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv test_preferred(R"(//server/share\a/b)", R"(/server/share\a/b)"); test_preferred(R"(//server/share\a/b)", R"(/server/share\a/b)"); #endif // ^^^ !_WIN32 @@ -419,7 +419,7 @@ TEST_CASE ("Path::make_parent_path and Path::parent_path", "[filesystem][files]" test_parent_path(R"(\\server\a)", R"(\\server\)"); test_parent_path(R"(\\server\a\)", R"(\\server\a)"); test_parent_path(R"(\\server\a\b)", R"(\\server\a)"); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv test_parent_path("C:/", "C:"); test_parent_path("C:/a", "C:"); test_parent_path("C:/a/", "C:/a"); @@ -470,7 +470,7 @@ TEST_CASE ("Path decomposition", "[filesystem][files]") bool single_slash_is_absolute = #if defined(_WIN32) false -#else // ^^^ _WIN32 // !_WIN32 vvv +#else // ^^^ _WIN32 // !_WIN32 vvv true #endif // ^^^ !_WIN32 ; @@ -478,7 +478,7 @@ TEST_CASE ("Path decomposition", "[filesystem][files]") bool drive_is_absolute = #if defined(_WIN32) true -#else // ^^^ _WIN32 // !_WIN32 vvv +#else // ^^^ _WIN32 // !_WIN32 vvv false #endif // ^^^ !_WIN32 ; @@ -488,7 +488,7 @@ TEST_CASE ("Path decomposition", "[filesystem][files]") #if defined(_WIN32) test_path_decomposition("C:a", false, "a", ""); test_path_decomposition("C:a.ext", false, "a", ".ext"); -#else // ^^^ _WIN32 // !_WIN32 vvv +#else // ^^^ _WIN32 // !_WIN32 vvv test_path_decomposition("C:a", false, "C:a", ""); test_path_decomposition("C:a.ext", false, "C:a", ".ext"); #endif // ^^^ !_WIN32 diff --git a/src/vcpkg/base/files.cpp b/src/vcpkg/base/files.cpp index a7aef10f4e..68db18576c 100644 --- a/src/vcpkg/base/files.cpp +++ b/src/vcpkg/base/files.cpp @@ -126,7 +126,7 @@ namespace { #if defined(_WIN32) return stdfs::path(Strings::to_utf16(utfpath.native())); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv return stdfs::path(utfpath.native()); #endif // ^^^ !_WIN32 } @@ -135,7 +135,7 @@ namespace { #if defined(_WIN32) return Strings::to_utf8(stdpath.native()); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv return stdpath.native(); #endif // ^^^ !_WIN32 } @@ -230,7 +230,7 @@ namespace // no match return first; -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv (void)last; return first; #endif // _WIN32 @@ -338,7 +338,7 @@ namespace #if defined(_WIN32) const auto ads = std::find(filename, last, ':'); // strip alternate data streams in intra-filename decomposition const auto extension = find_extension(filename, ads); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv const auto extension = find_extension(filename, last); #endif // _WIN32 return StringView(filename, static_cast(extension - filename)); @@ -354,7 +354,7 @@ namespace const auto ads = std::find(filename, last, ':'); // strip alternate data streams in intra-filename decomposition const auto extension = find_extension(filename, ads); return StringView(extension, static_cast(ads - extension)); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv const auto extension = find_extension(filename, last); return StringView(extension, static_cast(last - extension)); #endif // _WIN32 @@ -377,7 +377,7 @@ namespace // if root-name is otherwise nonempty, then it must be one of the always-absolute prefixes like // \\?\ or \\server, so the path is absolute. Otherwise it is relative. return first != find_root_name_end(first, last); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv return !str.empty() && str.byte_at_index(0) == '/'; #endif // ^^^ !_WIN32 } @@ -431,7 +431,7 @@ namespace { ec.assign(GetLastError(), std::system_category()); } -#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv +#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv struct stat s; if (lstat(target.c_str(), &s)) { @@ -485,7 +485,7 @@ namespace { ec.assign(GetLastError(), std::system_category()); } -#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv +#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv if (rmdir(current_entry.path().c_str())) { ec.assign(errno, std::system_category()); @@ -498,7 +498,7 @@ namespace stdfs::remove(current_entry.path(), ec); if (err.check_ec(ec, current_entry)) return; } -#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv +#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv else { if (unlink(current_entry.path().c_str())) @@ -698,8 +698,8 @@ namespace vcpkg m_str.push_back(preferred_separator); } } -#else // ^^^ _WIN32 / !_WIN32 vvv - // (!has_root_directory && is_absolute) can't happen on POSIX, so this just becomes has_filename +#else // ^^^ _WIN32 / !_WIN32 vvv + // (!has_root_directory && is_absolute) can't happen on POSIX, so this just becomes has_filename const auto my_relative_first = std::find_if_not(my_root_name_end, my_last, is_slash); if (my_relative_first != my_last && !is_slash(my_last[-1])) { @@ -944,7 +944,7 @@ namespace vcpkg { #if defined(_WIN32) ec.assign(::_wfopen_s(&m_fs, to_stdfs_path(file_path).c_str(), L"rb"), std::generic_category()); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv m_fs = ::fopen(file_path.c_str(), "rb"); if (m_fs) { @@ -961,7 +961,7 @@ namespace vcpkg { #if defined(_WIN32) ec.assign(::_wfopen_s(&m_fs, to_stdfs_path(file_path).c_str(), L"wb"), std::generic_category()); -#else // ^^^ _WIN32 / !_WIN32 vvv +#else // ^^^ _WIN32 / !_WIN32 vvv m_fs = ::fopen(file_path.c_str(), "wb"); if (m_fs) { @@ -1590,7 +1590,7 @@ namespace vcpkg { #if VCPKG_USE_STD_FILESYSTEM if (b->is_directory(ec)) -#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv +#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv if (stdfs::is_directory(b->path(), ec)) #endif // VCPKG_USE_STD_FILESYSTEM { @@ -1636,7 +1636,7 @@ namespace vcpkg { #if VCPKG_USE_STD_FILESYSTEM if (b->is_regular_file(ec)) -#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv +#else // ^^^ VCPKG_USE_STD_FILESYSTEM // !VCPKG_USE_STD_FILESYSTEM vvv if (stdfs::is_regular_file(b->path(), ec)) #endif // VCPKG_USE_STD_FILESYSTEM { @@ -1722,7 +1722,7 @@ namespace vcpkg auto written_bytes = sendfile(o_fd, i_fd, &bytes, info.st_size); #elif defined(__APPLE__) auto written_bytes = fcopyfile(i_fd, o_fd, 0, COPYFILE_ALL); -#else // ^^^ defined(__APPLE__) // !(defined(__APPLE__) || defined(__linux__)) vvv +#else // ^^^ defined(__APPLE__) // !(defined(__APPLE__) || defined(__linux__)) vvv ssize_t written_bytes = 0; { constexpr std::size_t buffer_length = 4096; @@ -1941,7 +1941,7 @@ namespace vcpkg { #if VCPKG_USE_STD_FILESYSTEM return from_stdfs_path(stdfs::absolute(to_stdfs_path(target), ec)); -#else // ^^^ VCPKG_USE_STD_FILESYSTEM / !VCPKG_USE_STD_FILESYSTEM vvv +#else // ^^^ VCPKG_USE_STD_FILESYSTEM / !VCPKG_USE_STD_FILESYSTEM vvv if (target.is_absolute()) { return target; @@ -2119,7 +2119,7 @@ namespace vcpkg { #if defined(_WIN32) static constexpr StringLiteral EXTS[] = {".cmd", ".exe", ".bat"}; -#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv +#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv static constexpr StringLiteral EXTS[] = {""}; #endif // ^^^!defined(_WIN32) const Path pname = name; diff --git a/src/vcpkg/commands.integrate.cpp b/src/vcpkg/commands.integrate.cpp index 04236e7a6b..9e9dcb8256 100644 --- a/src/vcpkg/commands.integrate.cpp +++ b/src/vcpkg/commands.integrate.cpp @@ -563,7 +563,7 @@ With a project open, go to Tools->NuGet Package Manager->Package Manager Console table.format("vcpkg integrate remove", "Remove user-wide integration"); table.format("vcpkg integrate project", "Generate a referencing nuget package for individual VS project use"); table.format("vcpkg integrate powershell", "Enable PowerShell tab-completion"); -#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv +#else // ^^^ defined(_WIN32) // !defined(_WIN32) vvv table.format("vcpkg integrate install", "Make installed packages available user-wide"); table.format("vcpkg integrate remove", "Remove user-wide integration"); table.format("vcpkg integrate bash", "Enable bash tab-completion"); diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index e14d0081ae..a53b916bdd 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -432,7 +432,7 @@ namespace vcpkg if (request) WinHttpCloseHandle(request); if (connect) WinHttpCloseHandle(connect); if (session) WinHttpCloseHandle(session); -#else // ^^^ _WIN32 // !_WIN32 vvv +#else // ^^^ _WIN32 // !_WIN32 vvv (void)payload; #endif // ^^^ !_WIN32 }