Skip to content

[Windows] keep the drive letter when computing a common parent directory - #10565

Open
charles-zablit wants to merge 1 commit into
swiftlang:mainfrom
charles-zablit:cz/windows/common-parent-drive-root
Open

charles-zablit wants to merge 1 commit into
swiftlang:mainfrom
charles-zablit:cz/windows/common-parent-drive-root

Conversation

@charles-zablit

Copy link
Copy Markdown
Contributor

Keep the drive letter when computing a common parent directory on Windows

Motivation:

getCommonParentDirectory splits paths into components and rebuilds the result by joining on "/". That cannot express a Windows root, so the common parent of C:\swift-syntax and C:\llbuild comes back as C: instead of C:\. This causes tests failures on Windows in the rebranch.

Modifications:

Walk up from the first path with parentDirectory until it is an ancestor of the rest, instead of decomposing and reassembling.

Result:

Drive roots survive, and distinct drives now terminate at a root rather than falling through to /. POSIX behaviour is unchanged.

@charles-zablit

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@charles-zablit
charles-zablit force-pushed the cz/windows/common-parent-drive-root branch from ecdddbf to 805fbc9 Compare September 21, 2026 14:16
@charles-zablit

Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@AnthonyLatsis

Copy link
Copy Markdown
Contributor

@swift-ci please test macOS

@owenv

owenv commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

@swift-ci test windows

@bkhouri

bkhouri commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

@swift-ci test self hosted windows

@charles-zablit

Copy link
Copy Markdown
Contributor Author

@swift-ci please test windows

(id: "drive_root_and_child", paths: [#"C:\"#, #"C:\swiftpm"#], expected: #"C:\"#),
(id: "drive_nested_common", paths: [#"C:\a\b\c"#, #"C:\a\b\d"#], expected: #"C:\a\b"#),
(id: "drive_single_path", paths: [#"C:\a\b"#], expected: #"C:\a\b"#),
(id: "different_drives", paths: [#"C:\a"#, #"D:\a"#], expected: #"C:\"#),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised by this one. I'm not sure what value returning one of the drives is. That doesn't sound like this would work in practice. I wonder if it makes more sense to return nil in this case. i.e., there is no common parent directory and client code has to deal with that possibility.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants