-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
5 changed files
with
108 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters