Files
camoufox/scripts/_mixin.py
T
icepaq 0ac611c4ad v150 with Windows Support - Python Package Being Merged Separately (#611)
* fix v150 patches

* screen related patch fixes

* fix juggler issues with 150

* Update grading.py

improved build tester scoring

* fix windows build for v150

- scripts/_mixin.py: switch moz_target from x86_64-pc-mingw32 (no longer
  supported in FF150) to x86_64-pc-windows-msvc
- additions/juggler/screencast/HeadlessWindowCapturer.h: typedef pid_t
  on XP_WIN; libwebrtc headers (video_capture.h, desktop_capturer.h)
  reference pid_t which is POSIX-only
- patches/anti-font-fingerprinting.patch: include mozilla/dom/Document.h
  in gfxTextRun.cpp; on Windows it is not transitively included so
  doc->GetInnerWindow() failed with "incomplete type 'Document'"

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* make service test use local binary

* updated ff fingerprint versions

* Update README.md

---------

Co-authored-by: Ubuntu <ubuntu@ip-172-31-15-96.us-east-2.compute.internal>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 15:34:05 -04:00

138 lines
3.6 KiB
Python

#!/usr/bin/env python3
"""
Common functions used across the Camoufox build system.
Not meant to be called directly.
"""
import contextlib
import fnmatch
import optparse
import os
import re
import sys
import time
start_time = time.time()
@contextlib.contextmanager
def temp_cd(path):
"""Temporarily change to a different working directory"""
_old_cwd = os.getcwd()
abs_path = os.path.abspath(path)
assert os.path.exists(abs_path), f'{abs_path} does not exist.'
os.chdir(abs_path)
try:
yield
finally:
os.chdir(_old_cwd)
def get_options():
"""Get options"""
parser = optparse.OptionParser()
parser.add_option('--mozconfig-only', dest='mozconfig_only', default=False, action="store_true")
parser.add_option(
'-P', '--no-settings-pane', dest='settings_pane', default=True, action="store_false"
)
return parser.parse_args()
def find_src_dir(root_dir='.', version=None, release=None):
"""Get the source directory"""
if version and release:
name = os.path.join(root_dir, f'camoufox-{version}-{release}')
assert os.path.exists(name), f'{name} does not exist.'
return name
folders = os.listdir(root_dir)
for folder in folders:
if os.path.isdir(folder) and folder.startswith('camoufox-'):
return os.path.join(root_dir, folder)
raise FileNotFoundError('No camoufox-* folder found')
def get_moz_target(target, arch):
"""Get moz_target from target and arch"""
if target == "linux":
return "aarch64-unknown-linux-gnu" if arch == "arm64" else f"{arch}-pc-linux-gnu"
if target == "windows":
return f"{arch}-pc-windows-msvc"
if target == "macos":
return "aarch64-apple-darwin" if arch == "arm64" else f"{arch}-apple-darwin"
raise ValueError(f"Unsupported target: {target}")
def list_files(root_dir, suffix):
"""List files in a directory"""
for root, _, files in os.walk(root_dir):
for file in fnmatch.filter(files, suffix):
full_path = os.path.join(root, file)
relative_path = os.path.relpath(full_path, root_dir)
yield os.path.join(root_dir, relative_path).replace('\\', '/')
def list_patches(root_dir='../patches', suffix='*.patch'):
"""List all patch files"""
return sorted(list_files(root_dir, suffix), key=os.path.basename)
def is_bootstrap_patch(name):
return bool(re.match(r'\d+\-.*', os.path.basename(name)))
def script_exit(statuscode):
"""Exit the script"""
if (time.time() - start_time) > 60:
# print elapsed time
elapsed = time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time))
print(f"\n\aElapsed time: {elapsed}")
sys.stdout.flush()
sys.exit(statuscode)
def run(cmd, exit_on_fail=True, do_print=True):
"""Run a command"""
if not cmd:
return
if do_print:
print(cmd)
sys.stdout.flush()
retval = os.system(cmd)
if retval != 0 and exit_on_fail:
print(f"fatal error: command '{cmd}' failed")
sys.stdout.flush()
script_exit(1)
return retval
def patch(patchfile, reverse=False, silent=False):
"""Run a patch file"""
if reverse:
cmd = f"patch -p1 -R -i {patchfile}"
else:
cmd = f"patch -p1 -i {patchfile}"
if silent:
cmd += ' > /dev/null'
else:
print(f"\n*** -> {cmd}")
sys.stdout.flush()
run(cmd)
__all__ = [
'get_moz_target',
'list_patches',
'patch',
'run',
'script_exit',
'temp_cd',
'get_options',
]
if __name__ == '__main__':
print('This is a module, not meant to be called directly.')
sys.exit(1)