-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Normalize C++ action config tool paths based on exec platform OS #22218
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,14 +86,23 @@ public interface OsPathPolicy { | |
|
||
boolean isCaseSensitive(); | ||
|
||
// We *should* use a case-insensitive policy for OS.DARWIN, but we currently don't handle this. | ||
OsPathPolicy HOST_POLICY = | ||
OS.getCurrent() == OS.WINDOWS ? WindowsOsPathPolicy.INSTANCE : UnixOsPathPolicy.INSTANCE; | ||
OsPathPolicy HOST_POLICY = getFilePathOs(OS.getCurrent()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: For this reason, a comment would also be welcome. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding (per https://bazel.build/extending/platforms) is that we've retroactively redefined "host" to mean "the platform Bazel runs on" and introduced "exec" to mean "the platform where an action executes". The only reason it's ambiguous is that we haven't followed through in replacing "host" with "exec" everywhere it matters (notably, A comment would be welcome, yes, but IMO we should stick to "host" or "exec" instead of introducing yet another term. |
||
|
||
static OsPathPolicy getFilePathOs() { | ||
return HOST_POLICY; | ||
} | ||
|
||
static OsPathPolicy getFilePathOs(OS os) { | ||
if (os != OS.WINDOWS) { | ||
// We *should* use a case-insensitive policy for OS.DARWIN, but we currently don't handle | ||
// this. | ||
return UnixOsPathPolicy.INSTANCE; | ||
} | ||
return os == OS.getCurrent() | ||
? WindowsOsPathPolicy.INSTANCE | ||
: WindowsOsPathPolicy.CROSS_PLATFORM_INSTANCE; | ||
} | ||
|
||
/** Utilities for implementations of {@link OsPathPolicy}. */ | ||
class Utils { | ||
/** | ||
|
@@ -135,4 +144,15 @@ static int removeRelativePaths(String[] segments, int starti, boolean isAbsolute | |
return segmentCount; | ||
} | ||
} | ||
|
||
/** | ||
* Unchecked exception thrown by {@link OsPathPolicy} implementations when a path cannot be | ||
* normalized on the current host OS. | ||
*/ | ||
final class UncheckedPathUnsupportedOnThisOsException | ||
extends UnsupportedOperationException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this need to be an unchecked exception? It looks like it's only thrown from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this is also reachable via But as |
||
UncheckedPathUnsupportedOnThisOsException(String message) { | ||
super(message); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do understand correctly that this will raise an error where there was none, but that's OK because if Bazel encountered
C:\WINDOWS32\SYSTEM\
style path on Linux, the situation would be unsalvageable anyway?Actually: what about the case where Bazel runs on Linux, there is a toolchain definition for Windows somewhere but it's not used? Then it looks like Bazel would raise an error where there were none. I'm not sure if this scenario happens a lot because it would require someone to depend on the toolchain, which they don't if it's just a toolchain that's never selected.