Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run clang-format in GitHub Actions #488

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 5 additions & 32 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
BasedOnStyle: Google
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 120
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
AllowShortIfStatementsOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
ObjCSpaceAfterProperty: true
ObjCBlockIndentWidth: 4
ObjCSpaceBeforeProtocolList: true
SpaceAfterCStyleCast: false
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Cpp11BracedListStyle: false
ColumnLimit: 120
BreakBeforeBraces: Linux
PointerAlignment: Right
DerivePointerAlignment: false
PointerAlignment: Left
IndentCaseLabels: true
SpaceBeforeCpp11BracedList: true
Cpp11BracedListStyle: false
5 changes: 5 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Sources/KSCrashRecordingCore/KSObjCApple.h
GLinnik21 marked this conversation as resolved.
Show resolved Hide resolved
Sources/KSCrashRecordingCore/llvm/*
Sources/KSCrashRecordingCore/llvm/*/*
Sources/KSCrashRecordingCore/swift/*
Sources/KSCrashRecordingCore/swift/*/*
61 changes: 61 additions & 0 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Clang Format Check
on:
pull_request:
paths:
- 'Sources/**'
- 'Tests/**'
GLinnik21 marked this conversation as resolved.
Show resolved Hide resolved
- 'Samples/Common/Sources/CrashTriggers/**'
- '.github/workflows/clang-format.yml'
- '.clang-format-ignore'

jobs:
formatting-check:
name: Formatting Check
runs-on: ubuntu-latest
env:
DIRS: 'Sources Tests Samples/Common/Sources/CrashTriggers'
steps:
- uses: actions/checkout@v4

- name: Install clang-format-18
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 18
sudo apt-get install -y clang-format-18

- name: Check formatting
id: check_format
run: |
find $DIRS -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.m' -o -name '*.mm' | \
xargs -r clang-format-18 -style=file -n -Werror 2> clang_format_errors.log

- name: Suggest formatting fixes
if: failure()
run: |
echo "##[error]Formatting issues found. Please run clang-format-18 on your code."

- name: Create summary and annotations
if: failure()
run: |
echo "### Formatting issues found" >> $GITHUB_STEP_SUMMARY
echo "Please run clang-format-18 on your code." >> $GITHUB_STEP_SUMMARY
echo "Note: Some files may be excluded from formatting based on .clang-format-ignore file." >> $GITHUB_STEP_SUMMARY
echo "::group::Formatting issues"
awk '
/^.*error:/ {
split($0, parts, ":")
file=parts[1]
line=parts[2]
col=parts[3]
message=$0
getline code_line
getline caret_line
sub(/:.*$/, "", file)
sub(/[^0-9]/, "", line)
sub(/[^0-9]/, "", col)
# Remove the "error: " prefix from the message
sub(/^[^:]+: [^:]+: [^:]+: /, "", message)
print "::error file="file",line="line",col="col"::"message
}' clang_format_errors.log
echo "::endgroup::"
4 changes: 1 addition & 3 deletions Samples/Common/Sources/CrashTriggers/CrashTriggers.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ @implementation CrashTriggers

+ (void)nsexception
{
NSException *exc = [NSException exceptionWithName:NSGenericException
reason:@"Test"
userInfo:@{ @"a": @"b"}];
NSException *exc = [NSException exceptionWithName:NSGenericException reason:@"Test" userInfo:@{ @"a" : @"b" }];
[exc raise];
}

Expand Down
45 changes: 15 additions & 30 deletions Sources/KSCrashBootTimeMonitor/KSCrashMonitor_BootTime.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#import "KSCrashMonitor_BootTime.h"

#import "KSCrashMonitorContext.h"
#import "KSSysCtl.h"
#import "KSDate.h"
#import "KSSysCtl.h"

#import <sys/types.h>
#import <Foundation/Foundation.h>
#import <sys/types.h>

static volatile bool g_isEnabled = false;

