Skip to content

Commit bdd688b

Browse files
authored
feat: add logging option (#10)
* feat: add logging option * chore: update log messages * wip: fix ubuntu version and swift version mismatch * wip: add `executionTimeAllowance` only for mac platforms * wip: remove unnecessary base test class * wip: remove duplication * refactor: remove use of lock for synchronization * wip: add additional logs to continuation tracking * wip: add more logs * wip: move all the mutation to actor isolated context * wip: format code * wip: add more logs * wip: add deinitialization log * wip: remove cleanup logic from actor deinit * wip: add additional logs * wip: add `@_unsafeInheritExecutor` flags * wip: remove `@_unsafeInheritExecutor` * wip: remove `@escaping` where not needed * wip: add `@_unsafeInheritExecutor` flags * test: forward file and line for assertions
1 parent d1c5531 commit bdd688b

29 files changed

+2882
-1402
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
"swift": "5.7"
6060
},
6161
{
62-
"os": "ubuntu-latest",
62+
"os": "ubuntu-20.04",
6363
"swift": "5.6"
6464
}
6565
]

AsyncObjects.podspec

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,31 @@ Pod::Spec.new do |s|
3838
}
3939

4040
s.dependency 'OrderedCollections', '~> 1.0.0'
41+
s.default_subspecs = :none
42+
43+
s.subspec 'Checked' do |ss|
44+
ss.pod_target_xcconfig = {
45+
'OTHER_SWIFT_FLAGS' => '-D ASYNCOBJECTS_USE_CHECKEDCONTINUATION'
46+
}
47+
end
48+
49+
s.subspec 'Logging' do |ss|
50+
ss.dependency 'Logging', '~> 1.0.0'
51+
# ss.default_subspec = 'Info'
52+
53+
for level in ['Debug', 'Info', 'Trace'] do
54+
ss.subspec level do |sss|
55+
sss.pod_target_xcconfig = {
56+
'OTHER_SWIFT_FLAGS' => "-D ASYNCOBJECTS_ENABLE_LOGGING_LEVEL_#{level.upcase}"
57+
}
58+
end
59+
end
60+
end
4161

4262
s.test_spec do |ts|
4363
ts.source_files = "Tests/#{s.name}Tests/**/*.swift"
64+
ts.dependency "#{s.name}/Checked"
65+
ts.dependency "#{s.name}/Logging"
4466
ts.scheme = { :parallelizable => true }
4567
end
4668
end

AsyncObjects.xcodeproj/project.pbxproj

Lines changed: 416 additions & 403 deletions
Large diffs are not rendered by default.

Package.swift

Lines changed: 52 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,97 +3,74 @@
33
import PackageDescription
44
import class Foundation.ProcessInfo
55

