Skip to content

Commit

Permalink
Adding Concurrency Checks and Fixes (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion authored Mar 9, 2024
1 parent 485d9fd commit 54c727e
Show file tree
Hide file tree
Showing 17 changed files with 394 additions and 28 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/FelinePine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
runs-on: [ubuntu-20.04, ubuntu-22.04]
swift-version: [5.8.1, 5.9]
swift-version: [5.8.1, 5.9, "5.10"]
steps:
- uses: actions/checkout@v3
- name: Cache swift package modules
Expand Down Expand Up @@ -70,17 +70,30 @@ jobs:
strategy:
matrix:
include:
- xcode: "/Applications/Xcode_14.3.1.app"
- runs-on: macos-13
xcode: "/Applications/Xcode_14.3.1.app"
iOSVersion: "16.4"
watchOSVersion: "9.4"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 14 Pro Max"
watchName: "Apple Watch Series 5 (40mm)"
iPhoneName: "iPhone 14"
- runs-on: macos-13
xcode: "/Applications/Xcode_15.0.1.app"
iOSVersion: "17.0.1"
watchOSVersion: "10.0"
watchName: "Apple Watch Ultra (49mm)"
iPhoneName: "iPhone 15 Pro Max"
watchName: "Apple Watch Series 8 (41mm)"
iPhoneName: "iPhone 15"
- runs-on: macos-14
xcode: "/Applications/Xcode_15.1.app"
iOSVersion: "17.2"
watchOSVersion: "10.2"
watchName: "Apple Watch Series 9 (41mm)"
iPhoneName: "iPhone 15 Plus"
- runs-on: macos-14
xcode: "/Applications/Xcode_15.2.app"
iOSVersion: "17.2"
watchOSVersion: "10.2"
watchName: "Apple Watch Series 9 (45mm)"
iPhoneName: "iPhone 15 Pro"
steps:
- uses: actions/checkout@v3
- name: Cache swift package modules
Expand Down
4 changes: 2 additions & 2 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--indent 2
--header strip
--header "\n {file}.swift\n FelinePine\n\n Created by Leo Dion.\n Copyright © {year} BrightDigit.\n\n Permission is hereby granted, free of charge, to any person\n obtaining a copy of this software and associated documentation\n files (the “Software”), to deal in the Software without\n restriction, including without limitation the rights to use,\n copy, modify, merge, publish, distribute, sublicense, and/or\n sell copies of the Software, and to permit persons to whom the\n Software is furnished to do so, subject to the following\n conditions:\n \n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of the Software.\n\n THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,\n EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\n OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\n OTHER DEALINGS IN THE SOFTWARE.\n"
--commas inline
--disable wrapMultilineStatementBraces
--disable wrapMultilineStatementBraces, redundantInternal
--extensionacl on-declarations
--decimalgrouping 3,4
--exclude .build, DerivedData, Sample
7 changes: 0 additions & 7 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
opt_in_rules:
- anyobject_protocol
- array_init
- attributes
- closure_body_length
Expand All @@ -22,11 +21,9 @@ opt_in_rules:
- expiring_todo
- explicit_acl
- explicit_init
- explicit_self
- explicit_top_level_acl
- fallthrough
- fatal_error_message
- file_header
- file_name
- file_name_no_space
- file_types_order
Expand All @@ -46,7 +43,6 @@ opt_in_rules:
- lower_acl_than_parent
- missing_docs
- modifier_order
#- multiline_arguments
- multiline_arguments_brackets
- multiline_function_chains
- multiline_literal_brackets
Expand Down Expand Up @@ -82,13 +78,10 @@ opt_in_rules:
- strong_iboutlet
- switch_case_on_newline
- toggle_bool
#- trailing_closure
- type_contents_order
- unavailable_function
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- unused_declaration
- unused_import
- vertical_parameter_alignment_on_call
- vertical_whitespace_between_cases
- vertical_whitespace_closing_braces
Expand Down
4 changes: 2 additions & 2 deletions Mintfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
nicklockwood/SwiftFormat@0.47.0
realm/SwiftLint@0.41.0
nicklockwood/SwiftFormat@0.52.11
realm/SwiftLint@0.54.0
peripheryapp/[email protected]
11 changes: 11 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ let package = Package(
package: "swift-log",
condition: .when(platforms: [.linux, .android, .wasi, .windows])
)
],
swiftSettings: [
SwiftSetting.enableUpcomingFeature("BareSlashRegexLiterals"),
SwiftSetting.enableUpcomingFeature("ConciseMagicFile"),
SwiftSetting.enableUpcomingFeature("ExistentialAny"),
SwiftSetting.enableUpcomingFeature("ForwardTrailingClosures"),
SwiftSetting.enableUpcomingFeature("ImplicitOpenExistentials"),
SwiftSetting.enableUpcomingFeature("StrictConcurrency"),
SwiftSetting.enableUpcomingFeature("DisableOutwardActorInference"),
SwiftSetting.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
Expand All @@ -32,3 +42,4 @@ let package = Package(
)
]
)
// swiftlint:enable explicit_acl explicit_top_level_acl
4 changes: 2 additions & 2 deletions Scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ pushd $PACKAGE_DIR

