Skip to content

Commit 63e0372

Browse files
authored
Respect existing environment variables in build tool plugins (#6566)
1 parent 99ec492 commit 63e0372

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
`redundant_self` rule.
7373
[SimplyDanny](https://github.com/SimplyDanny)
7474
[#6553](https://github.com/realm/SwiftLint/issues/6553)
75+
76+
* Respect existing environment variables when setting `BUILD_WORKSPACE_DIRECTORY`
77+
in build tool plugins.
78+
[SimplyDanny](https://github.com/SimplyDanny)
79+
[#6080](https://github.com/realm/SwiftLint/issues/6080)
7580

7681
## 0.63.2: High-Speed Extraction
7782

Plugins/SwiftLintBuildToolPlugin/SwiftLintBuildToolPlugin.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct SwiftLintBuildToolPlugin: BuildToolPlugin {
3636
target: Target
3737
) throws -> [String: String] {
3838
let workingDirectory: Path = try target.directory.resolveWorkingDirectory(in: context.package.directory)
39-
return ["BUILD_WORKSPACE_DIRECTORY": "\(workingDirectory)"]
39+
return addedToEnvironment(["BUILD_WORKSPACE_DIRECTORY": "\(workingDirectory)"])
4040
}
4141

4242
private func makeCommand(
@@ -83,6 +83,10 @@ struct SwiftLintBuildToolPlugin: BuildToolPlugin {
8383
}
8484
}
8585

86+
private func addedToEnvironment(_ new: [String: String]) -> [String: String] {
87+
ProcessInfo.processInfo.environment.merging(new) { _, new in new }
88+
}
89+
8690
#if canImport(XcodeProjectPlugin)
8791

8892
import XcodeProjectPlugin
@@ -138,7 +142,7 @@ extension SwiftLintBuildToolPlugin: XcodeBuildToolPlugin {
138142
throw SwiftLintBuildToolPluginError.swiftFilesNotInWorkingDirectory(workingDirectory)
139143
}
140144

141-
return ["BUILD_WORKSPACE_DIRECTORY": "\(workingDirectory)"]
145+
return addedToEnvironment(["BUILD_WORKSPACE_DIRECTORY": "\(workingDirectory)"])
142146
}
143147
}
144148

0 commit comments

Comments
 (0)