Skip to content

Commit 3decad2

Browse files
authored
Merge pull request #200 from aaronfranke/format-gh-actions
Update formatting script and use GitHub Actions
2 parents 717c3fe + 528ac92 commit 3decad2

File tree

118 files changed

+4004
-4004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+4004
-4004
lines changed

.gitattributes

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
* text=auto eol=lf
3+
# Except for Windows-only / Visual Studio files
4+
*.bat eol=crlf
5+
*.sln eol=crlf
6+
*.csproj eol=crlf
7+
18
*.hdr binary

.github/workflows/file_format.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import sys
5+
6+
if len(sys.argv) < 2:
7+
print("Invalid usage of file_format.py, it should be called with a path to one or multiple files.")
8+
sys.exit(1)
9+
10+
BOM = b"\xef\xbb\xbf"
11+
12+
changed = []
13+
invalid = []
14+
15+
for file in sys.argv[1:]:
16+
try:
17+
with open(file, "rt", encoding="utf-8") as f:
18+
original = f.read()
19+
except UnicodeDecodeError:
20+
invalid.append(file)
21+
continue
22+
23+
if original == "":
24+
continue
25+
26+
EOL = "\r\n" if file.endswith((".csproj", ".sln", ".bat")) else "\n"
27+
WANTS_BOM = file.endswith((".csproj", ".sln"))
28+
29+
revamp = EOL.join([line.rstrip("\n\r\t ") for line in original.splitlines(True)]).rstrip(EOL) + EOL
30+
31+
new_raw = revamp.encode(encoding="utf-8")
32+
if not WANTS_BOM and new_raw.startswith(BOM):
33+
new_raw = new_raw[len(BOM) :]
34+
elif WANTS_BOM and not new_raw.startswith(BOM):
35+
new_raw = BOM + new_raw
36+
37+
with open(file, "rb") as f:
38+
old_raw = f.read()
39+
40+
if old_raw != new_raw:
41+
changed.append(file)
42+
with open(file, "wb") as f:
43+
f.write(new_raw)
44+
45+
if changed:
46+
for file in changed:
47+
print(f"FIXED: {file}")
48+
49+
if invalid:
50+
for file in invalid:
51+
print(f"REQUIRES MANUAL CHANGES: {file}")
52+
sys.exit(1)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: 📊 Static Checks
2+
on: [push, pull_request]
3+
4+
concurrency:
5+
group: ci-${{ github.actor }}-${{ github.head_ref || github.run_number }}-${{ github.ref }}-static
6+
7+
jobs:
8+
static-checks:
9+
name: Code style and file formatting
10+
runs-on: ubuntu-24.04
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 2
16+
17+
- name: Install Python dependencies and general setup
18+
run: |
19+
git config diff.wsErrorHighlight all
20+
21+
- name: Style checks via pre-commit
22+
uses: pre-commit/[email protected]
23+
with:
24+
extra_args: --all-files

.pre-commit-config.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
default_language_version:
2+
python: python3
3+
4+
exclude: |
5+
(?x)^(
6+
CODE_OF_CONDUCT.md
7+
)
8+
9+
repos:
10+
- repo: local
11+
hooks:
12+
- id: file-format
13+
name: file-format
14+
language: python
15+
entry: python .github/workflows/file_format.py
16+
types_or: [text]

CMakeLists.txt

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
1313
# For MSVC builds default to SSE enabled, and determine if it's a 64-bit (-A x64) vs. 32-bit (-A Win32) build.
1414
if (MSVC)
1515
option(SSE "SSE 4.1 support" TRUE)
16-
if ( CMAKE_GENERATOR_PLATFORM STREQUAL Win32 )
16+
if ( CMAKE_GENERATOR_PLATFORM STREQUAL Win32 )
1717
set(BUILD_X64 0)
1818
else()
1919
set(BUILD_X64 1)
@@ -71,25 +71,25 @@ endif()
7171
if (NOT MSVC)
7272
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
7373
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
74-
74+
7575
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
7676
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
7777

7878
if (SAN)
7979
message("Enabling SAN")
80-
80+
8181
set(SANITIZE_FLAGS "-fsanitize=address -fno-omit-frame-pointer -fsanitize=undefined -fno-sanitize=alignment")
82-
82+
8383
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZE_FLAGS}")
8484
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${SANITIZE_FLAGS}")
85-
85+
8686
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${SANITIZE_FLAGS}")
8787
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${SANITIZE_FLAGS}")
8888
endif()
8989