if [ -z "$CI" ]; then
$MINT_RUN swiftformat .
$MINT_RUN swiftlint autocorrect
$MINT_RUN swiftlint --autocorrect
fi

$MINT_RUN periphery scan
$MINT_RUN periphery scan --disable-update-check
$MINT_RUN swiftformat --lint $SWIFTFORMAT_OPTIONS .
$MINT_RUN swiftlint lint $SWIFTLINT_OPTIONS

Expand Down
29 changes: 29 additions & 0 deletions Sources/FelinePine/Feline.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
//
// Feline.swift
// FelinePine
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
#if canImport(os)
import os
Expand Down
29 changes: 29 additions & 0 deletions Sources/FelinePine/Loggable.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
//
// Loggable.swift
// FelinePine
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation

/// Loggable type for a ``LoggingSystem``.
Expand Down
29 changes: 29 additions & 0 deletions Sources/FelinePine/Logger+LoggerCategory.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
//
// Logger+LoggerCategory.swift
// FelinePine
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
#if canImport(os)
import os
Expand Down
30 changes: 30 additions & 0 deletions Sources/FelinePine/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
//
// Logger.swift
// FelinePine
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

// swiftlint:disable file_types_order

#if canImport(os)
Expand All @@ -9,3 +38,4 @@
/// swift-log Logging.Logger
public typealias Logger = Logging.Logger
#endif
// swiftlint:enable file_types_order
62 changes: 53 additions & 9 deletions Sources/FelinePine/LoggingSystem.swift
Original file line number Diff line number Diff line change
@@ -1,28 +1,72 @@
//
// LoggingSystem.swift
// FelinePine
//
// Created by Leo Dion.
// Copyright © 2024 BrightDigit.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

import Foundation
#if canImport(os)
import os
#else
import Logging
#endif

private enum LoggingSystemRepository {
static var items = [String: Any]()
static func loggingSystem<LoggingSystemType: LoggingSystem>(
// swiftlint:disable strict_fileprivate
private class LoggingSystemRepository: @unchecked Sendable {
fileprivate static let shared = LoggingSystemRepository()

private let lock = NSRecursiveLock()
private var items = [String: Any]()

private init(items: [String: Any] = [String: Any]()) {
self.items = items
}

fileprivate func loggingSystem<LoggingSystemType: LoggingSystem>(
for system: LoggingSystemType.Type,
using value: @autoclosure () -> [LoggingSystemType.Category: Logger]
) -> [LoggingSystemType.Category: Logger] {
let anyItem = items[system.identifier]
let anyItem = lock.withLock {
items[system.identifier]
}
if let item = anyItem as? [LoggingSystemType.Category: Logger] {
return item
} else {
assert(anyItem == nil)
let value = value()
items[system.identifier] = value
return value
return lock.withLock {
let value = value()
items[system.identifier] = value
return value
}
}
}
}

// swiftlint:enable strict_fileprivate

/// Defines the logging categories for your application.
public protocol LoggingSystem {
/// Logging categories available to types in the application
Expand Down Expand Up @@ -59,13 +103,13 @@ extension LoggingSystem {

extension LoggingSystem where Category: CaseIterable {
private static var loggers: [Category: Logger] {
LoggingSystemRepository.loggingSystem(for: Self.self, using: defaultLoggers())
LoggingSystemRepository.shared.loggingSystem(for: Self.self, using: defaultLoggers())
}

/// If ``Category`` implements `CaseIterable`, ``LoggingSystem`` can automatically
/// iterate over the cases and automatically create the ``Logger`` objects needed.
public static func logger(forCategory category: Category) -> Logger {
guard let logger = Self.loggers[category] else {
guard let logger = loggers[category] else {
preconditionFailure("missing logger")
}
return logger
Expand Down
Loading

0 comments on commit 54c727e

Please sign in to comment.