Skip to content

Commit 22835e2

Browse files
nateboschjakemac53
andauthored
Add support for multiple full paths on macos (#2276)
We cannot look up multiple basename commands in the system path and the current `macOsExecutable` configuration may have existing uses in `dart_test.yaml` files so it isn't safe to require full paths. Add a separate `macOsAbsolutePaths` configuration to enable internal definitions that check multiple full paths and execute the first one that exists. Add the basename `firefox` as a fallback. Adding that command to the path is one workaround for users with firefox installed in an unexpected location. This is also the only approach that is compatible with mac on GitHub actions using the `setup-firefox` action. There is no support here for `dart_test.yaml`. Users that are configuring an executable for macOS will continue to have support for only a single value, even if they are specifying an absolute path. Tests remain skipped because our mono repo setup does not have a way to include the `setup-firefox` action. --------- Co-authored-by: Jacob MacDonald <[email protected]>
1 parent 9a2d155 commit 22835e2

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

pkgs/test/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Fix dart2wasm tests on windows.
44
* Increase SDK constraint to ^3.5.0-311.0.dev.
55
* Support running Node.js tests compiled with dart2wasm.
6+
* Allow `firefox` or `firefox-bin` executable name on macOS.
67

78
## 1.25.8
89

pkgs/test/lib/src/runner/browser/default_settings.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ final defaultSettings = UnmodifiableMapView({
2424
),
2525
Runtime.firefox: ExecutableSettings(
2626
linuxExecutable: 'firefox',
27-
macOSExecutable: '/Applications/Firefox.app/Contents/MacOS/firefox-bin',
27+
macOSExecutables: [
28+
'/Applications/Firefox.app/Contents/MacOS/firefox-bin',
29+
'/Applications/Firefox.app/Contents/MacOS/firefox',
30+
'firefox',
31+
],
2832
windowsExecutable: r'Mozilla Firefox\firefox.exe',
2933
environmentOverride: 'FIREFOX_EXECUTABLE'),
3034
Runtime.safari: ExecutableSettings(

pkgs/test/lib/src/runner/executable_settings.dart

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ class ExecutableSettings {
2020
/// looked up on the system path. It may not be relative.
2121
final String? _linuxExecutable;
2222

23-
/// The path to the executable on Mac OS.
23+
/// Potential commands to execute on Mac OS to launch this executable.
2424
///
25-
/// This may be an absolute path or a basename, in which case it will be
26-
/// looked up on the system path. It may not be relative.
27-
final String? _macOSExecutable;
25+
/// The values may be an absolute path, or a basename.
26+
/// The chosen command will be the first value from this list which either is
27+
/// a full path that exists, or is a basename. When a basename is included it
28+
/// should always be at the end of the list because it will always terminate
29+
/// the search through the list. Relative paths are not allowed.
30+
final List<String>? _macOSExectuables;
2831

2932
/// The path to the executable on Windows.
3033
///
@@ -45,7 +48,22 @@ class ExecutableSettings {
4548
if (envVariable != null) return envVariable;
4649
}
4750

48-
if (Platform.isMacOS) return _macOSExecutable!;
51+
if (Platform.isMacOS) {
52+
if (_macOSExectuables != null) {
53+
for (final path in _macOSExectuables) {
54+
if (p.basename(path) == path) return path;
55+
if (p.isAbsolute(path)) {
56+
if (File(path).existsSync()) return path;
57+
} else {
58+
throw ArgumentError(
59+
'Mac OS executable must be a basename or an absolute path.'
60+
' Got relative path: $path');
61+
}
62+
}
63+
}
64+
throw ArgumentError('Could not find a command basename or an existing '
65+
'path in $_macOSExectuables');
66+
}
4967
if (!Platform.isWindows) return _linuxExecutable!;
5068
final windowsExecutable = _windowsExecutable!;
5169
if (p.isAbsolute(windowsExecutable)) return windowsExecutable;
@@ -177,12 +195,14 @@ class ExecutableSettings {
177195
{Iterable<String>? arguments,
178196
String? linuxExecutable,
179197
String? macOSExecutable,
198+
List<String>? macOSExecutables,
180199
String? windowsExecutable,
181200
String? environmentOverride,
182201
bool? headless})
183202
: arguments = arguments == null ? const [] : List.unmodifiable(arguments),
184203
_linuxExecutable = linuxExecutable,
185-
_macOSExecutable = macOSExecutable,
204+
_macOSExectuables =
205+
_normalizeMacExecutable(macOSExecutable, macOSExecutables),
186206
_windowsExecutable = windowsExecutable,
187207
_environmentOverride = environmentOverride,
188208
_headless = headless;
@@ -192,6 +212,13 @@ class ExecutableSettings {
192212
arguments: arguments.toList()..addAll(other.arguments),
193213
headless: other._headless ?? _headless,
194214
linuxExecutable: other._linuxExecutable ?? _linuxExecutable,
195-
macOSExecutable: other._macOSExecutable ?? _macOSExecutable,
215+
macOSExecutables: other._macOSExectuables ?? _macOSExectuables,
196216
windowsExecutable: other._windowsExecutable ?? _windowsExecutable);
197217
}
218+
219+
List<String>? _normalizeMacExecutable(
220+
String? singleArgument, List<String>? listArgument) {
221+
if (listArgument != null) return listArgument;
222+
if (singleArgument != null) return [singleArgument];
223+
return null;
224+
}

0 commit comments

Comments
 (0)