Skip to content

Commit c443bc3

Browse files
committed
Strip shell session env vars from BuildDescription signature.
OLDPWD and TERM_SESSION_ID change across terminal/shell sessions but don't affect build output. Including them in the signature can invalidate the on-disk BuildDescription cache for cosmetic differences, producing redundant bundle directories per terminal session.
1 parent b2433e7 commit c443bc3

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

Sources/SWBTaskExecution/BuildDescriptionSignature.swift

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ package struct BuildDescriptionSignatureComponents: Codable, Hashable, Sendable
5757
let targets: [TargetMetadata]
5858
let projects: [ProjectMetadata]
5959
let systemInfo: SystemInfo?
60-
let userInfo: UserInfo?
60+
var userInfo: UserInfo?
6161
let developerPath: Path
6262
let xcodeVersionString: String
6363
let xcodeProductBuildVersionString: String
@@ -106,10 +106,31 @@ package struct BuildDescriptionSignatureComponents: Codable, Hashable, Sendable
106106
}
107107
}
108108

109+
extension BuildDescriptionSignatureComponents {
110+
/// Env vars stripped from `UserInfo` before hashing into the signature.
111+
/// These change across terminal/shell sessions but don't affect build output
112+
/// and including them can invalidate the on-disk cache for cosmetic differences.
113+
fileprivate static let environmentDenylist: Set<String> = [
114+
"OLDPWD",
115+
"TERM_SESSION_ID",
116+
]
117+
118+
fileprivate static func filteredEnvironmentForSignature(_ env: [String: String]) -> [String: String] {
119+
env.filter { !environmentDenylist.contains($0.key) }
120+
}
121+
}
122+
109123
extension BuildDescriptionSignatureComponents {
110124
var humanReadableString: ByteString {
111125
get throws {
112-
try ByteString(JSONEncoder(outputFormatting: [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]).encode(self))
126+
var components = self
127+
if let ui = components.userInfo {
128+
components.userInfo = UserInfo(
129+
user: ui.user, group: ui.group, uid: ui.uid, gid: ui.gid, home: ui.home,
130+
processEnvironment: Self.filteredEnvironmentForSignature(ui.processEnvironment),
131+
buildSystemEnvironment: Self.filteredEnvironmentForSignature(ui.buildSystemEnvironment))
132+
}
133+
return try ByteString(JSONEncoder(outputFormatting: [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]).encode(components))
113134
}
114135
}
115136

0 commit comments

Comments
 (0)