Skip to content

Fix swiftc selection for the case no swiftc found in Swift SDK #7296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kateinoigakukun
Copy link
Member

Fix PATH executable selection in UserToolchain

Motivation:

When swiftc is not in the toolchain bin directory of Swift SDK, system swiftc in PATH should be used. But the current implementation of UserToolchain always picks the last found entry in the PATH instead of the first one. This behavior was introduced by 22c2493

The causes actual issues when:

  1. More than two swiftc are in PATH
  2. The invoked swift-build is placed from outside of toolchain bin directory

Then it uses the last found swiftc in PATH even though we expect the first one.

Modifications:

Fixed the order of PATH selection to prefer the first entry.

Result:

The first found swiftc is used as well as shell PATH selection.

When `swiftc` is not in the toolchain bin directory of Swift SDK,
system swiftc in PATH should be used. But the current implementation
of `UserToolchain` always picks the last found entry in the PATH
instead of the first one. This behavior was introduced by
22c2493
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@neonichu
Copy link
Contributor

Not really a comment for this PR, but it seems inconsistent that we're not using xcrun here when on macOS instead of PATH.

@kateinoigakukun
Copy link
Member Author

Yeah, findTool handles xcrun case but there are some direct calls of getTool. I'm not sure they are appropriate use.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Thanks!

@kateinoigakukun kateinoigakukun merged commit dc514d5 into swiftlang:main Jan 25, 2024
@kateinoigakukun kateinoigakukun deleted the yt/choose-first-found-swiftc branch January 25, 2024 09:49
MaxDesiatov added a commit that referenced this pull request Jun 6, 2024
Behavior of `--toolchain` regressed in
#7296 by
preferring the first match in toolset root paths: when `swiftc` is
available in the same directory next to the SwiftPM binary being
invoked, that became preferred with `--toolchain` value ignored.

This is now fixed by slightly tweaking where custom toolchain gets added
- it's prepended.

A newly added test verifies that the behavior is fixed. For that we had
to inject `FileSystem` and `EnvironmentVariables` in a lot more places,
with an added benefit of making our tests more consistent and isolated
from an arbitrary build environment.

Resolves: rdar://126095653

---------

Co-authored-by: Pavel Yaskevich <[email protected]>
MaxDesiatov added a commit that referenced this pull request Jun 12, 2024
Behavior of `--toolchain` regressed in
#7296 by
preferring the first match in toolset root paths: when `swiftc` is
available in the same directory next to the SwiftPM binary being
invoked, that became preferred with `--toolchain` value ignored.

This is now fixed by slightly tweaking where custom toolchain gets added
- it's prepended.

A newly added test verifies that the behavior is fixed. For that we had
to inject `FileSystem` and `EnvironmentVariables` in a lot more places,
with an added benefit of making our tests more consistent and isolated
from an arbitrary build environment.

Resolves: rdar://126095653

---------

Co-authored-by: Pavel Yaskevich <[email protected]>
(cherry picked from commit ee9d0b2)

# Conflicts:
#	Sources/PackageModel/UserToolchain.swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants