Add script to apply clang-format on all sources

1. python script wrapper to call clang-format over the whole code base
2. Add clang-format rule `IncludeBlocks: Preserve` to tell clang-format
do not merge include blocks
3. Fix existed clang-format issue in code base

Bug: angleproject:3532
Change-Id: I289292dc62c2784ff21688065c87c3f3f5538f17
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1709720
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Jamie Madill <jmadill@chromium.org>
This commit is contained in:
Jiacheng Lu 2019-07-19 09:18:55 -06:00 коммит произвёл Commit Bot
Родитель fb5c581dc4
Коммит f35f11106d
21 изменённых файлов: 216 добавлений и 171 удалений

Просмотреть файл

@ -15,6 +15,8 @@ ColumnLimit: 100
# Always break before braces
BreakBeforeBraces: Custom
BraceWrapping:
# TODO(lujc) wait for clang-format-9 support in Chromium tools
# AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
@ -53,3 +55,6 @@ KeepEmptyLinesAtTheStartOfBlocks: true
# Indent nested PP directives.
IndentPPDirectives: AfterHash
# Include blocks style
IncludeBlocks: Preserve

Просмотреть файл

@ -0,0 +1,51 @@
#!/usr/bin/env python
# Copyright 2019 The ANGLE Project Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# apply_clang_format_on_all_sources.py:
# Script to apply clang-format recursively on directory,
# example usage:
# ./scripts/apply_clang_format_on_all_sources.py src
from __future__ import print_function
import os
import sys
import platform
import subprocess
# inplace change and use style from .clang-format
CLANG_FORMAT_ARGS = ['-i', '-style=file']
def main(directory):
system = platform.system()
clang_format_exe = 'clang-format'
if system == 'Windows':
clang_format_exe += '.bat'
partial_cmd = [clang_format_exe] + CLANG_FORMAT_ARGS
for subdir, _, files in os.walk(directory):
if 'third_party' in subdir:
continue
for f in files:
if f.endswith(('.c', '.h', '.cpp', '.hpp')):
f_abspath = os.path.join(subdir, f)
print("Applying clang-format on ", f_abspath)
subprocess.check_call(partial_cmd + [f_abspath])
if __name__ == '__main__':
if len(sys.argv) > 2:
print('Too mang args', file=sys.stderr)
elif len(sys.argv) == 2:
main(os.path.join(os.getcwd(), sys.argv[1]))
else:
main(os.getcwd())

Просмотреть файл

@ -65,7 +65,7 @@ TEST_F(FeatureSupportUtilTest, APIVersion)
// Test the ANGLEAddDeviceInfoToSystemInfo function
TEST_F(FeatureSupportUtilTest, SystemInfo)
{
SystemInfo systemInfo = mSystemInfo;
SystemInfo systemInfo = mSystemInfo;
systemInfo.machineManufacturer = "BAD";
systemInfo.machineModelName = "BAD";
@ -87,8 +87,8 @@ TEST_F(FeatureSupportUtilTest, ParseRules)
]
}
)rulefile";
RulesHandle rulesHandle = nullptr;
int rulesVersion = 0;
RulesHandle rulesHandle = nullptr;
int rulesVersion = 0;
EXPECT_TRUE(ANGLEAndroidParseRulesString(kRulesFileContents, &rulesHandle, &rulesVersion));
EXPECT_NE(nullptr, rulesHandle);
ANGLEFreeRulesHandle(rulesHandle);
@ -140,8 +140,8 @@ TEST_F(FeatureSupportUtilTest, TestRuleProcessing)
]
}
)rulefile";
RulesHandle rulesHandle = nullptr;
int rulesVersion = 0;
RulesHandle rulesHandle = nullptr;
int rulesVersion = 0;
EXPECT_TRUE(ANGLEAndroidParseRulesString(kRulesFileContents, &rulesHandle, &rulesVersion));
EXPECT_NE(nullptr, rulesHandle);

Просмотреть файл

