Script to install deps (Windows only for now) (#7331)

* Script to install deps (Windows only for now)

* Set runner temp dir for choco

* Add missing os import

* Modify for CI

* Update CL

* Improve logging

* Update workflow to install deps via script

* Explain 3.1.1 version lock
This commit is contained in:
Nick Bolton 2024-01-19 14:44:50 +00:00 committed by GitHub
parent 4211fce112
commit ef31d3e21b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 108 additions and 15 deletions

View file

@ -59,8 +59,8 @@ jobs:
$client.DownloadFile("https://binaries.symless.com/bonjour/BonjourSDK.zip",".\bonjoursdk.zip")
[System.IO.Compression.ZipFile]::ExtractToDirectory(".\bonjoursdk.zip", "$env:BONJOUR_BASE_DIR")
- name: Install OpenSSL
run: choco install openssl -y --no-progress
- name: Install dependencies
run: python ./scripts/install_deps.py --skip cmake ninja
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.0.2

View file

@ -28,6 +28,7 @@ Tasks:
- #7327 Only use Ninja to build on Windows
- #7328 Reset error state before calling Process32Next
- #1177 Split CMake presets into debug and release
- #7331 Script to install deps (Windows only for now)
# 1.14.6

87
scripts/install_deps.py Normal file
View file

@ -0,0 +1,87 @@
import os
from lib import windows
import subprocess
import sys
import argparse
def main():
"""Entry point for the script."""
parser = argparse.ArgumentParser()
parser.add_argument('--pause-on-exit', action='store_true')
parser.add_argument('--skip', nargs='*', default=[])
args = parser.parse_args()
try:
deps = Deps(args.skip)
deps.install()
except Exception as e:
print(f'Error: {e}')
if (args.pause_on_exit):
input('Press enter to continue...')
class Deps:
def __init__(self, skip):
self.skip = skip
def install(self):
"""Installs dependencies."""
if (sys.platform == 'win32'):
self.windows()
else:
print(f'Unsupported platform: {sys.platform}')
def windows(self):
"""Installs dependencies on Windows."""
if not windows.is_admin():
windows.relaunch_as_admin(__file__)
sys.exit()
ci_env = os.environ.get('CI')
if ci_env:
print('CI environment detected')
self.choco_ci()
# already installed on github runners.
self.skip.extend(['cmake', 'ninja'])
self.choco("cmake")
self.choco("ninja")
# lock openssl to 3.1.1. as of 19th jan 2024, 3.2.0 breaks cmake configure.
self.choco("openssl", "3.1.1")
def choco(self, package, version=None):
"""Installs a package using Chocolatey."""
if (package in self.skip):
print(f'Skipping: {package}')
return
args = ['choco', 'install', package]
if (version):
args.extend(['--version', version])
args.extend(['-y', '--no-progress'])
subprocess.run(args, shell=True, check=True)
def choco_ci(self):
"""Configures Chocolatey cache for CI."""
runner_temp_key = 'RUNNER_TEMP'
runner_temp = os.environ.get(runner_temp_key)
if runner_temp:
# sets the choco cache dir, which should match the dir in the ci cache action.
key_arg = '--name="cacheLocation"'
value_arg = f'--value="{runner_temp}/choco"'
subprocess.run(['choco', 'config', 'set', key_arg, value_arg], shell=True, check=True)
else:
print(f'Warning: CI environment variable {runner_temp_key} not set')
main()

15
scripts/lib/windows.py Normal file
View file

@ -0,0 +1,15 @@
import ctypes
import sys
def relaunch_as_admin(script):
args = ' '.join(sys.argv[1:])
command = f'{script} --pause-on-exit {args}'
print(f'Re-launching script as admin: {command}')
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, command, None, 1)
def is_admin():
"""Returns True if the current process has admin privileges."""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except ctypes.WinError:
return False

View file

@ -1,9 +1,9 @@
import os
import subprocess
import ctypes
import sys
import argparse
import glob
from lib import windows
BIN_NAME = 'synergyd'
SOURCE_BIN_DIR = os.path.join('build', 'bin')
@ -21,11 +21,8 @@ def main():
parser.add_argument('--target-bin-name', default=BIN_NAME)
args = parser.parse_args()
if not is_admin():
print('Re-launching script as admin')
args = ' '.join(sys.argv[1:])
command = f'{__file__} --pause-on-exit {args}'
ctypes.windll.shell32.ShellExecuteW(None, 'runas', sys.executable, command, None, 1)
if not windows.is_admin():
windows.relaunch_as_admin(__file__)
sys.exit()
try:
@ -83,11 +80,4 @@ def copy_bin_files(source_bin_dir, target_bin_dir, source_bin_name, target_bin_n
except subprocess.CalledProcessError as e:
print(f'Copy failed: {e}')
def is_admin():
"""Returns True if the current process has admin privileges."""
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except ctypes.WinError:
return False
main()