Skip to content

Commit

Permalink
Basic: support case insensitivity for environment
Browse files Browse the repository at this point in the history
Windows is case insensitive for the environment control block, which we
did not honour. This causes issues when Swift is used with programs
which are incorrectly cased (e.g. emacs). Introduce an explicit wrapper
type for Windows to make the lookup case insensitive, canonicalising the
name to lowercase. This allows us to treat Path and PATH identically
(along with any other environment variable and case matching) which
respects the Windows behaviour. Additionally, migrate away from the
POSIX variants which do not handle the case properly to the Windows
version which does.

The introduced type `ProcessEnvironmentBlock` is just a typealias,
allowing access to the dictionary itself which is important to preserve
the behaviour for the clients.  The `CaseInsensitiveString` is a case
insensitive, case preserving string representation that allows us to
recreate the environment on Windows as the environment is case
insensitive, so it should not be possible to have conflicts when reading
the Process Environment Block from the Process Execution Block.

This is a partial resolution to environment variable handling as the
tools need subsequent changes to adopt the new API.

Fixes: #446

Co-authored-by: Max Desiatov <[email protected]>
  • Loading branch information
compnerd and Max Desiatov committed Dec 19, 2023
1 parent 9dd047d commit 0583d26
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 50 deletions.
2 changes: 1 addition & 1 deletion Sources/TSCBasic/FileSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private struct LocalFileSystem: FileSystem {

var tempDirectory: AbsolutePath {
get throws {
let override = ProcessEnv.vars["TMPDIR"] ?? ProcessEnv.vars["TEMP"] ?? ProcessEnv.vars["TMP"]
let override = ProcessEnv.block["TMPDIR"] ?? ProcessEnv.block["TEMP"] ?? ProcessEnv.block["TMP"]
if let path = override.flatMap({ try? AbsolutePath(validating: $0) }) {
return path
}
Expand Down
Loading

0 comments on commit 0583d26

Please sign in to comment.