Skip to content

Commit b4137f2

Browse files
authored
fix(x86): bake x86 node for Windows (#209)
1 parent 385cd69 commit b4137f2

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

Diff for: .github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
types: [published]
55
jobs:
66
deploy:
7-
runs-on: ubuntu-latest
7+
runs-on: windows-latest
88
steps:
99
- uses: actions/checkout@v2
1010
- uses: microsoft/playwright-github-action@v1

Diff for: build_driver.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import re
1717
import shutil
1818
import subprocess
19+
import sys
1920

2021
from playwright.path_utils import get_file_dirname
2122

@@ -33,7 +34,19 @@
3334
shutil.rmtree(driver_path / "out")
3435

3536
subprocess.check_call("npm i", cwd=driver_path, shell=True)
36-
subprocess.check_call("npm run bake", cwd=driver_path, shell=True)
37+
38+
platform = sys.platform
39+
if platform == "darwin":
40+
subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True)
41+
elif platform == "linux":
42+
subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True)
43+
elif platform == "win32":
44+
# Windows is the only one that can build all drivers (x86 and x64),
45+
# so we publish from it
46+
subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True)
47+
subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True)
48+
subprocess.check_call("npm run bake-win32", cwd=driver_path, shell=True)
49+
subprocess.check_call("npm run bake-win32-amd64", cwd=driver_path, shell=True)
3750

3851
# for local development
3952
drivers = (driver_path / "out").glob("**/*")

Diff for: build_package.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import shutil
1818
import subprocess
19+
import sys
1920
import zipfile
2021

2122
from playwright.path_utils import get_file_dirname
@@ -36,11 +37,18 @@
3637
base_wheel_location = glob.glob("dist/*.whl")[0]
3738
without_platform = base_wheel_location[:-7]
3839

39-
pack_wheel_drivers = [
40-
("driver-linux", "manylinux1_x86_64.whl"),
41-
("driver-macos", "macosx_10_13_x86_64.whl"),
42-
("driver-win.exe", "win_amd64.whl"),
43-
]
40+
pack_wheel_drivers = []
41+
if sys.platform == "linux":
42+
pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl"))
43+
if sys.platform == "darwin":
44+
pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl"))
45+
if sys.platform == "win32":
46+
# Windows is the only one that can build all drivers (x86 and x64),
47+
# so we publish from it
48+
pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl"))
49+
pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl"))
50+
pack_wheel_drivers.append(("driver-win32.exe", "win32.whl"))
51+
pack_wheel_drivers.append(("driver-win32-amd64.exe", "win_amd64.whl"))
4452

4553
for driver, wheel in pack_wheel_drivers:
4654
wheel_location = without_platform + wheel

Diff for: driver/package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
"description": "Playwright driver",
66
"bin": "main.js",
77
"scripts": {
8-
"bake": "pkg --public --out-path=out ."
8+
"bake-darwin": "pkg --public --targets node12-macos-x64 --output=out/driver-darwin .",
9+
"bake-win32": "pkg --public --targets node12-win-x86 --output=out/driver-win32.exe .",
10+
"bake-win32-amd64": "pkg --public --targets node12-win-x64 --output=out/driver-win32-amd64.exe .",
11+
"bake-linux": "pkg --public --targets node12-linux-x64 --output=out/driver-linux ."
912
},
1013
"keywords": [],
1114
"author": {

Diff for: playwright/main.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414

1515
import asyncio
1616
import io
17+
import os
18+
import stat
1719
import subprocess
1820
import sys
21+
from pathlib import Path
1922
from typing import Any
2023

2124
from greenlet import greenlet
@@ -30,21 +33,23 @@
3033
from playwright.sync_base import dispatcher_fiber, set_dispatcher_fiber
3134

3235

33-
def compute_driver_name() -> str:
36+
def compute_driver_executable() -> Path:
37+
package_path = get_file_dirname()
3438
platform = sys.platform
3539
if platform == "darwin":
36-
result = "driver-macos"
40+
return package_path / "drivers" / "driver-darwin"
3741
elif platform == "linux":
38-
result = "driver-linux"
42+
return package_path / "drivers" / "driver-linux"
3943
elif platform == "win32":
40-
result = "driver-win.exe"
41-
return result
44+
result = package_path / "drivers" / "driver-win32-amd64.exe"
45+
if result.exists():
46+
return result
47+
return package_path / "drivers" / "driver-win32.exe"
48+
return package_path / "drivers" / "driver-linux"
4249

4350

4451
async def run_driver_async() -> Connection:
45-
package_path = get_file_dirname()
46-
driver_name = compute_driver_name()
47-
driver_executable = package_path / "drivers" / driver_name
52+
driver_executable = compute_driver_executable()
4853

4954
# Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
5055
def _get_stderr_fileno() -> int:
@@ -134,9 +139,12 @@ def main() -> None:
134139
if "install" not in sys.argv:
135140
print('Run "python -m playwright install" to complete installation')
136141
return
137-
package_path = get_file_dirname()
138-
driver_name = compute_driver_name()
139-
driver_executable = package_path / "drivers" / driver_name
142+
driver_executable = compute_driver_executable()
143+
# Fix the executable bit during the installation.
144+
if not sys.platform == "win32":
145+
st = os.stat(driver_executable)
146+
if st.st_mode & stat.S_IEXEC == 0:
147+
os.chmod(driver_executable, st.st_mode | stat.S_IEXEC)
140148
print("Installing the browsers...")
141149
subprocess.check_call(f"{driver_executable} install", shell=True)
142150

0 commit comments

Comments
 (0)