Core: Add clang script and check on building release

This commit is contained in:
zilmar 2022-12-19 15:51:02 +10:30
parent bd1b1b4dbb
commit 620aabcf9e
5 changed files with 124 additions and 3 deletions

BIN
Bin/clang-format-12.exe Normal file

Binary file not shown.

37
Source/.clang-format Normal file
View File

@ -0,0 +1,37 @@
---
BasedOnStyle: Microsoft
Language: Cpp
Standard: Cpp11
AccessModifierOffset: -4
AllowShortEnumsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: WithoutElse
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakInheritanceList: AfterColon
BreakConstructorInitializers: AfterColon
BreakStringLiterals: false
ColumnLimit: 0
IndentCaseLabels: false
IndentWidth: 4
PointerAlignment: Middle
SortIncludes: true
SpaceAfterTemplateKeyword: true
SpaceBeforeParens: ControlStatements
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Never
...

View File

@ -17,7 +17,6 @@ class CX86Ops :
public asmjit::Logger public asmjit::Logger
{ {
public: public:
enum Multipler enum Multipler
{ {
Multip_x1 = 1, Multip_x1 = 1,
@ -130,7 +129,7 @@ private:
}; };
static x86Reg RegValue(const asmjit::x86::Gp & Reg); static x86Reg RegValue(const asmjit::x86::Gp & Reg);
asmjit::Error _log(const char* data, size_t size) noexcept; asmjit::Error _log(const char * data, size_t size) noexcept;
void AddSymbol(const char * SymbolKey, const char * SymbolValue); void AddSymbol(const char * SymbolKey, const char * SymbolValue);
void RemoveSymbol(const char * SymbolKey); void RemoveSymbol(const char * SymbolKey);
std::string VariableSymbol(void * Variable) const; std::string VariableSymbol(void * Variable) const;

View File

@ -52,6 +52,9 @@
<ClCompile> <ClCompile>
<AdditionalIncludeDirectories>$(SolutionDir)Source\3rdParty\asmjit\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(SolutionDir)Source\3rdParty\asmjit\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile> </ClCompile>
<PostBuildEvent>
<Command Condition="'$(Configuration)'=='Release'">"$(SolutionDir)\Source\Script\clang.cmd" check</Command>
</PostBuildEvent>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="UserInterface\About.cpp" /> <ClCompile Include="UserInterface\About.cpp" />

82
Source/Script/clang.cmd Normal file
View File

@ -0,0 +1,82 @@
@echo off
setlocal EnableDelayedExpansion
set origdir=%cd%
cd /d %~dp0..\..
set base_dir=%cd%
cd /d %origdir%
set ScanDir[0]="%base_dir%\Source\Common"
set ScanDir[1]="%base_dir%\Source\Project64"
set ScanDir[2]="%base_dir%\Source\Project64-core"
set ScanFiles[0]="*.cpp"
set ScanFiles[1]="*.h"
set Exclude[0]="%base_dir%\Source\Project64-core\Version.h"
set Exclude[1]="%base_dir%\Source\Project64\UserInterface\resource.h"
set ValidParam=0
if "%1" == "check" set ValidParam=1
if "%1" == "format" set ValidParam=1
IF %ValidParam%==0 GOTO :Usage
if "%1" == "check" echo Checking code formatting
if "%1" == "check" set ClangParm=-style=file -Werror --dry-run
if "%1" == "format" set ClangParm=-i -style=file
set /a Result=0
set /a DirectoryIndex=0
:DirectoryLoop
if defined ScanDir[%DirectoryIndex%] (
CALL :ProcessDirectory %DirectoryIndex%
set /a DirectoryIndex += 1
GOTO :DirectoryLoop
)
exit /b %Result%
:ProcessDirectory
call set Directory=%%ScanDir[%1]%%
set /a ScanFilesIndex=0
:ScanFilesLoop
if defined ScanFiles[%ScanFilesIndex%] (
CALL :ProcessDirectoryFiles %ScanFilesIndex%
set /a ScanFilesIndex += 1
GOTO :ScanFilesLoop
)
goto :end
:ProcessDirectoryFiles
call set Files=%%ScanFiles[%1]%%
For /R %Directory% %%A In (%Files%) Do (
::"%base_dir%\bin\clang-format-12.exe" -i -style=file "%%A"
CALL :ProcessFile "%%A"
)
goto :end
:ProcessFile
set /a ExcludeIndex=0
:ExcludeLoop
if defined Exclude[%ExcludeIndex%] (
call set ExcludeFile=%%Exclude[%ExcludeIndex%]%%
if %1==!ExcludeFile! (
goto :end
)
set /a ExcludeIndex += 1
GOTO :ExcludeLoop
)
"%base_dir%\bin\clang-format-12.exe" %ClangParm% %1
IF %ERRORLEVEL% NEQ 0 set /a Result=1
goto :end
:Usage
echo clang.cmd [format/check]
echo check - checks to see if any code would have to change
echo format - change the code to meet clang formating
:end