Expand All @@ -47,58 +47,43 @@ void kscm_bootTime_resetState(void)
*
* @return The result of the sysctl call.
*/
static const char* dateSysctl(const char* name)
static const char *dateSysctl(const char *name)
{
struct timeval value = kssysctl_timevalForName(name);
char* buffer = malloc(21);
char *buffer = malloc(21);
ksdate_utcStringFromTimestamp(value.tv_sec, buffer);
return buffer;
}

#pragma mark - API -

static const char* monitorId(void)
{
return "BootTime";
}
static const char *monitorId(void) { return "BootTime"; }

static void setEnabled(bool isEnabled)
{
if(isEnabled != g_isEnabled)
{
if (isEnabled != g_isEnabled) {
g_isEnabled = isEnabled;
}
}

static bool isEnabled(void)
{
return g_isEnabled;
}
static bool isEnabled(void) { return g_isEnabled; }

static void addContextualInfoToEvent(KSCrash_MonitorContext* eventContext)
static void addContextualInfoToEvent(KSCrash_MonitorContext *eventContext)
{
if(g_isEnabled)
{
if (g_isEnabled) {
eventContext->System.bootTime = dateSysctl("kern.boottime");
}
}

KSCrashMonitorAPI* kscm_boottime_getAPI(void)
KSCrashMonitorAPI *kscm_boottime_getAPI(void)
{
static KSCrashMonitorAPI api =
{
.monitorId = monitorId,
.setEnabled = setEnabled,
.isEnabled = isEnabled,
.addContextualInfoToEvent = addContextualInfoToEvent
};
static KSCrashMonitorAPI api = { .monitorId = monitorId,
.setEnabled = setEnabled,
.isEnabled = isEnabled,
.addContextualInfoToEvent = addContextualInfoToEvent };
return &api;
}

#pragma mark - Injection -

__attribute__((constructor))
static void kscm_boottime_register(void)
{
kscm_addMonitor(kscm_boottime_getAPI());
}
__attribute__((constructor)) static void kscm_boottime_register(void) { kscm_addMonitor(kscm_boottime_getAPI()); }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// KSCrashMonitor_BootTime.h
//
//
// Created by Gleb Linnik on 04.06.2024.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
Expand All @@ -24,7 +24,6 @@
// THE SOFTWARE.
//


#ifndef KSCrashMonitor_BootTime_h
#define KSCrashMonitor_BootTime_h

Expand All @@ -36,7 +35,7 @@ extern "C" {

/** Access the Monitor API.
*/
KSCrashMonitorAPI* kscm_boottime_getAPI(void);
KSCrashMonitorAPI *kscm_boottime_getAPI(void);

#ifdef __cplusplus
}
Expand Down
43 changes: 20 additions & 23 deletions Sources/KSCrashCore/NSError+SimpleConstructor.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,51 @@

#import "NSError+SimpleConstructor.h"


@implementation NSError (SimpleConstructor)

+ (NSError*) errorWithDomain:(NSString*) domain code:(NSInteger) code description:(NSString*) fmt, ...
+ (NSError *)errorWithDomain:(NSString *)domain code:(NSInteger)code description:(NSString *)fmt, ...
{
va_list args;
va_start(args, fmt);
NSString* desc = [[NSString alloc] initWithFormat:fmt arguments:args];

NSString *desc = [[NSString alloc] initWithFormat:fmt arguments:args];
va_end(args);

return [NSError errorWithDomain:domain
code:code
userInfo:[NSDictionary dictionaryWithObject:desc
forKey:NSLocalizedDescriptionKey]];
userInfo:[NSDictionary dictionaryWithObject:desc forKey:NSLocalizedDescriptionKey]];
}

+ (BOOL) fillError:(NSError* __autoreleasing *) error
withDomain:(NSString*) domain
code:(NSInteger) code
description:(NSString*) fmt, ...
+ (BOOL)fillError:(NSError *__autoreleasing *)error
withDomain:(NSString *)domain
code:(NSInteger)code
description:(NSString *)fmt, ...
{
if(error != nil)
{
if (error != nil) {
va_list args;
va_start(args, fmt);
NSString* desc = [[NSString alloc] initWithFormat:fmt arguments:args];

NSString *desc = [[NSString alloc] initWithFormat:fmt arguments:args];
va_end(args);

*error = [NSError errorWithDomain:domain
code:code
userInfo:[NSDictionary dictionaryWithObject:desc
forKey:NSLocalizedDescriptionKey]];
userInfo:[NSDictionary dictionaryWithObject:desc forKey:NSLocalizedDescriptionKey]];
}
return NO;
}

+ (BOOL) clearError:(NSError* __autoreleasing *) error
+ (BOOL)clearError:(NSError *__autoreleasing *)error
{
if(error != nil)
{
if (error != nil) {
*error = nil;
}
return NO;
}

@end

@interface NSError_SimpleConstructor_AOG8G : NSObject @end @implementation NSError_SimpleConstructor_AOG8G @end

@interface NSError_SimpleConstructor_AOG8G : NSObject
@end
@implementation NSError_SimpleConstructor_AOG8G
@end
6 changes: 3 additions & 3 deletions Sources/KSCrashCore/include/KSSystemCapabilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// THE SOFTWARE.
//


#ifndef HDR_KSSystemCapabilities_h
#define HDR_KSSystemCapabilities_h

Expand All @@ -44,7 +43,8 @@
#define KSCRASH_HOST_IOS (KSCRASH_HOST_APPLE && TARGET_OS_IOS)
#define KSCRASH_HOST_TV (KSCRASH_HOST_APPLE && TARGET_OS_TV)
#define KSCRASH_HOST_WATCH (KSCRASH_HOST_APPLE && TARGET_OS_WATCH)
#define KSCRASH_HOST_MAC (KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || KSCRASH_HOST_VISION))
#define KSCRASH_HOST_MAC \
(KSCRASH_HOST_APPLE && TARGET_OS_MAC && !(TARGET_OS_IOS || TARGET_OS_TV || TARGET_OS_WATCH || KSCRASH_HOST_VISION))

#if KSCRASH_HOST_APPLE
#define KSCRASH_CAN_GET_MAC_ADDRESS 1
Expand Down Expand Up @@ -151,4 +151,4 @@
#define KSCRASH_HAS_REACHABILITY 0
#endif

#endif // HDR_KSSystemCapabilities_h
#endif // HDR_KSSystemCapabilities_h
11 changes: 3 additions & 8 deletions Sources/KSCrashCore/include/NSError+SimpleConstructor.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
* @param fmt Description of the error (gets placed into the user data with the key
* NSLocalizedDescriptionKey).
*/
+ (NSError*) errorWithDomain:(NSString*) domain
code:(NSInteger) code
description:(NSString*) fmt, ...;
+ (NSError *)errorWithDomain:(NSString *)domain code:(NSInteger)code description:(NSString *)fmt, ...;

/** Fill an error pointer with an NSError object if it's not nil.
*
Expand All @@ -53,17 +51,14 @@
* NSLocalizedDescriptionKey).
* @return NO (to keep the analyzer happy).
*/
+ (BOOL) fillError:(NSError**) error
withDomain:(NSString*) domain
code:(NSInteger) code
description:(NSString*) fmt, ...;
+ (BOOL)fillError:(NSError **)error withDomain:(NSString *)domain code:(NSInteger)code description:(NSString *)fmt, ...;

/** Clear a pointer-to-error to nil of its pointer is not nil.
*
* @param error Error pointer to fill (ignored if nil).
* @return NO (to keep the analyzer happy).
*/
+ (BOOL) clearError:(NSError**) error;
+ (BOOL)clearError:(NSError **)error;

@end

Expand Down
Loading
Loading