@ -27,7 +27,7 @@ class LabeledObject
public:
virtual ~LabeledObject() {}
virtual void setLabel(const Context *context, const std::string &label) = 0;
virtual const std::string &getLabel() const = 0;
virtual const std::string &getLabel() const = 0;
};
class Debug : angle::NonCopyable

Просмотреть файл

@ -407,10 +407,10 @@ class FlattenUniformVisitor : public sh::VariableNameVisitor
const std::string &name,
const std::string &mappedName) override
{
bool isSampler = IsSamplerType(variable.type);
bool isImage = IsImageType(variable.type);
bool isAtomicCounter = IsAtomicCounterType(variable.type);
std::vector<LinkedUniform> *uniformList = mUniforms;
bool isSampler = IsSamplerType(variable.type);
bool isImage = IsImageType(variable.type);
bool isAtomicCounter = IsAtomicCounterType(variable.type);
std::vector<LinkedUniform> *uniformList = mUniforms;
if (isSampler)
{
uniformList = mSamplerUniforms;

Просмотреть файл

@ -55,7 +55,7 @@ class SurfaceImpl : public FramebufferAttachmentObjectImpl
const gl::FramebufferState &state) = 0;
virtual egl::Error makeCurrent(const gl::Context *context);
virtual egl::Error unMakeCurrent(const gl::Context *context);
virtual egl::Error swap(const gl::Context *context) = 0;
virtual egl::Error swap(const gl::Context *context) = 0;
virtual egl::Error swapWithDamage(const gl::Context *context, EGLint *rects, EGLint n_rects);
virtual egl::Error postSubBuffer(const gl::Context *context,
EGLint x,

Просмотреть файл

@ -80,7 +80,7 @@ struct PixelShaderOutputVariable
std::string name;
std::string source;
size_t outputLocation = 0;
size_t outputIndex = 0;
size_t outputIndex = 0;
};
struct BuiltinVarying final : private angle::NonCopyable

Просмотреть файл

@ -825,8 +825,8 @@ void OutputHLSLImage2DUniformGroup(ProgramD3D &programD3D,
out << "};\n";
}
gl::Shader *shaderGL = programData.getAttachedShader(shaderType);
const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(shaderGL);
gl::Shader *shaderGL = programData.getAttachedShader(shaderType);
const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(shaderGL);
const bool getDimensionsIgnoresBaseLevel = programD3D.usesGetDimensionsIgnoresBaseLevel();
if (shaderD3D->useImage2DFunction(Image2DHLSLGroupFunctionName(textureGroup, IMAGE2DSIZE)))

Просмотреть файл

@ -275,7 +275,7 @@ class RendererD3D : public BufferFactoryD3D
virtual UniformStorageD3D *createUniformStorage(size_t storageSize) = 0;
// Image operations
virtual ImageD3D *createImage() = 0;
virtual ImageD3D *createImage() = 0;
virtual ExternalImageSiblingImpl *createExternalImageSibling(
const gl::Context *context,
EGLenum target,
@ -386,7 +386,7 @@ class RendererD3D : public BufferFactoryD3D
// Necessary hack for default framebuffers in D3D.
virtual FramebufferImpl *createDefaultFramebuffer(const gl::FramebufferState &state) = 0;
virtual gl::Version getMaxSupportedESVersion() const = 0;
virtual gl::Version getMaxSupportedESVersion() const = 0;
virtual gl::Version getMaxConformantESVersion() const = 0;
angle::Result initRenderTarget(const gl::Context *context, RenderTargetD3D *renderTarget);

Просмотреть файл

@ -1032,7 +1032,7 @@ void ProgramVk::updateBuffersDescriptorSet(ContextVk *contextVk,
gl::StorageBuffersArray<VkDescriptorBufferInfo> descriptorBufferInfo;
gl::StorageBuffersArray<VkWriteDescriptorSet> writeDescriptorInfo;
uint32_t writeCount = 0;
uint32_t writeCount = 0;
// The binding is incremented every time arrayElement 0 is encountered, which means there will
// be an increment right at the start. Start from -1 to get 0 as the first binding.
int32_t currentBinding = -1;

Просмотреть файл

@ -121,7 +121,7 @@ class GLMark2Benchmark : public testing::TestWithParam<GLMark2BenchmarkTestParam
const BenchmarkInfo benchmarkInfo = kBenchmarks[std::get<1>(GetParam())];
const char *benchmark = benchmarkInfo.glmark2Config;
const char *benchmarkName = benchmarkInfo.name;
bool completeRun = benchmark == nullptr || benchmark[0] == '\0';
bool completeRun = benchmark == nullptr || benchmark[0] == '\0';
Optional<std::string> cwd = GetCWD();

Просмотреть файл

@ -350,9 +350,9 @@ bool GPUTestExpectationsParser::parseLine(const GPUTestConfig &config,
SplitString(lineData, kWhitespaceASCII, KEEP_WHITESPACE, SPLIT_WANT_NONEMPTY);
int32_t stage = kLineParserBegin;
GPUTestExpectationEntry entry;
entry.lineNumber = lineNumber;
entry.used = false;
bool skipLine = false;
entry.lineNumber = lineNumber;
entry.used = false;
bool skipLine = false;
for (size_t i = 0; i < tokens.size() && !skipLine; ++i)
{
Token token = ParseToken(tokens[i]);

Просмотреть файл

@ -54,7 +54,7 @@ class VulkanExternalHelper
bool mHasExternalSemaphoreFd = false;
PFN_vkGetPhysicalDeviceImageFormatProperties2 vkGetPhysicalDeviceImageFormatProperties2 =
nullptr;
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = nullptr;
PFN_vkGetMemoryFdKHR vkGetMemoryFdKHR = nullptr;
PFN_vkGetSemaphoreFdKHR vkGetSemaphoreFdKHR = nullptr;
PFN_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR
vkGetPhysicalDeviceExternalSemaphorePropertiesKHR = nullptr;

Просмотреть файл

@ -54,34 +54,34 @@ class Event
enum EventType
{
EVENT_CLOSED, // The window requested to be closed
EVENT_MOVED, // The window has moved
EVENT_RESIZED, // The window was resized
EVENT_LOST_FOCUS, // The window lost the focus
EVENT_GAINED_FOCUS, // The window gained the focus
EVENT_TEXT_ENTERED, // A character was entered
EVENT_KEY_PRESSED, // A key was pressed
EVENT_KEY_RELEASED, // A key was released
EVENT_MOUSE_WHEEL_MOVED, // The mouse wheel was scrolled
EVENT_MOUSE_BUTTON_PRESSED, // A mouse button was pressed
EVENT_MOUSE_BUTTON_RELEASED, // A mouse button was released
EVENT_MOUSE_MOVED, // The mouse cursor moved
EVENT_MOUSE_ENTERED, // The mouse cursor entered the area of the window
EVENT_MOUSE_LEFT, // The mouse cursor left the area of the window
EVENT_TEST, // Event for testing purposes
EVENT_CLOSED, // The window requested to be closed
EVENT_MOVED, // The window has moved
EVENT_RESIZED, // The window was resized
EVENT_LOST_FOCUS, // The window lost the focus
EVENT_GAINED_FOCUS, // The window gained the focus
EVENT_TEXT_ENTERED, // A character was entered
EVENT_KEY_PRESSED, // A key was pressed
EVENT_KEY_RELEASED, // A key was released
EVENT_MOUSE_WHEEL_MOVED, // The mouse wheel was scrolled
EVENT_MOUSE_BUTTON_PRESSED, // A mouse button was pressed
EVENT_MOUSE_BUTTON_RELEASED, // A mouse button was released
EVENT_MOUSE_MOVED, // The mouse cursor moved
EVENT_MOUSE_ENTERED, // The mouse cursor entered the area of the window
EVENT_MOUSE_LEFT, // The mouse cursor left the area of the window
EVENT_TEST, // Event for testing purposes
};
EventType Type;
union
{
MoveEvent Move; // Move event parameters
SizeEvent Size; // Size event parameters
KeyEvent Key; // Key event parameters
MouseMoveEvent MouseMove; // Mouse move event parameters
MouseButtonEvent MouseButton; // Mouse button event parameters
MouseWheelEvent MouseWheel; // Mouse wheel event parameters
MoveEvent Move; // Move event parameters
SizeEvent Size; // Size event parameters
KeyEvent Key; // Key event parameters
MouseMoveEvent MouseMove; // Mouse move event parameters
MouseButtonEvent MouseButton; // Mouse button event parameters
MouseWheelEvent MouseWheel; // Mouse wheel event parameters
};
};
#endif // SAMPLE_UTIL_EVENT_H
#endif // SAMPLE_UTIL_EVENT_H

Просмотреть файл

@ -116,7 +116,7 @@ Matrix4 Matrix4::frustum(float l, float r, float b, float t, float n, float f)
Matrix4 Matrix4::perspective(float fovY, float aspectRatio, float nearZ, float farZ)
{
const float frustumHeight = tanf(static_cast<float>(fovY / 360.0f * M_PI)) * nearZ;
const float frustumWidth = frustumHeight * aspectRatio;
const float frustumWidth = frustumHeight * aspectRatio;
return frustum(-frustumWidth, frustumWidth, -frustumHeight, frustumHeight, nearZ, farZ);
}

Просмотреть файл

@ -13,7 +13,8 @@ template <typename outType>
inline outType *DynamicCastComObject(IUnknown *object)
{
outType *outObject = nullptr;
HRESULT result = object->QueryInterface(__uuidof(outType), reinterpret_cast<void**>(&outObject));
HRESULT result =
object->QueryInterface(__uuidof(outType), reinterpret_cast<void **>(&outObject));
if (SUCCEEDED(result))
{
return outObject;
@ -25,4 +26,4 @@ inline outType *DynamicCastComObject(IUnknown *object)
}
}
#endif // UTIL_COM_UTILS_H
#endif // UTIL_COM_UTILS_H

Просмотреть файл

@ -14,21 +14,13 @@
using namespace angle;
SphereGeometry::SphereGeometry()
{
}
SphereGeometry::SphereGeometry() {}
SphereGeometry::~SphereGeometry()
{
}
SphereGeometry::~SphereGeometry() {}
CubeGeometry::CubeGeometry()
{
}
CubeGeometry::CubeGeometry() {}
CubeGeometry::~CubeGeometry()
{
}
CubeGeometry::~CubeGeometry() {}
void CreateSphereGeometry(size_t sliceCount, float radius, SphereGeometry *result)
{

Просмотреть файл

@ -10,108 +10,108 @@
enum Key
{
KEY_UNKNOWN,
KEY_A, // The A key
KEY_B, // The B key
KEY_C, // The C key
KEY_D, // The D key
KEY_E, // The E key
KEY_F, // The F key
KEY_G, // The G key
KEY_H, // The H key
KEY_I, // The I key
KEY_J, // The J key
KEY_K, // The K key
KEY_L, // The L key
KEY_M, // The M key
KEY_N, // The N key
KEY_O, // The O key
KEY_P, // The P key
KEY_Q, // The Q key
KEY_R, // The R key
KEY_S, // The S key
KEY_T, // The T key
KEY_U, // The U key
KEY_V, // The V key
KEY_W, // The W key
KEY_X, // The X key
KEY_Y, // The Y key
KEY_Z, // The Z key
KEY_NUM0, // The 0 key
KEY_NUM1, // The 1 key
KEY_NUM2, // The 2 key
KEY_NUM3, // The 3 key
KEY_NUM4, // The 4 key
KEY_NUM5, // The 5 key
KEY_NUM6, // The 6 key
KEY_NUM7, // The 7 key
KEY_NUM8, // The 8 key
KEY_NUM9, // The 9 key
KEY_ESCAPE, // The escape key
KEY_LCONTROL, // The left control key
KEY_LSHIFT, // The left shift key
KEY_LALT, // The left alt key
KEY_LSYSTEM, // The left OS specific key: Window (Windows and Linux), Apple (MacOS X), ...
KEY_RCONTROL, // The right control key
KEY_RSHIFT, // The right shift key
KEY_RALT, // The right alt key
KEY_RSYSTEM, // The right OS specific key: Window (Windows and Linux), Apple (MacOS X), ...
KEY_MENU, // The menu key
KEY_LBRACKET, // The [ key
KEY_RBRACKET, // The ] key
KEY_SEMICOLON, // The ; key
KEY_COMMA, // The , key
KEY_PERIOD, // The . key
KEY_QUOTE, // The ' key
KEY_SLASH, // The / key
KEY_BACKSLASH, // The \ key
KEY_TILDE, // The ~ key
KEY_EQUAL, // The = key
KEY_DASH, // The - key
KEY_SPACE, // The space key
KEY_RETURN, // The return key
KEY_BACK, // The backspace key
KEY_TAB, // The tabulation key
KEY_PAGEUP, // The page up key
KEY_PAGEDOWN, // The page down key
KEY_END, // The end key
KEY_HOME, // The home key
KEY_INSERT, // The insert key
KEY_DELETE, // The delete key
KEY_ADD, // +
KEY_SUBTRACT, // -
KEY_MULTIPLY, // *
KEY_DIVIDE, // /
KEY_LEFT, // Left arrow
KEY_RIGHT, // Right arrow
KEY_UP, // Up arrow
KEY_DOWN, // Down arrow
KEY_NUMPAD0, // The numpad 0 key
KEY_NUMPAD1, // The numpad 1 key
KEY_NUMPAD2, // The numpad 2 key
KEY_NUMPAD3, // The numpad 3 key
KEY_NUMPAD4, // The numpad 4 key
KEY_NUMPAD5, // The numpad 5 key
KEY_NUMPAD6, // The numpad 6 key
KEY_NUMPAD7, // The numpad 7 key
KEY_NUMPAD8, // The numpad 8 key
KEY_NUMPAD9, // The numpad 9 key
KEY_F1, // The F1 key
KEY_F2, // The F2 key
KEY_F3, // The F3 key
KEY_F4, // The F4 key
KEY_F5, // The F5 key
KEY_F6, // The F6 key
KEY_F7, // The F7 key
KEY_F8, // The F8 key
KEY_F9, // The F8 key
KEY_F10, // The F10 key
KEY_F11, // The F11 key
KEY_F12, // The F12 key
KEY_F13, // The F13 key
KEY_F14, // The F14 key
KEY_F15, // The F15 key
KEY_PAUSE, // The pause key
KEY_A, // The A key
KEY_B, // The B key
KEY_C, // The C key
KEY_D, // The D key
KEY_E, // The E key
KEY_F, // The F key
KEY_G, // The G key
KEY_H, // The H key
KEY_I, // The I key
KEY_J, // The J key
KEY_K, // The K key
KEY_L, // The L key
KEY_M, // The M key
KEY_N, // The N key
KEY_O, // The O key
KEY_P, // The P key
KEY_Q, // The Q key
KEY_R, // The R key
KEY_S, // The S key
KEY_T, // The T key
KEY_U, // The U key
KEY_V, // The V key
KEY_W, // The W key
KEY_X, // The X key
KEY_Y, // The Y key
KEY_Z, // The Z key
KEY_NUM0, // The 0 key
KEY_NUM1, // The 1 key
KEY_NUM2, // The 2 key
KEY_NUM3, // The 3 key
KEY_NUM4, // The 4 key
KEY_NUM5, // The 5 key
KEY_NUM6, // The 6 key
KEY_NUM7, // The 7 key
KEY_NUM8, // The 8 key
KEY_NUM9, // The 9 key
KEY_ESCAPE, // The escape key
KEY_LCONTROL, // The left control key
KEY_LSHIFT, // The left shift key
KEY_LALT, // The left alt key
KEY_LSYSTEM, // The left OS specific key: Window (Windows and Linux), Apple (MacOS X), ...
KEY_RCONTROL, // The right control key
KEY_RSHIFT, // The right shift key
KEY_RALT, // The right alt key
KEY_RSYSTEM, // The right OS specific key: Window (Windows and Linux), Apple (MacOS X), ...
KEY_MENU, // The menu key
KEY_LBRACKET, // The [ key
KEY_RBRACKET, // The ] key
KEY_SEMICOLON, // The ; key
KEY_COMMA, // The , key
KEY_PERIOD, // The . key
KEY_QUOTE, // The ' key
KEY_SLASH, // The / key
KEY_BACKSLASH, // The \ key
KEY_TILDE, // The ~ key
KEY_EQUAL, // The = key
KEY_DASH, // The - key
KEY_SPACE, // The space key
KEY_RETURN, // The return key
KEY_BACK, // The backspace key
KEY_TAB, // The tabulation key
KEY_PAGEUP, // The page up key
KEY_PAGEDOWN, // The page down key
KEY_END, // The end key
KEY_HOME, // The home key
KEY_INSERT, // The insert key
KEY_DELETE, // The delete key
KEY_ADD, // +
KEY_SUBTRACT, // -
KEY_MULTIPLY, // *
KEY_DIVIDE, // /
KEY_LEFT, // Left arrow
KEY_RIGHT, // Right arrow
KEY_UP, // Up arrow
KEY_DOWN, // Down arrow
KEY_NUMPAD0, // The numpad 0 key
KEY_NUMPAD1, // The numpad 1 key
KEY_NUMPAD2, // The numpad 2 key
KEY_NUMPAD3, // The numpad 3 key
KEY_NUMPAD4, // The numpad 4 key
KEY_NUMPAD5, // The numpad 5 key
KEY_NUMPAD6, // The numpad 6 key
KEY_NUMPAD7, // The numpad 7 key
KEY_NUMPAD8, // The numpad 8 key
KEY_NUMPAD9, // The numpad 9 key
KEY_F1, // The F1 key
KEY_F2, // The F2 key
KEY_F3, // The F3 key
KEY_F4, // The F4 key
KEY_F5, // The F5 key
KEY_F6, // The F6 key
KEY_F7, // The F7 key
KEY_F8, // The F8 key
KEY_F9, // The F8 key
KEY_F10, // The F10 key
KEY_F11, // The F11 key
KEY_F12, // The F12 key
KEY_F13, // The F13 key
KEY_F14, // The F14 key
KEY_F15, // The F15 key
KEY_PAUSE, // The pause key
KEY_COUNT,
};
#endif // SAMPLE_UTIL_KEYBOARD_H
#endif // SAMPLE_UTIL_KEYBOARD_H

Просмотреть файл

@ -18,4 +18,4 @@ enum MouseButton
MOUSEBUTTON_COUNT,
};
#endif // SAMPLE_UTIL_MOUSE_H
#endif // SAMPLE_UTIL_MOUSE_H

Просмотреть файл

@ -70,7 +70,7 @@ bool StabilizeCPUForBenchmarking()
"default priority");
success = false;
}
#if ANGLE_PLATFORM_LINUX
# if ANGLE_PLATFORM_LINUX
cpu_set_t affinity;
CPU_SET(0, &affinity);
errno = 0;
@ -81,9 +81,9 @@ bool StabilizeCPUForBenchmarking()
"default affinity");
success = false;
}
#else
# else
// TODO(jmadill): Implement for non-linux. http://anglebug.com/2923
#endif
# endif
return success;
#else // defined(ANGLE_PLATFORM_FUCHSIA)

Просмотреть файл

@ -24,13 +24,9 @@ RNG::RNG()
}
// Seed from fixed number.
RNG::RNG(unsigned int seed) : mGenerator(seed)
{
}
RNG::RNG(unsigned int seed) : mGenerator(seed) {}
RNG::~RNG()
{
}
RNG::~RNG() {}
void RNG::reseed(unsigned int newSeed)
{