9090
set(CMAKE_CXX_FLAGS -std=c++17)
9191
set(GCC_COMPILE_FLAGS "-fvisibility=hidden -fPIC -fno-strict-aliasing -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Wno-unused-local-typedefs -Wno-unused-value -Wno-unused-parameter -Wno-unused-variable -Wno-reorder -Wno-misleading-indentation -Wno-class-memaccess -Wno-deprecated-copy -Wno-maybe-uninitialized -Wno-unused-function -Wno-stringop-overflow -Wno-unknown-warning-option")
92-
92+
9393
if (NOT BUILD_X64)
9494
set(GCC_COMPILE_FLAGS "${GCC_COMPILE_FLAGS} -m32")
9595
endif()
@@ -107,7 +107,7 @@ if (NOT MSVC)
107107
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0")
108108
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0")
109109
endif()
110-
110+
111111
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -static-libgcc -static-libstdc++ -static")
112112
else()
113113
if (SSE)
@@ -117,7 +117,7 @@ if (NOT MSVC)
117117
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_SSE=0")
118118
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_SSE=0")
119119
endif()
120-
120+
121121
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_LINK_FLAGS} -Wl,-rpath .")
122122
endif()
123123

@@ -163,7 +163,7 @@ set(ENCODER_LIB_SRC_LIST
163163
encoder/3rdparty/android_astc_decomp.cpp
164164
encoder/3rdparty/tinyexr.cpp
165165
transcoder/basisu_transcoder.cpp
166-
166+
167167
encoder/basisu_astc_hdr_6x6_enc.h
168168
encoder/basisu_astc_hdr_common.h
169169
encoder/basisu_backend.h
@@ -223,46 +223,46 @@ target_link_libraries(basisu PRIVATE basisu_encoder)
223223
if(EXAMPLES)
224224
add_executable(examples example/example.cpp)
225225
target_link_libraries(examples PRIVATE basisu_encoder)
226-
endif()
226+
endif()
227227

228228
#if (MSVC)
229229
target_sources(basisu PRIVATE "${CMAKE_SOURCE_DIR}/basisu.manifest")
230230
if(EXAMPLES)
231231
target_sources(examples PRIVATE "${CMAKE_SOURCE_DIR}/basisu.manifest")
232-
endif()
232+
endif()
233233
#endif()
234234

235235
if (ZSTD)
236236
target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1)
237237
if(EXAMPLES)
238238
target_compile_definitions(examples PRIVATE BASISD_SUPPORT_KTX2_ZSTD=1)
239-
endif()
239+
endif()
240240
else()
241241
target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0)
242242
if(EXAMPLES)
243243
target_compile_definitions(examples PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0)
244-
endif()
244+
endif()
245245
endif()
246246

247247
if (NOT MSVC)
248248
# For Non-Windows builds, let cmake try and find the system OpenCL headers/libs for us.
249249
if (OPENCL AND OPENCL_FOUND)
250250
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
251-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
252-
251+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
252+
253253
target_include_directories(basisu PRIVATE ${OpenCL_INCLUDE_DIRS})
254254
if(EXAMPLES)
255255
target_include_directories(examples PRIVATE ${OpenCL_INCLUDE_DIRS})
256-
endif()
256+
endif()
257257
target_include_directories(basisu_encoder PRIVATE ${OpenCL_INCLUDE_DIRS})
258258
set(BASISU_EXTRA_LIBS ${OpenCL_LIBRARIES})
259259
endif()
260260
else()
261261
# For Windows builds, we use our local copies of the OpenCL import lib and Khronos headers.
262262
if (OPENCL)
263263
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
264-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
265-
264+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBASISU_SUPPORT_OPENCL=1")
265+
266266
target_include_directories(basisu PRIVATE "OpenCL")
267267
if(EXAMPLES)
268268
target_include_directories(examples PRIVATE "OpenCL")
@@ -281,7 +281,7 @@ else()
281281
endif()
282282
endif()
283283
endif()
284-
endif()
284+
endif()
285285

286286
if (NOT MSVC)
287287
target_link_libraries(basisu PRIVATE m pthread ${BASISU_EXTRA_LIBS})
@@ -305,22 +305,21 @@ if (NOT EMSCRIPTEN)
305305
endif()
306306

