Skip to content

Commit

Permalink
fix(x86): bake x86 node for Windows (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Oct 2, 2020
1 parent 385cd69 commit b4137f2
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
types: [published]
jobs:
deploy:
runs-on: ubuntu-latest
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: microsoft/playwright-github-action@v1
Expand Down
15 changes: 14 additions & 1 deletion build_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import re
import shutil
import subprocess
import sys

from playwright.path_utils import get_file_dirname

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

subprocess.check_call("npm i", cwd=driver_path, shell=True)
subprocess.check_call("npm run bake", cwd=driver_path, shell=True)

platform = sys.platform
if platform == "darwin":
subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True)
elif platform == "linux":
subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True)
elif platform == "win32":
# Windows is the only one that can build all drivers (x86 and x64),
# so we publish from it
subprocess.check_call("npm run bake-darwin", cwd=driver_path, shell=True)
subprocess.check_call("npm run bake-linux", cwd=driver_path, shell=True)
subprocess.check_call("npm run bake-win32", cwd=driver_path, shell=True)
subprocess.check_call("npm run bake-win32-amd64", cwd=driver_path, shell=True)

# for local development
drivers = (driver_path / "out").glob("**/*")
Expand Down
18 changes: 13 additions & 5 deletions build_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import os
import shutil
import subprocess
import sys
import zipfile

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

pack_wheel_drivers = [
("driver-linux", "manylinux1_x86_64.whl"),
("driver-macos", "macosx_10_13_x86_64.whl"),
("driver-win.exe", "win_amd64.whl"),
]
pack_wheel_drivers = []
if sys.platform == "linux":
pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl"))
if sys.platform == "darwin":
pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl"))
if sys.platform == "win32":
# Windows is the only one that can build all drivers (x86 and x64),
# so we publish from it
pack_wheel_drivers.append(("driver-linux", "manylinux1_x86_64.whl"))
pack_wheel_drivers.append(("driver-darwin", "macosx_10_13_x86_64.whl"))
pack_wheel_drivers.append(("driver-win32.exe", "win32.whl"))
pack_wheel_drivers.append(("driver-win32-amd64.exe", "win_amd64.whl"))

for driver, wheel in pack_wheel_drivers:
wheel_location = without_platform + wheel
Expand Down
5 changes: 4 additions & 1 deletion driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"description": "Playwright driver",
"bin": "main.js",
"scripts": {
"bake": "pkg --public --out-path=out ."
"bake-darwin": "pkg --public --targets node12-macos-x64 --output=out/driver-darwin .",
"bake-win32": "pkg --public --targets node12-win-x86 --output=out/driver-win32.exe .",
"bake-win32-amd64": "pkg --public --targets node12-win-x64 --output=out/driver-win32-amd64.exe .",
"bake-linux": "pkg --public --targets node12-linux-x64 --output=out/driver-linux ."
},
"keywords": [],
"author": {
Expand Down
30 changes: 19 additions & 11 deletions playwright/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@

import asyncio
import io
import os
import stat
import subprocess
import sys
from pathlib import Path
from typing import Any

from greenlet import greenlet
Expand All @@ -30,21 +33,23 @@
from playwright.sync_base import dispatcher_fiber, set_dispatcher_fiber


def compute_driver_name() -> str:
def compute_driver_executable() -> Path:
package_path = get_file_dirname()
platform = sys.platform
if platform == "darwin":
result = "driver-macos"
return package_path / "drivers" / "driver-darwin"
elif platform == "linux":
result = "driver-linux"
return package_path / "drivers" / "driver-linux"
elif platform == "win32":
result = "driver-win.exe"
return result
result = package_path / "drivers" / "driver-win32-amd64.exe"
if result.exists():
return result
return package_path / "drivers" / "driver-win32.exe"
return package_path / "drivers" / "driver-linux"


async def run_driver_async() -> Connection:
package_path = get_file_dirname()
driver_name = compute_driver_name()
driver_executable = package_path / "drivers" / driver_name
driver_executable = compute_driver_executable()

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

Expand Down

0 comments on commit b4137f2

Please sign in to comment.