Skip to content

Commit

Permalink
Update EnvironmentHelper API
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Sep 24, 2024
1 parent 04dede6 commit 162dbba
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
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 @@ final class AppGraph: GraphHost {
}

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 @@ extension _ViewDebug {
@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 @@ import WASILibc
#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
}
}

0 comments on commit 162dbba

Please sign in to comment.