This commit is contained in:
2026-04-27 19:21:50 -07:00
parent 98856b3f54
commit a3d5fa846b
16 changed files with 513 additions and 337 deletions

View File

@ -52,6 +52,46 @@ class WorkingDir:
def __exit__(self, exc_type, exc_val, exc_tb):
os.chdir(self.prev_cwd)
def write_if_changed(filepath, content):
"""Write content to filepath only if it differs from existing file preserving mtime when unchanged"""
if os.path.isfile(filepath):
with open(filepath, 'r') as f:
if f.read() == content:
return False
with open(filepath, 'w') as f:
f.write(content)
return True
def find_browser():
"""Find a browser that supports file:// with --allow-file-access-from-files - Chrome/Chromium/Edge"""
osn = get_os()
if osn == 'win':
candidates = []
for p in (os.environ.get('PROGRAMFILES', ''), os.environ.get('PROGRAMFILES(X86)', ''), os.environ.get('LOCALAPPDATA', '')):
if p:
candidates.append(os.path.join(p, 'Google', 'Chrome', 'Application', 'chrome.exe'))
candidates.append(os.path.join(p, 'Google', 'Chrome', 'chrome.exe'))
candidates.append(os.path.join(p, 'Google', 'Chromium', 'chrome.exe'))
candidates.append(os.path.join(p, 'Chromium', 'Application', 'chrome.exe'))
for p in (os.environ.get('PROGRAMFILES(X86)', ''), os.environ.get('PROGRAMFILES', '')):
if p:
candidates.append(os.path.join(p, 'Microsoft', 'Edge', 'Application', 'msedge.exe'))
for c in candidates:
if os.path.isfile(c):
return c
elif osn == 'mac':
for app in ('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium',
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'):
if os.path.isfile(app):
return app
else:
for name in ('google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser', 'microsoft-edge'):
found = shutil.which(name)
if found:
return found
return None
def write_lnx(filepath, output):
if filepath.endswith('.lz4'):
with open(filepath, 'wb') as f:
@ -279,7 +319,7 @@ def get_khamake_threads() -> int:
addon_prefs = get_lnx_preferences()
if hasattr(addon_prefs, 'khamake_threads_use_auto') and addon_prefs.khamake_threads_use_auto:
return -1
return 1 if not hasattr(addon_prefs, 'khamake_threads') else addon_prefs.khamake_threads
return -1 if not hasattr(addon_prefs, 'khamake_threads') else addon_prefs.khamake_threads
def get_compilation_server():
addon_prefs = get_lnx_preferences()