307307
if (MSVC)
308-
set_target_properties(basisu PROPERTIES
308+
set_target_properties(basisu PROPERTIES
309309
RUNTIME_OUTPUT_NAME "basisu"
310310
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
311311
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
312312
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
313313
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
314-
)
315-
314+
)
315+
316316
if(EXAMPLES)
317-
set_target_properties(examples PROPERTIES
317+
set_target_properties(examples PROPERTIES
318318
RUNTIME_OUTPUT_NAME "examples"
319319
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
320320
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
321321
RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
322322
RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
323-
)
323+
)
324324
endif()
325325
endif()
326-

CppProperties.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
"intelliSenseMode": "windows-msvc-x64"
1919
}
2020
]
21-
}
21+
}

LICENSES/Apache-2.0.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ AND DISTRIBUTION
77

88
1. Definitions.
99

10-
10+
1111

1212
"License" shall mean the terms and conditions for use, reproduction, and distribution
1313
as defined by Sections 1 through 9 of this document.
1414

15-
15+
1616

1717
"Licensor" shall mean the copyright owner or entity authorized by the copyright
1818
owner that is granting the License.
1919

20-
20+
2121

2222
"Legal Entity" shall mean the union of the acting entity and all other entities
2323
that control, are controlled by, or are under common control with that entity.
@@ -26,31 +26,31 @@ or indirect, to cause the direction or management of such entity, whether
2626
by contract or otherwise, or (ii) ownership of fifty percent (50%) or more
2727
of the outstanding shares, or (iii) beneficial ownership of such entity.
2828

29-
29+
3030

3131
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions
3232
granted by this License.
3333

34-
34+
3535

3636
"Source" form shall mean the preferred form for making modifications, including
3737
but not limited to software source code, documentation source, and configuration
3838
files.
3939

40-
40+
4141

4242
"Object" form shall mean any form resulting from mechanical transformation
4343
or translation of a Source form, including but not limited to compiled object
4444
code, generated documentation, and conversions to other media types.
4545

46-
46+
4747

4848
"Work" shall mean the work of authorship, whether in Source or Object form,
4949
made available under the License, as indicated by a copyright notice that
5050
is included in or attached to the work (an example is provided in the Appendix
5151
below).
5252

53-
53+
5454

5555
"Derivative Works" shall mean any work, whether in Source or Object form,
5656
that is based on (or derived from) the Work and for which the editorial revisions,
@@ -59,7 +59,7 @@ original work of authorship. For the purposes of this License, Derivative
5959
Works shall not include works that remain separable from, or merely link (or
6060
bind by name) to the interfaces of, the Work and Derivative Works thereof.
6161

62-
62+
6363

6464
"Contribution" shall mean any work of authorship, including the original version
6565
of the Work and any modifications or additions to that Work or Derivative
@@ -74,7 +74,7 @@ for the purpose of discussing and improving the Work, but excluding communicatio
7474
that is conspicuously marked or otherwise designated in writing by the copyright
7575
owner as "Not a Contribution."
7676

77-
77+
7878

7979
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
8080
of whom a Contribution has been received by Licensor and subsequently incorporated

OpenCL/CL/cl_d3d10.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,3 @@ typedef cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)(
125125
#endif
126126

127127
#endif /* __OPENCL_CL_D3D10_H */
128-

OpenCL/CL/cl_d3d11.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,3 @@ typedef cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)(
125125
#endif
126126

127127
#endif /* __OPENCL_CL_D3D11_H */
128-

OpenCL/CL/cl_dx9_media_sharing.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C" {
3030

3131
typedef cl_uint cl_dx9_media_adapter_type_khr;
3232
typedef cl_uint cl_dx9_media_adapter_set_khr;
33-
33+
3434
#if defined(_WIN32)
3535
#include <d3d9.h>
3636
typedef struct _cl_dx9_surface_info_khr
@@ -91,7 +91,7 @@ typedef cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)(
9191
cl_mem_flags flags,
9292
cl_dx9_media_adapter_type_khr adapter_type,
9393
void * surface_info,
94-
cl_uint plane,
94+
cl_uint plane,
9595
cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2;
9696

9797
typedef cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)(
@@ -226,4 +226,3 @@ typedef cl_int (CL_API_CALL *clEnqueueReleaseDX9ObjectsINTEL_fn)(
226226
#endif
227227

228228
#endif /* __OPENCL_CL_DX9_MEDIA_SHARING_H */
229-

0 commit comments

Comments
 (0)