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

Update EnvironmentHelper API #122

Merged
merged 1 commit into from
Sep 24, 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
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/App/AppGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

private lazy var launchProfileOptions = LaunchProfileOptions(
rawValue: EnvironmentHelper.value(for: "OPENSWIFTUI_PROFILE_LAUNCH")
rawValue: EnvironmentHelper.int32(for: "OPENSWIFTUI_PROFILE_LAUNCH")

Check warning on line 28 in Sources/OpenSwiftUI/App/AppGraph.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/App/AppGraph.swift#L28

Added line #L28 was not covered by tests
)

var didCollectLaunchProfile: Bool = false
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Core/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
internal import COpenSwiftUI
internal import OpenGraphShims

private let waitingForPreviewThunks = EnvironmentHelper.value(for: "XCODE_RUNNING_FOR_PREVIEWS") != 0
private let waitingForPreviewThunks = EnvironmentHelper.bool(for: "XCODE_RUNNING_FOR_PREVIEWS")
private var blockedGraphHosts: [Unmanaged<GraphHost>] = []

class GraphHost {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/Test/_BenchmarkHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
import QuartzCore
#endif

private let enableProfiler = EnvironmentHelper.value(for: "OPENSWIFTUI_PROFILE_BENCHMARKS") != 0
private let enableProfiler = EnvironmentHelper.bool(for: "OPENSWIFTUI_PROFILE_BENCHMARKS")

public protocol _BenchmarkHost: AnyObject {
func _renderForTest(interval: Double)
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
@inline(__always)
static func instantiateIfNeeded() {
if !isInitialized {
let debugValue = UInt32(bitPattern: EnvironmentHelper.value(for: "OPENSWIFTUI_VIEW_DEBUG"))
let debugValue = UInt32(bitPattern: EnvironmentHelper.int32(for: "OPENSWIFTUI_VIEW_DEBUG"))

Check warning on line 72 in Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUI/View/Debug/TODO/ViewDebug.swift#L72

Added line #L72 was not covered by tests
properties = Properties(rawValue: debugValue)
isInitialized = true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//
// EnvironmentHelper.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: Complete

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
Expand All @@ -8,15 +15,19 @@
#error("Unsupported Platform")
#endif

enum EnvironmentHelper {
package enum EnvironmentHelper {
@_transparent
@inline(__always)
static func value(for key: String) -> Int32 {
package static func int32(for key: String) -> Int32 {

Check warning on line 20 in Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift#L20

Added line #L20 was not covered by tests
key.withCString { string in
guard let env = getenv(string) else {
return 0
}
return atoi(env)
}
}
}

@_transparent
package static func bool(for key: String) -> Bool {
int32(for: key) != 0

Check warning on line 31 in Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift#L30-L31

Added lines #L30 - L31 were not covered by tests
}
}
Loading