Skip to content

Commit 3a59949

Browse files
committed
Bug 1908788 - Correctly locate geckodriver binary for mach wpt on Android, r=webdriver-reviewers,whimboo
The functional change here is searching the host binary directory as well as the dist directory. The code is also refactored a bit to split the firefox_android processing into its own function, like for desktop Firefox, and to share the geckodriver search code through a helper. Differential Revision: https://phabricator.services.mozilla.com/D217978
1 parent 8bf3ea8 commit 3a59949

File tree

2 files changed

+70
-62
lines changed

2 files changed

+70
-62
lines changed

testing/web-platform/mach_commands.py

+69-59
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,12 @@ def kwargs_common(self, kwargs):
3333

3434
tests_src_path = os.path.join(self._here, "tests")
3535

36-
if (
37-
kwargs["product"] in {"firefox", "firefox_android"}
38-
and kwargs["specialpowers_path"] is None
39-
):
40-
kwargs["specialpowers_path"] = os.path.join(
41-
self.distdir, "xpi-stage", "[email protected]"
42-
)
43-
44-
if kwargs["product"] == "firefox_android":
45-
# package_name may be different in the future
46-
package_name = kwargs["package_name"]
47-
if not package_name:
48-
kwargs[
49-
"package_name"
50-
] = package_name = "org.mozilla.geckoview.test_runner"
51-
52-
# Note that this import may fail in non-firefox-for-android trees
53-
from mozrunner.devices.android_device import (
54-
InstallIntent,
55-
get_adb_path,
56-
verify_android_device,
57-
)
58-
59-
kwargs["adb_binary"] = get_adb_path(self)
60-
install = (
61-
InstallIntent.NO if kwargs.pop("no_install") else InstallIntent.YES
62-
)
63-
verify_android_device(
64-
self, install=install, verbose=False, xre=True, app=package_name
65-
)
66-
67-
if kwargs["certutil_binary"] is None:
68-
kwargs["certutil_binary"] = os.path.join(
69-
os.environ.get("MOZ_HOST_BIN"), "certutil"
36+
if kwargs["product"] in {"firefox", "firefox_android"}:
37+
if kwargs["specialpowers_path"] is None:
38+
kwargs["specialpowers_path"] = os.path.join(
39+
self.distdir, "xpi-stage", "[email protected]"
7040
)
7141

72-
if kwargs["install_fonts"] is None:
73-
kwargs["install_fonts"] = True
74-
75-
if not kwargs["device_serial"]:
76-
kwargs["device_serial"] = ["emulator-5554"]
77-
7842
if kwargs["config"] is None:
7943
kwargs["config"] = os.path.join(
8044
self.topobjdir, "_tests", "web-platform", "wptrunner.local.ini"
@@ -118,27 +82,11 @@ def kwargs_firefox(self, kwargs):
11882
if kwargs["binary"] is None:
11983
kwargs["binary"] = self.get_binary_path()
12084

121-
if kwargs["certutil_binary"] is None:
122-
kwargs["certutil_binary"] = self.get_binary_path("certutil")
123-
12485
if kwargs["webdriver_binary"] is None:
125-
try_paths = [self.get_binary_path("geckodriver", validate_exists=False)]
126-
ext = ".exe" if sys.platform in ["win32", "msys", "cygwin"] else ""
127-
for build_type in ["release", "debug"]:
128-
try_paths.append(
129-
os.path.join(
130-
self.topsrcdir, "target", build_type, f"geckodriver{ext}"
131-
)
132-
)
133-
found_paths = []
134-
for path in try_paths:
135-
if os.path.exists(path):
136-
found_paths.append(path)
86+
kwargs["webdriver_binary"] = self.find_webdriver_binary()
13787

138-
if found_paths:
139-
# Pick the most recently modified version
140-
found_paths.sort(key=os.path.getmtime)
141-
kwargs["webdriver_binary"] = found_paths[-1]
88+
if kwargs["certutil_binary"] is None:
89+
kwargs["certutil_binary"] = self.get_binary_path("certutil")
14290

14391
if kwargs["install_fonts"] is None:
14492
kwargs["install_fonts"] = True
@@ -156,6 +104,47 @@ def kwargs_firefox(self, kwargs):
156104

157105
return kwargs
158106

107+
def kwargs_firefox_android(self, kwargs):
108+
from wptrunner import wptcommandline
109+
110+
kwargs = self.kwargs_common(kwargs)
111+
112+
# package_name may be different in the future
113+
package_name = kwargs["package_name"]
114+
if not package_name:
115+
kwargs["package_name"] = package_name = "org.mozilla.geckoview.test_runner"
116+
117+
# Note that this import may fail in non-firefox-for-android trees
118+
from mozrunner.devices.android_device import (
119+
InstallIntent,
120+
get_adb_path,
121+
verify_android_device,
122+
)
123+
124+
kwargs["adb_binary"] = get_adb_path(self)
125+
install = InstallIntent.NO if kwargs.pop("no_install") else InstallIntent.YES
126+
verify_android_device(
127+
self, install=install, verbose=False, xre=True, app=package_name
128+
)
129+
130+
if kwargs["webdriver_binary"] is None:
131+
kwargs["webdriver_binary"] = self.find_webdriver_binary()
132+
133+
if kwargs["certutil_binary"] is None:
134+
kwargs["certutil_binary"] = os.path.join(
135+
os.environ.get("MOZ_HOST_BIN"), "certutil"
136+
)
137+
138+
if kwargs["install_fonts"] is None:
139+
kwargs["install_fonts"] = True
140+
141+
if not kwargs["device_serial"]:
142+
kwargs["device_serial"] = ["emulator-5554"]
143+
144+
kwargs = wptcommandline.check_args(kwargs)
145+
146+
return kwargs
147+
159148
def kwargs_wptrun(self, kwargs):
160149
"""Setup kwargs for wpt-run which is only used for non-gecko browser products"""
161150
from tools.wpt import run, virtualenv
@@ -233,6 +222,27 @@ def setup_fonts_firefox(self):
233222
with open(ahem_src, "rb") as src, open(ahem_dest, "wb") as dest:
234223
dest.write(src.read())
235224

225+
def find_webdriver_binary(self):
226+
ext = ".exe" if sys.platform in ["win32", "msys", "cygwin"] else ""
227+
try_paths = [
228+
self.get_binary_path("geckodriver", validate_exists=False),
229+
os.path.join(self.topobjdir, "dist", "host", "bin", f"geckodriver{ext}"),
230+
]
231+
232+
for build_type in ["release", "debug"]:
233+
try_paths.append(
234+
os.path.join(self.topsrcdir, "target", build_type, f"geckodriver{ext}")
235+
)
236+
found_paths = []
237+
for path in try_paths:
238+
if os.path.exists(path):
239+
found_paths.append(path)
240+
241+
if found_paths:
242+
# Pick the most recently modified version
243+
found_paths.sort(key=os.path.getmtime)
244+
return found_paths[-1]
245+
236246

237247
class WebPlatformTestsServeRunner(MozbuildObject):
238248
def run(self, **kwargs):

testing/web-platform/mach_commands_base.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ def run(self, logger, **kwargs):
5050
logger.info(e.help())
5151
return 1
5252
elif kwargs["product"] == "firefox_android":
53-
from wptrunner import wptcommandline
54-
55-
kwargs = wptcommandline.check_args(self.setup.kwargs_common(kwargs))
53+
kwargs = self.setup.kwargs_firefox_android(kwargs)
5654
else:
5755
kwargs = self.setup.kwargs_wptrun(kwargs)
5856

0 commit comments

Comments
 (0)