Skip to content

Commit 156425a

Browse files
committed
Move environment into Basics
1 parent dfbbab9 commit 156425a

File tree

11 files changed

+20
-71
lines changed

11 files changed

+20
-71
lines changed

Package.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,9 @@ let package = Package(
184184

185185
.systemLibrary(name: "SPMSQLite3", pkgConfig: systemSQLitePkgConfig),
186186

187-
.target(
188-
name: "Environment",
189-
exclude: ["CMakeLists.txt"]),
190-
191187
.target(
192188
name: "Basics",
193189
dependencies: [
194-
"Environment",
195190
"SPMSQLite3",
196191
.product(name: "DequeModule", package: "swift-collections"),
197192
.product(name: "OrderedCollections", package: "swift-collections"),
@@ -627,10 +622,6 @@ let package = Package(
627622
]
628623
),
629624

630-
.testTarget(
631-
name: "EnvironmentTests",
632-
dependencies: ["Environment"]),
633-
634625
.testTarget(
635626
name: "BasicsTests",
636627
dependencies: ["Basics", "SPMTestSupport", "tsan_utils"],

Sources/Basics/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ add_library(Basics
2525
Concurrency/ThreadSafeKeyValueStore.swift
2626
Concurrency/TokenBucket.swift
2727
DispatchTimeInterval+Extensions.swift
28-
EnvironmentVariables.swift
28+
Environment/Environment.swift
29+
Environment/EnvironmentKey.swift
30+
Environment/EnvironmentShims.swift
2931
Errors.swift
3032
FileSystem/AbsolutePath.swift
3133
FileSystem/FileSystem+Extensions.swift
@@ -73,7 +75,6 @@ add_library(Basics
7375
Vendor/Triple.swift
7476
Vendor/Triple+Platforms.swift)
7577
target_link_libraries(Basics PUBLIC
76-
Environment
7778
SwiftCollections::DequeModule
7879
SwiftCollections::OrderedCollections
7980
SwiftSystem::SystemPackage

Sources/Environment/Environment.swift renamed to Sources/Basics/Environment/Environment.swift

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,16 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
internal import Foundation
14-
internal import Synchronization
15-
16-
#if canImport(Glibc)
17-
import Glibc
18-
#elseif canImport(Musl)
19-
import Musl
20-
#elseif os(Windows)
21-
import CRT
22-
import WinSDK
13+
import Foundation
14+
15+
#if USE_IMPL_ONLY_IMPORTS
16+
@_implementationOnly import TSCclibc
2317
#else
24-
import Darwin.C
18+
import TSCclibc
2519
#endif
2620

2721
// FIXME: Use Synchronization.Mutex when available
28-
struct Mutex<T>: @unchecked Sendable {
22+
class Mutex<T>: @unchecked Sendable {
2923
var lock: NSLock
3024
var value: T
3125

@@ -34,7 +28,7 @@ struct Mutex<T>: @unchecked Sendable {
3428
self.value = value
3529
}
3630

37-
mutating func withLock<U>(_ body: (inout T) -> U) -> U {
31+
func withLock<U>(_ body: (inout T) -> U) -> U {
3832
self.lock.lock()
3933
defer { self.lock.unlock() }
4034
return body(&self.value)
@@ -111,7 +105,7 @@ extension Environment {
111105

112106
// MARK: - Global Environment
113107
extension Environment {
114-
static var _cachedCurrent = Mutex<Self?>(value: nil)
108+
static let _cachedCurrent = Mutex<Self?>(value: nil)
115109

116110
/// Vends a copy of the current process's environment variables.
117111
///

Sources/Environment/EnvironmentKey.swift renamed to Sources/Basics/Environment/EnvironmentKey.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
internal import Foundation
14-
1513
/// A key used to access values in an ``Environment``.
1614
///
1715
/// This type respects the compiled platform's case sensitivity requirements.
1816
public struct EnvironmentKey {
1917
public var rawValue: String
2018

21-
public init(_ rawValue: String) {
19+
package init(_ rawValue: String) {
2220
self.rawValue = rawValue
2321
}
2422
}

Sources/Basics/EnvironmentVariables.swift renamed to Sources/Basics/Environment/EnvironmentShims.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@_exported import Environment
1413
import struct TSCBasic.ProcessEnvironmentBlock
1514

1615
import class TSCBasic.Process

Sources/Build/LLBuildCommands.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import SPMBuildCore
1717
import SPMLLBuild
1818

1919
import class TSCBasic.LocalFileOutputByteStream
20-
import enum TSCBasic.ProcessEnv
2120

2221
import class TSCUtility.IndexStore
2322

Sources/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ add_subdirectory(Commands)
1515
add_subdirectory(CompilerPluginSupport)
1616
add_subdirectory(CoreCommands)
1717
add_subdirectory(DriverSupport)
18-
add_subdirectory(Environment)
1918
add_subdirectory(LLBuildManifest)
2019
add_subdirectory(PackageDescription)
2120
add_subdirectory(PackageFingerprint)

Sources/Environment/CMakeLists.txt

Lines changed: 0 additions & 33 deletions
This file was deleted.

Tests/EnvironmentTests/EnvironmentKeyTests.swift renamed to Tests/BasicsTests/Environment/EnvironmentKeyTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@testable import Environment
13+
@testable import Basics
1414
import XCTest
1515

1616
final class EnvironmentKeyTests: XCTestCase {

Tests/EnvironmentTests/EnvironmentTests.swift renamed to Tests/BasicsTests/Environment/EnvironmentTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
@testable import Environment
13+
@testable import Basics
1414
import XCTest
1515

1616
final class EnvironmentTests: XCTestCase {

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
@_spi(ProcessEnvironmentBlockShim)
1314
import Basics
1415
@testable import SourceControl
1516
import SPMTestSupport
@@ -25,11 +26,11 @@ class GitRepositoryTests: XCTestCase {
2526

2627
override func setUp() {
2728
// needed for submodule tests
28-
Git.environment = ["GIT_ALLOW_PROTOCOL": "file"]
29+
Git.environmentBlock = ["GIT_ALLOW_PROTOCOL": "file"]
2930
}
3031

3132
override func tearDown() {
32-
Git.environment = ProcessInfo.processInfo.environment
33+
Git.environmentBlock = .init(Environment.current)
3334
}
3435

3536
/// Test the basic provider functions.
@@ -197,7 +198,7 @@ class GitRepositoryTests: XCTestCase {
197198

198199
try Process.checkNonZeroExit(
199200
args: Git.tool, "-C", repoPath.pathString, "submodule", "add", testRepoPath.pathString,
200-
environment: Git.environment
201+
environment: .init(Git.environmentBlock)
201202
)
202203
let repo = GitRepository(path: repoPath)
203204
try repo.stageEverything()
@@ -613,7 +614,7 @@ class GitRepositoryTests: XCTestCase {
613614
try foo.checkout(newBranch: "submodule")
614615
try Process.checkNonZeroExit(
615616
args: Git.tool, "-C", fooPath.pathString, "submodule", "add", barPath.pathString, "bar",
616-
environment: Git.environment
617+
environment: .init(Git.environmentBlock)
617618
)
618619

619620
try foo.stageEverything()
@@ -635,7 +636,7 @@ class GitRepositoryTests: XCTestCase {
635636
// Add a submodule too to check for recursive submodules.
636637
try Process.checkNonZeroExit(
637638
args: Git.tool, "-C", barPath.pathString, "submodule", "add", bazPath.pathString, "baz",
638-
environment: Git.environment
639+
environment: .init(Git.environmentBlock)
639640
)
640641

641642
try bar.stageEverything()

0 commit comments

Comments
 (0)