Skip to content

Commit 18fcaf6

Browse files
committed
Replace ProcessEnv.vars with block w/o API breakage
This fixes some warnings without more intrusive breaking changes for SwiftPM clients, as previously attempted in #7364. Also fixed some formatting inconsistencies.
1 parent 99a65c0 commit 18fcaf6

File tree

14 files changed

+45
-29
lines changed

14 files changed

+45
-29
lines changed

Sources/Basics/Concurrency/ConcurrencyHelpers.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import func TSCBasic.tsc_await
2020

2121
public enum Concurrency {
2222
public static var maxOperations: Int {
23-
ProcessEnv.vars["SWIFTPM_MAX_CONCURRENT_OPERATIONS"].flatMap(Int.init) ?? ProcessInfo.processInfo
23+
ProcessEnv.block["SWIFTPM_MAX_CONCURRENT_OPERATIONS"].flatMap(Int.init) ?? ProcessInfo.processInfo
2424
.activeProcessorCount
2525
}
2626
}

Sources/Build/BuildPlan/BuildPlan.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ extension BuildParameters {
9595
get throws {
9696
// FIXME: We use this hack to let swiftpm's functional test use shared
9797
// cache so it doesn't become painfully slow.
98-
if let path = ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"] {
98+
if let path = ProcessEnv.block["SWIFTPM_TESTS_MODULECACHE"] {
9999
return try AbsolutePath(validating: path)
100100
}
101101
return buildPath.appending("ModuleCache")
@@ -158,7 +158,7 @@ extension BuildParameters {
158158

159159
/// Returns the scoped view of build settings for a given target.
160160
func createScope(for target: ResolvedTarget) -> BuildSettings.Scope {
161-
return BuildSettings.Scope(target.underlying.buildSettings, environment: buildEnvironment)
161+
BuildSettings.Scope(target.underlying.buildSettings, environment: buildEnvironment)
162162
}
163163
}
164164

@@ -288,7 +288,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
288288
self.fileSystem = fileSystem
289289
self.observabilityScope = observabilityScope.makeChildScope(description: "Build Plan")
290290

291-
var productMap: [ResolvedProduct.ID: (product: ResolvedProduct, buildDescription: ProductBuildDescription)] = [:]
291+
var productMap = [ResolvedProduct.ID: (product: ResolvedProduct, buildDescription: ProductBuildDescription)]()
292292
// Create product description for each product we have in the package graph that is eligible.
293293
for product in graph.allProducts where product.shouldCreateProductDescription {
294294
let buildParameters: BuildParameters
@@ -446,7 +446,8 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
446446
for item in derivedTestTargets {
447447
var derivedTestTargets = [item.entryPointTargetBuildDescription.target]
448448

449-
targetMap[item.entryPointTargetBuildDescription.target.id] = .swift(item.entryPointTargetBuildDescription)
449+
targetMap[item.entryPointTargetBuildDescription.target.id] =
450+
.swift(item .entryPointTargetBuildDescription)
450451

451452
if let discoveryTargetBuildDescription = item.discoveryTargetBuildDescription {
452453
targetMap[discoveryTargetBuildDescription.target.id] = .swift(discoveryTargetBuildDescription)
@@ -552,9 +553,9 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
552553
}
553554

554555
// Add search paths from the system library targets.
555-
for target in graph.reachableTargets {
556+
for target in self.graph.reachableTargets {
556557
if let systemLib = target.underlying as? SystemLibraryTarget {
557-
arguments.append(contentsOf: try self.pkgConfig(for: systemLib).cFlags)
558+
try arguments.append(contentsOf: self.pkgConfig(for: systemLib).cFlags)
558559
// Add the path to the module map.
559560
arguments += ["-I", systemLib.moduleMapPath.parentDirectory.pathString]
560561
}
@@ -589,7 +590,7 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
589590
}
590591

591592
// Add search paths from the system library targets.
592-
for target in graph.reachableTargets {
593+
for target in self.graph.reachableTargets {
593594
if let systemLib = target.underlying as? SystemLibraryTarget {
594595
arguments += try self.pkgConfig(for: systemLib).cFlags
595596
}
@@ -645,7 +646,12 @@ public class BuildPlan: SPMBuildCore.BuildPlan {
645646
extension Basics.Diagnostic {
646647
static var swiftBackDeployError: Self {
647648
.warning(
648-
"Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an optional Swift library package that can be downloaded from \"More Downloads\" for Apple Developers at https://developer.apple.com/download/more/"
649+
"""
650+
Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by \
651+
default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an \
652+
optional Swift library package that can be downloaded from \"More Downloads\" for Apple Developers at \
653+
https://developer.apple.com/download/more/
654+
"""
649655
)
650656
}
651657

@@ -728,7 +734,7 @@ extension ResolvedProduct {
728734
}
729735

730736
private var isBinaryOnly: Bool {
731-
return self.targets.filter({ !($0.underlying is BinaryTarget) }).isEmpty
737+
self.targets.filter { !($0.underlying is BinaryTarget) }.isEmpty
732738
}
733739

734740
private var isPlugin: Bool {

Sources/Commands/PackageCommands/Format.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extension SwiftPackageCommand {
3737
func run(_ swiftCommandState: SwiftCommandState) async throws {
3838
// Look for swift-format binary.
3939
// FIXME: This should be moved to user toolchain.
40-
let swiftFormatInEnv = lookupExecutablePath(filename: ProcessEnv.vars["SWIFT_FORMAT"])
40+
let swiftFormatInEnv = lookupExecutablePath(filename: ProcessEnv.block["SWIFT_FORMAT"])
4141
guard let swiftFormat = swiftFormatInEnv ?? Process.findExecutable("swift-format").flatMap(AbsolutePath.init) else {
4242
swiftCommandState.observabilityScope.emit(error: "Could not find swift-format in PATH or SWIFT_FORMAT")
4343
throw TSCUtility.Diagnostics.fatalError

Sources/Commands/SwiftTestCommand.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,7 @@ final class ParallelTestRunner {
933933

934934
// command's result output goes on stdout
935935
// ie "swift test" should output to stdout
936-
if ProcessEnv.vars["SWIFTPM_TEST_RUNNER_PROGRESS_BAR"] == "lit" {
936+
if ProcessEnv.block["SWIFTPM_TEST_RUNNER_PROGRESS_BAR"] == "lit" {
937937
self.progressAnimation = ProgressAnimation.percent(
938938
stream: TSCBasic.stdoutStream,
939939
verbose: false,
@@ -1292,7 +1292,7 @@ extension TestCommandOptions {
12921292

12931293
/// Returns the test case specifier if overridden in the env.
12941294
private func skippedTestsOverride(fileSystem: FileSystem) -> TestCaseSpecifier? {
1295-
guard let override = ProcessEnv.vars["_SWIFTPM_SKIP_TESTS_LIST"] else {
1295+
guard let override = ProcessEnv.block["_SWIFTPM_SKIP_TESTS_LIST"] else {
12961296
return nil
12971297
}
12981298

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,9 @@ public final class ManifestLoader: ManifestLoaderProtocol {
857857

858858
// FIXME: Workaround for the module cache bug that's been haunting Swift CI
859859
// <rdar://problem/48443680>
860-
let moduleCachePath = try (ProcessEnv.vars["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"]).flatMap{ try AbsolutePath(validating: $0) }
860+
let moduleCachePath = try (
861+
ProcessEnv.block["SWIFTPM_MODULECACHE_OVERRIDE"] ??
862+
ProcessEnv.block["SWIFTPM_TESTS_MODULECACHE"]).flatMap { try AbsolutePath(validating: $0) }
861863

862864
var cmd: [String] = []
863865
cmd += [self.toolchain.swiftCompilerPathForManifests.pathString]
@@ -955,7 +957,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
955957
evaluationResult.compilerCommandLine = cmd
956958

957959
// Compile the manifest.
958-
TSCBasic.Process.popen(arguments: cmd, environment: self.toolchain.swiftCompilerEnvironment, queue: callbackQueue) { result in
960+
TSCBasic.Process.popen(
961+
arguments: cmd,
962+
environment: self.toolchain.swiftCompilerEnvironment,
963+
queue: callbackQueue
964+
) { result in
959965
dispatchPrecondition(condition: .onQueue(callbackQueue))
960966

961967
var cleanupIfError = DelayableAction(target: tmpDir, action: cleanupTmpDir)
@@ -1054,7 +1060,11 @@ public final class ManifestLoader: ManifestLoaderProtocol {
10541060
#endif
10551061

10561062
let cleanupAfterRunning = cleanupIfError.delay()
1057-
TSCBasic.Process.popen(arguments: cmd, environment: environment, queue: callbackQueue) { result in
1063+
TSCBasic.Process.popen(
1064+
arguments: cmd,
1065+
environment: environment,
1066+
queue: callbackQueue
1067+
) { result in
10581068
dispatchPrecondition(condition: .onQueue(callbackQueue))
10591069

10601070
defer { cleanupAfterRunning.perform() }

Sources/PackageLoading/PkgConfig.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public struct PkgConfig {
126126

127127
private static var envSearchPaths: [AbsolutePath] {
128128
get throws {
129-
if let configPath = ProcessEnv.vars["PKG_CONFIG_PATH"] {
129+
if let configPath = ProcessEnv.block["PKG_CONFIG_PATH"] {
130130
#if os(Windows)
131131
return try configPath.split(separator: ";").map({ try AbsolutePath(validating: String($0)) })
132132
#else
@@ -183,7 +183,7 @@ internal struct PkgConfigParser {
183183
variables["pcfiledir"] = pcFile.parentDirectory.pathString
184184

185185
// Add pc_sysrootdir variable. This is the path of the sysroot directory for pc files.
186-
variables["pc_sysrootdir"] = ProcessEnv.vars["PKG_CONFIG_SYSROOT_DIR"] ?? AbsolutePath.root.pathString
186+
variables["pc_sysrootdir"] = ProcessEnv.block["PKG_CONFIG_SYSROOT_DIR"] ?? AbsolutePath.root.pathString
187187

188188
let fileContents: String = try fileSystem.readFileContents(pcFile)
189189
for line in fileContents.components(separatedBy: "\n") {

Sources/PackageModel/SwiftSDKs/SwiftSDK.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,10 @@ public struct SwiftSDK: Equatable {
465465
) throws -> SwiftSDK {
466466
let originalWorkingDirectory = originalWorkingDirectory ?? localFileSystem.currentWorkingDirectory
467467
// Select the correct binDir.
468-
if ProcessEnv.vars["SWIFTPM_CUSTOM_BINDIR"] != nil {
468+
if ProcessEnv.block["SWIFTPM_CUSTOM_BINDIR"] != nil {
469469
print("SWIFTPM_CUSTOM_BINDIR was deprecated in favor of SWIFTPM_CUSTOM_BIN_DIR")
470470
}
471-
let customBinDir = (ProcessEnv.vars["SWIFTPM_CUSTOM_BIN_DIR"] ?? ProcessEnv.vars["SWIFTPM_CUSTOM_BINDIR"])
471+
let customBinDir = (ProcessEnv.block["SWIFTPM_CUSTOM_BIN_DIR"] ?? ProcessEnv.block["SWIFTPM_CUSTOM_BINDIR"])
472472
.flatMap { try? AbsolutePath(validating: $0) }
473473
let binDir = try customBinDir ?? binDir ?? SwiftSDK.hostBinDir(
474474
fileSystem: localFileSystem,
@@ -478,7 +478,7 @@ public struct SwiftSDK: Equatable {
478478
let sdkPath: AbsolutePath?
479479
#if os(macOS)
480480
// Get the SDK.
481-
if let value = ProcessEnv.vars["SDKROOT"] {
481+
if let value = ProcessEnv.block["SDKROOT"] {
482482
sdkPath = try AbsolutePath(validating: value)
483483
} else {
484484
// No value in env, so search for it.

Sources/SPMBuildCore/BuildSystem/BuildSystem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ package enum BuildSystemUtilities {
175175
/// Returns the build path from the environment, if present.
176176
public static func getEnvBuildPath(workingDir: AbsolutePath) throws -> AbsolutePath? {
177177
// Don't rely on build path from env for SwiftPM's own tests.
178-
guard ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"] == nil else { return nil }
179-
guard let env = ProcessEnv.vars["SWIFTPM_BUILD_DIR"] else { return nil }
178+
guard ProcessEnv.block["SWIFTPM_TESTS_MODULECACHE"] == nil else { return nil }
179+
guard let env = ProcessEnv.block["SWIFTPM_BUILD_DIR"] else { return nil }
180180
return try AbsolutePath(validating: env, relativeTo: workingDir)
181181
}
182182
}

Sources/SourceControl/RepositoryManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public class RepositoryManager: Cancellable {
331331
}
332332

333333
// We are expecting handle.repository.url to always be a resolved absolute path.
334-
let shouldCacheLocalPackages = ProcessEnv.vars["SWIFTPM_TESTS_PACKAGECACHE"] == "1" || cacheLocalPackages
334+
let shouldCacheLocalPackages = ProcessEnv.block["SWIFTPM_TESTS_PACKAGECACHE"] == "1" || cacheLocalPackages
335335

336336
if let cachePath, !(handle.repository.isLocal && !shouldCacheLocalPackages) {
337337
let cachedRepositoryPath = try cachePath.appending(handle.repository.storagePath())

Sources/Workspace/DefaultPluginScriptRunner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public struct DefaultPluginScriptRunner: PluginScriptRunner, Cancellable {
209209
#endif
210210

211211
// Honor any module cache override that's set in the environment.
212-
let moduleCachePath = ProcessEnv.vars["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.vars["SWIFTPM_TESTS_MODULECACHE"]
212+
let moduleCachePath = ProcessEnv.block["SWIFTPM_MODULECACHE_OVERRIDE"] ?? ProcessEnv.block["SWIFTPM_TESTS_MODULECACHE"]
213213
if let moduleCachePath {
214214
commandLine += ["-module-cache-path", moduleCachePath]
215215
}

Sources/Workspace/Workspace+Configuration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ extension Workspace {
8989
public var localMirrorsConfigurationFile: AbsolutePath {
9090
get throws {
9191
// backwards compatibility
92-
if let customPath = ProcessEnv.vars["SWIFTPM_MIRROR_CONFIG"] {
92+
if let customPath = ProcessEnv.block["SWIFTPM_MIRROR_CONFIG"] {
9393
return try AbsolutePath(validating: customPath)
9494
}
9595
return DefaultLocations.mirrorsConfigurationFile(at: self.localConfigurationDirectory)

Sources/XCBuildSupport/XcodeBuildSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ package final class XcodeBuildSystem: SPMBuildCore.BuildSystem {
9090
self.fileSystem = fileSystem
9191
self.observabilityScope = observabilityScope.makeChildScope(description: "Xcode Build System")
9292

93-
if let xcbuildTool = ProcessEnv.vars["XCBUILD_TOOL"] {
93+
if let xcbuildTool = ProcessEnv.block["XCBUILD_TOOL"] {
9494
xcbuildPath = try AbsolutePath(validating: xcbuildTool)
9595
} else {
9696
let xcodeSelectOutput = try TSCBasic.Process.popen(args: "xcode-select", "-p").utf8Output().spm_chomp()

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ final class APIDiffTests: CommandsTestCase {
4242
try skipIfApiDigesterUnsupported()
4343
// The following is added to separate out the integration point testing of the API
4444
// diff digester with SwiftPM from the functionality tests of the digester itself
45-
guard ProcessEnv.vars["SWIFTPM_TEST_API_DIFF_OUTPUT"] == "1" else {
45+
guard ProcessEnv.block["SWIFTPM_TEST_API_DIFF_OUTPUT"] == "1" else {
4646
throw XCTSkip("Env var SWIFTPM_TEST_API_DIFF_OUTPUT must be set to test the output")
4747
}
4848
}

Tests/PackageCollectionsTests/GitHubPackageMetadataProviderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ class GitHubPackageMetadataProviderTests: XCTestCase {
339339
httpClient.configuration.requestHeaders = .init()
340340
httpClient.configuration.requestHeaders!.add(name: "Cache-Control", value: "no-cache")
341341
var configuration = GitHubPackageMetadataProvider.Configuration(disableCache: true) // Disable cache so we hit the API
342-
if let token = ProcessEnv.vars["GITHUB_API_TOKEN"] {
342+
if let token = ProcessEnv.block["GITHUB_API_TOKEN"] {
343343
configuration.authTokens = { [.github("github.com"): token] }
344344
}
345345
configuration.apiLimitWarningThreshold = 50

0 commit comments

Comments
 (0)