Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Add linter step with clang-format and buildifier. (#620)
Browse files Browse the repository at this point in the history
Also lint our files accordingly
  • Loading branch information
tnek authored Oct 1, 2021
1 parent 6ba5831 commit 58cec58
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 55 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,29 @@ jobs:
fi
done
if [[ $build_and_run_test != 0 ]]; then
if [[ $build_and_run_test != 0 ]]; then
echo "NEED TO RUN BUILD AND TESTS"
echo "::set-output name=run_build_and_tests::true"
else
else
echo "::set-output name=run_build_and_tests::false"
fi
if [[ $build_driver != 0 ]]; then
echo "NEED TO BUILD DRIVER"
echo "::set-output name=build_driver::true"
else
else
echo "::set-output name=build_driver::false"
fi
lint:
runs-on: ubuntu-latest
needs: [preqs]
if: needs.preqs.outputs.run_build_and_tests == 'true'
steps:
- uses: actions/checkout@v2
- name: Run linters
run: ./Testing/lint.sh

build_userspace:
runs-on: macos-latest
needs: [preqs]
Expand Down
5 changes: 2 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ package_group(
packages = ["//..."],
)


################################################################################
# Loading/Unloading/Reloading
################################################################################
Expand Down Expand Up @@ -223,15 +222,15 @@ genrule(
test_suite(
name = "unit_tests",
tests = [
"//Source/common:SantaCacheTest",
"//Source/common:SNTFileInfoTest",
"//Source/common:SNTPrefixTreeTest",
"//Source/common:SantaCacheTest",
"//Source/santactl:SNTCommandFileInfoTest",
"//Source/santactl:SNTCommandSyncTest",
"//Source/santad:SNTApplicationTest",
"//Source/santad:SNTEndpointSecurityManagerTest",
"//Source/santad:SNTEventTableTest",
"//Source/santad:SNTExecutionControllerTest",
"//Source/santad:SNTRuleTableTest",
"//Source/santad:SNTEndpointSecurityManagerTest",
],
)
2 changes: 1 addition & 1 deletion Source/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ santa_unit_test(
name = "SNTFileInfoTest",
srcs = ["SNTFileInfoTest.m"],
resources = [
"testdata/32bitplist",
"testdata/bad_pagezero",
"testdata/missing_pagezero",
"testdata/32bitplist",
],
structured_resources = glob([
"testdata/BundleExample.app/**",
Expand Down
1 change: 0 additions & 1 deletion Source/common/SNTXPCMetricServiceInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#import "Source/common/SNTXPCMetricServiceInterface.h"


@implementation SNTXPCMetricServiceInterface

+ (NSXPCInterface *)metricServiceInterface {
Expand Down
6 changes: 3 additions & 3 deletions Source/santa/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ macos_application(
app_icons = glob(["Resources/Images.xcassets/**"]),
bundle_id = "com.google.santa",
bundle_name = "Santa",
infoplists = ["Info.plist"],
minimum_os_version = "10.9",
entitlements = "Santa.app.entitlements",
codesignopts = [
"--timestamp",
"--force",
"--options library,kill,runtime",
],
entitlements = "Santa.app.entitlements",
infoplists = ["Info.plist"],
minimum_os_version = "10.9",
provisioning_profile = select({
"//:ci_build": None,
"//conditions:default": "Santa_Dev.provisionprofile",
Expand Down
2 changes: 1 addition & 1 deletion Source/santa_driver/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ cc_library(
"SANTA_VERSION=" + SANTA_VERSION,
],
deps = [
"//Source/common:SantaCache",
"//Source/common:SNTKernelCommon",
"//Source/common:SNTLoggingKernel",
"//Source/common:SNTPrefixTreeKernel",
"//Source/common:SantaCache",
],
alwayslink = 1,
)
Expand Down
4 changes: 2 additions & 2 deletions Source/santactl/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ objc_library(
macos_command_line_application(
name = "santactl",
bundle_id = "com.google.santa.ctl",
infoplists = ["Info.plist"],
minimum_os_version = "10.9",
codesignopts = [
"--timestamp",
"--force",
"--options library,kill,runtime",
],
infoplists = ["Info.plist"],
minimum_os_version = "10.9",
provisioning_profile = select({
"//:ci_build": None,
"//conditions:default": "Santa_Dev.provisionprofile",
Expand Down
45 changes: 22 additions & 23 deletions Source/santad/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ objc_library(
"DataLayer/SNTEventTable.m",
"DataLayer/SNTRuleTable.h",
"DataLayer/SNTRuleTable.m",
"EventProviders/SNTCachingEndpointSecurityManager.h",
"EventProviders/SNTCachingEndpointSecurityManager.mm",
"EventProviders/SNTDriverManager.h",
"EventProviders/SNTDriverManager.m",
"EventProviders/SNTEndpointSecurityManager.h",
"EventProviders/SNTEndpointSecurityManager.mm",
"EventProviders/SNTCachingEndpointSecurityManager.h",
"EventProviders/SNTCachingEndpointSecurityManager.mm",
"EventProviders/SNTEventProvider.h",
"Logs/SNTEventLog.h",
"Logs/SNTEventLog.m",
Expand Down Expand Up @@ -52,7 +52,6 @@ objc_library(
"IOKit",
],
deps = [
"//Source/common:SantaCache",
"//Source/common:SNTBlockMessage",
"//Source/common:SNTCachedDecision",
"//Source/common:SNTCommonEnums",
Expand All @@ -67,6 +66,7 @@ objc_library(
"//Source/common:SNTXPCControlInterface",
"//Source/common:SNTXPCNotifierInterface",
"//Source/common:SNTXPCSyncdInterface",
"//Source/common:SantaCache",
"@FMDB",
"@MOLCodesignChecker",
"@MOLXPCConnection",
Expand All @@ -75,11 +75,11 @@ objc_library(

objc_library(
name = "EndpointSecurityTestLib",
testonly = 1,
srcs = [
"EventProviders/EndpointSecurityTestUtil.h",
"EventProviders/EndpointSecurityTestUtil.mm",
],
testonly = 1,
sdk_dylibs = [
"EndpointSecurity",
"bsm",
Expand All @@ -90,14 +90,14 @@ macos_bundle(
name = "com.google.santa.daemon",
bundle_extension = "systemextension",
bundle_id = "com.google.santa.daemon",
infoplists = ["Info.plist"],
linkopts = ["-execute"],
minimum_os_version = "10.9",
codesignopts = [
"--timestamp",
"--force",
"--options library,kill,runtime",
],
infoplists = ["Info.plist"],
linkopts = ["-execute"],
minimum_os_version = "10.9",
provisioning_profile = select({
"//:ci_build": None,
"//conditions:default": "Santa_Daemon_Dev.provisionprofile",
Expand Down Expand Up @@ -140,7 +140,6 @@ santa_unit_test(
"bsm",
],
deps = [
"//Source/common:SantaCache",
"//Source/common:SNTBlockMessage",
"//Source/common:SNTCachedDecision",
"//Source/common:SNTCommonEnums",
Expand All @@ -152,6 +151,7 @@ santa_unit_test(
"//Source/common:SNTRule",
"//Source/common:SNTXPCNotifierInterface",
"//Source/common:SNTXPCSyncdInterface",
"//Source/common:SantaCache",
"@MOLCodesignChecker",
"@MOLXPCConnection",
"@OCMock",
Expand Down Expand Up @@ -201,42 +201,41 @@ santa_unit_test(
santa_unit_test(
name = "SNTEndpointSecurityManagerTest",
srcs = [
"EventProviders/SNTEndpointSecurityManager.h",
"EventProviders/SNTEndpointSecurityManager.mm",
"EventProviders/SNTEndpointSecurityManagerTest.mm",
"EventProviders/SNTEventProvider.h",
"EventProviders/SNTEndpointSecurityManager.mm",
"EventProviders/SNTEndpointSecurityManager.h",
],
sdk_dylibs = [
"EndpointSecurity",
"bsm",
],
deps = [
":EndpointSecurityTestLib",
"//Source/common:SNTKernelCommon",
"//Source/common:SNTPrefixTree",
"//Source/common:SantaCache",
],
sdk_dylibs = [
"EndpointSecurity",
"bsm",
],

)

santa_unit_test(
name = "SNTApplicationTest",
srcs = [
"SNTApplicationTest.m",
],
data = [
"//Source/santad/testdata:binaryrules_testdata",
],
srcs = [
"SNTApplicationTest.m"
minimum_os_version = "10.15",
sdk_dylibs = [
"EndpointSecurity",
"bsm",
],
deps = [
":santad_lib",
":EndpointSecurityTestLib",
":santad_lib",
"@MOLCodesignChecker",
"@MOLXPCConnection",
"@OCMock",
],
minimum_os_version = "10.15",
sdk_dylibs = [
"EndpointSecurity",
"bsm",
],
)
8 changes: 4 additions & 4 deletions Testing/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ licenses(["notice"])

santa_unit_test(
name = "SNTExecTest",
srcs = [
"SNTExecTest.m",
],
data = [
"//Source/santad/testdata:binaryrules_testdata",
],
srcs = [
"SNTExecTest.m"
],
deps = [],
minimum_os_version = "10.15",
deps = [],
)

test_suite(
Expand Down
8 changes: 8 additions & 0 deletions Testing/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
GIT_ROOT=$(git rev-parse --show-toplevel)

find $GIT_ROOT \( -name "*.m" -o -name "*.h" -name "*.mm" \) | xargs clang-format --Werror --dry-run

go get github.com/bazelbuild/buildtools/buildifier

~/go/bin/buildifier --lint=warn -r $GIT_ROOT
27 changes: 15 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
workspace(name = "santa")

load("@bazel_tools//tools/build_defs/repo:git.bzl",
"git_repository",
"new_git_repository",
load(
"@bazel_tools//tools/build_defs/repo:git.bzl",
"git_repository",
"new_git_repository",
)

git_repository(
name = "build_bazel_rules_apple",
commit = "a2deaf0e557edaad295533d1b21aa88ce1f0227d", # Latest commit that fixes https://github.com/google/santa/issues/595
remote = "https://github.com/bazelbuild/rules_apple.git",
commit = "a2deaf0e557edaad295533d1b21aa88ce1f0227d", # Latest commit that fixes https://github.com/google/santa/issues/595
)

load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")

apple_rules_dependencies()

load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")

apple_support_dependencies()

# Macops MOL* dependencies

git_repository(
name = "MOLAuthenticatingURLSession",
commit = "7ef7af5c732eb8b9375af29a65262be5d97ad391", # tag = v3.0
remote = "https://github.com/google/macops-molauthenticatingurlsession.git",
commit = "7ef7af5c732eb8b9375af29a65262be5d97ad391", # tag = v3.0
shallow_since = "1620062009 -0400",
)

Expand All @@ -40,18 +43,15 @@ git_repository(

git_repository(
name = "MOLXPCConnection",
commit = "2c67c925c2b57fea9af551295d2b6711b38bb224", # tag = v2.1
remote = "https://github.com/google/macops-molxpcconnection.git",
commit = "2c67c925c2b57fea9af551295d2b6711b38bb224", # tag = v2.1
shallow_since = "1564684202 -0400",
)

# FMDB

new_git_repository(
name = "FMDB",
remote = "https://github.com/ccgus/fmdb.git",
commit = "61e51fde7f7aab6554f30ab061cc588b28a97d04", # tag = 2.7.7
shallow_since = "1589301502 -0700",
build_file_content = """
objc_library(
name = "FMDB",
Expand All @@ -62,15 +62,15 @@ objc_library(
visibility = ["//visibility:public"],
)
""",
commit = "61e51fde7f7aab6554f30ab061cc588b28a97d04", # tag = 2.7.7
remote = "https://github.com/ccgus/fmdb.git",
shallow_since = "1589301502 -0700",
)

# OCMock

new_git_repository(
name = "OCMock",
remote = "https://github.com/erikdoe/ocmock",
commit = "4a49ebb985bc16fae9489771aa35482ccbea14a3", # tag = v3.8.1
shallow_since = "1609349457 +0100",
build_file_content = """
objc_library(
name = "OCMock",
Expand All @@ -88,4 +88,7 @@ objc_library(
visibility = ["//visibility:public"],
)
""",
commit = "4a49ebb985bc16fae9489771aa35482ccbea14a3", # tag = v3.8.1
remote = "https://github.com/erikdoe/ocmock",
shallow_since = "1609349457 +0100",
)

0 comments on commit 58cec58

Please sign in to comment.