6-
let appleGitHub = "https://github.com/apple"
7-
let package = Package(
8-
name: "AsyncObjects",
9-
platforms: [
10-
.macOS(.v10_15),
11-
.iOS(.v13),
12-
.tvOS(.v13),
13-
.watchOS(.v6),
14-
],
15-
products: [
16-
.library(
17-
name: "AsyncObjects",
18-
targets: ["AsyncObjects"]
19-
),
20-
],
21-
dependencies: [
22-
.package(url: "\(appleGitHub)/swift-collections.git", from: "1.0.0"),
23-
.package(url: "\(appleGitHub)/swift-docc-plugin", from: "1.0.0"),
24-
.package(url: "\(appleGitHub)/swift-format", from: "0.50700.0"),
25-
],
26-
targets: [
27-
.target(
28-
name: "AsyncObjects",
29-
dependencies: [
30-
.product(
31-
name: "OrderedCollections",
32-
package: "swift-collections"
33-
),
34-
],
35-
swiftSettings: swiftSettings
36-
),
37-
.testTarget(
38-
name: "AsyncObjectsTests",
39-
dependencies: ["AsyncObjects"],
40-
swiftSettings: testingSwiftSettings
41-
),
6+
var dependencies: [Target.Dependency] = {
7+
var dependencies: [Target.Dependency] = [
8+
.product(name: "OrderedCollections", package: "swift-collections")
429
]
43-
)
4410

45-
var swiftSettings: [SwiftSetting] = {
46-
var swiftSettings: [SwiftSetting] = []
11+
if ProcessInfo.processInfo.environment["ASYNCOBJECTS_ENABLE_LOGGING_LEVEL"] != nil {
12+
dependencies.append(.product(name: "Logging", package: "swift-log"))
13+
}
14+
15+
return dependencies
16+
}()
17+
18+
var settings: [SwiftSetting] = {
19+
var settings: [SwiftSetting] = []
4720

48-
if ProcessInfo.processInfo.environment[
49-
"SWIFTCI_CONCURRENCY_CHECKS"
50-
] != nil {
51-
swiftSettings.append(
21+
if ProcessInfo.processInfo.environment["SWIFTCI_CONCURRENCY_CHECKS"] != nil {
22+
settings.append(
5223
.unsafeFlags([
5324
"-Xfrontend",
5425
"-warn-concurrency",
5526
"-enable-actor-data-race-checks",
5627
"-require-explicit-sendable",
28+
"-strict-concurrency=complete"
5729
])
5830
)
5931
}
6032

61-
if ProcessInfo.processInfo.environment[
62-
"SWIFTCI_WARNINGS_AS_ERRORS"
63-
] != nil {
64-
swiftSettings.append(
65-
.unsafeFlags([
66-
"-warnings-as-errors"
67-
])
68-
)
33+
if ProcessInfo.processInfo.environment["SWIFTCI_WARNINGS_AS_ERRORS"] != nil {
34+
settings.append(.unsafeFlags(["-warnings-as-errors"]))
6935
}
7036

71-
if ProcessInfo.processInfo.environment[
72-
"ASYNCOBJECTS_USE_CHECKEDCONTINUATION"
73-
] != nil {
74-
swiftSettings.append(
75-
.define("ASYNCOBJECTS_USE_CHECKEDCONTINUATION")
76-
)
37+
if ProcessInfo.processInfo.environment["ASYNCOBJECTS_USE_CHECKEDCONTINUATION"] != nil {
38+
settings.append(.define("ASYNCOBJECTS_USE_CHECKEDCONTINUATION"))
7739
}
7840

79-
return swiftSettings
80-
}()
81-
82-
var testingSwiftSettings: [SwiftSetting] = {
83-
var swiftSettings: [SwiftSetting] = []
84-
85-
if ProcessInfo.processInfo.environment[
86-
"SWIFTCI_CONCURRENCY_CHECKS"
87-
] != nil {
88-
swiftSettings.append(
89-
.unsafeFlags([
90-
"-Xfrontend",
91-
"-warn-concurrency",
92-
"-enable-actor-data-race-checks",
93-
"-require-explicit-sendable",
94-
])
95-
)
41+
if let level = ProcessInfo.processInfo.environment["ASYNCOBJECTS_ENABLE_LOGGING_LEVEL"] {
42+
if level.caseInsensitiveCompare("TRACE") == .orderedSame {
43+
settings.append(.define("ASYNCOBJECTS_ENABLE_LOGGING_LEVEL_TRACE"))
44+
} else if level.caseInsensitiveCompare("DEBUG") == .orderedSame {
45+
settings.append(.define("ASYNCOBJECTS_ENABLE_LOGGING_LEVEL_DEBUG"))
46+
} else {
47+
settings.append(.define("ASYNCOBJECTS_ENABLE_LOGGING_LEVEL_INFO"))
48+
}
9649
}
9750

98-
return swiftSettings
51+
return settings
9952
}()
53+
54+
let appleGitHub = "https://github.com/apple"
55+
let package = Package(
56+
name: "AsyncObjects",
57+
platforms: [
58+
.macOS(.v10_15),
59+
.iOS(.v13),
60+
.tvOS(.v13),
61+
.watchOS(.v6),
62+
],
63+
products: [
64+
.library(name: "AsyncObjects", targets: ["AsyncObjects"]),
65+
],
66+
dependencies: [
67+
.package(url: "\(appleGitHub)/swift-collections.git", from: "1.0.0"),
68+
.package(url: "\(appleGitHub)/swift-docc-plugin", from: "1.0.0"),
69+
.package(url: "\(appleGitHub)/swift-format", from: "0.50700.0"),
70+
.package(url: "\(appleGitHub)/swift-log.git", from: "1.0.0"),
71+
],
72+
targets: [
73+
.target(name: "AsyncObjects", dependencies: dependencies, swiftSettings: settings),
74+
.testTarget(name: "AsyncObjectsTests", dependencies: ["AsyncObjects"]),
75+
]
76+
)

0 commit comments

Comments
 (0)