Skip to content

Commit

Permalink
Add script to apply clang-format on all sources
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Jamie Madill <[email protected]>
  • Loading branch information
Jason0214 authored and Commit Bot committed Jul 19, 2019
1 parent fb5c581 commit f35f111
Show file tree
Hide file tree
Showing 21 changed files with 216 additions and 171 deletions.
5 changes: 5 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -53,3 +55,6 @@ KeepEmptyLinesAtTheStartOfBlocks: true

# Indent nested PP directives.
IndentPPDirectives: AfterHash

# Include blocks style
IncludeBlocks: Preserve
51 changes: 51 additions & 0 deletions scripts/apply_clang_format_on_all_sources.py
Original file line number Diff line number Diff line change
@@ -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())
10 changes: 5 additions & 5 deletions src/feature_support_util/feature_support_util_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/libANGLE/ProgramLinkedResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/SurfaceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/d3d/DynamicHLSL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/d3d/DynamicImage2DHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
4 changes: 2 additions & 2 deletions src/libANGLE/renderer/d3d/RendererD3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libANGLE/renderer/vulkan/ProgramVk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/perf_tests/glmark2Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
6 changes: 3 additions & 3 deletions src/tests/test_expectations/GPUTestExpectationsParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_utils/VulkanExternalHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 22 additions & 22 deletions util/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion util/Matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions util/com_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,4 +26,4 @@ inline outType *DynamicCastComObject(IUnknown *object)
}
}

#endif // UTIL_COM_UTILS_H
#endif // UTIL_COM_UTILS_H
16 changes: 4 additions & 12 deletions util/geometry_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading

0 comments on commit f35f111

Please sign in to comment.