diff --git a/build/gn_run_binary.py b/build/gn_run_binary.py index 10ace2b8a62dfa..7a085ec7e4f9e0 100644 --- a/build/gn_run_binary.py +++ b/build/gn_run_binary.py @@ -51,8 +51,25 @@ import subprocess import sys +import os + +# add windows check + +if(sys.platform.startswith('win')): + file_name = os.path.splitext(sys.argv[1]) + args = '' + for x in file_name: + if x == '.py': + args = ['python.exe'] + sys.argv[1:] + break + + if bool(args) == False: + + args = sys.argv[1:] + +else: + args = sys.argv[1:] -args = sys.argv[1:] ret = subprocess.call(args) if ret != 0: diff --git a/scripts/WIN_README.md b/scripts/WIN_README.md new file mode 100644 index 00000000000000..462cd6ca6e771f --- /dev/null +++ b/scripts/WIN_README.md @@ -0,0 +1,35 @@ +# Windows Support + +short guide on using example build scripts on windows. + +## Requirements + +1. PowerShell (Version 5.0 and up preferred) +2. git + +## Usage + +run setup script. + +```PowerShell +./scripts/windows_setup.ps1 --setup +``` + +when running an example build script, the arguments and their order is +important. + +```PowerShell +./scripts/examples/gn_efr32_example.sh [] +``` + +for example: + +```PowerShell +./scripts/examples/gn_efr32_example.ps1 /examples/lighting-app/efr32/ /out/lighting-app BRD4161A +``` + +To cleanup environment: + +```PowerShell +./scrips/windows_setup.ps1 --cleanup +``` diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 new file mode 100644 index 00000000000000..9d3ce8b33b030d --- /dev/null +++ b/scripts/bootstrap.ps1 @@ -0,0 +1,365 @@ +$_PW_BANNER = " + + ▒█████▄ █▓ ▄███▒ ▒█ ▒█ ░▓████▒ ░▓████▒ ▒▓████▄ + ▒█░ █░ ░█▒ ██▒ ▀█▒ ▒█░ █ ▒█ ▒█ ▀ ▒█ ▀ ▒█ ▀█▌ + ▒█▄▄▄█░ ░█▒ █▓░ ▄▄░ ▒█░ █ ▒█ ▒███ ▒███ ░█ █▌ + ▒█▀ ░█░ ▓█ █▓ ░█░ █ ▒█ ▒█ ▄ ▒█ ▄ ░█ ▄█▌ + ▒█ ░█░ ░▓███▀ ▒█▓▀▓█░ ░▓████▒ ░▓████▒ ▒▓████▀ +" +########################################################################################### +# function: Invoke-CmdScript # +# Purpose: when a batch file is invoked within a powershell script, it is started in a # +# child process in cmd, any change to eniroment variables don't take effect # +# this function, parses the script and executes the commands in the scope of # +# this script # +########################################################################################### + +function Invoke-CmdScript { + param( + [String] $scriptName + ) + $cmdLine = """$scriptName"" $args & set" + & $Env:SystemRoot\system32\cmd.exe /c $cmdLine | + Select-String '^([^=]*)=(.*)$' | + ForEach-Object { + $varName = $_.Matches[0].Groups[1].Value + $varValue = $_.Matches[0].Groups[2].Value + Set-Item Env:$varName $varValue + } +} +########################################################################################### +# function: check_for_git # +# Purpose: checks for git and exits script if none exists # +########################################################################################### +function check_for_git() { + + + try { + git --version > $null + } + catch { + { "Error: Git was not found. please make sure there is a valid git installation present' + and added to the PATH"} + exit + } + + +} +########################################################################################### +# function: pw_(color) # +# Purpose: prints input in the color specified by the name of the function # +########################################################################################### +function pw_red($inputText) { + Write-Host "$inputText" -ForegroundColor Red +} + +function pw_yellow($inputText) { + Write-Host "$inputText" -ForegroundColor Yellow +} + +function pw_cyan($inputText) { + Write-Host "$inputText" -ForegroundColor Cyan +} + +function pw_magenta($inputText) { + Write-Host "$inputText" -ForegroundColor Magenta +} + +function pw_white($inputText) { + Write-Host "$inputText" -ForegroundColor White -BackgroundColor Black +} + +function pw_green($inputText) { + Write-Host "$inputText" -ForegroundColor Green +} + +function pw_activate() { + _pw_hello " ACTIVATOR! This sets your shell environment variables.\n" + $Global:_PW_ENV_SETUP_STATUS = 0 +} +########################################################################################### +# function: pw_finalize # +# Purpose: activates the pigweed environment # +########################################################################################### +function pw_finalize($arg1, $arg2) { + + $_PW_NAME = "$arg1" + $_PW_SETUP_SH = "$arg2" + + if ("$Global:_PW_ENV_SETUP_STATUS" -ne 0 ) { + return + } + + if (Test-Path -Path $_PW_SETUP_SH -PathType Leaf) { + + . $_PW_SETUP_SH + Invoke-CmdScript $_PW_SETUP_SH + + if ($?) { + if ($_PW_NAME -eq "bootstrap" -and $env:PW_ENVSETUP_QUIET.length -eq 0) { + Write-Output "To reactivate this environment in the future, run this in your " + Write-Output "terminal:" + Write-Output + pw_green " source ./activate.sh" + Write-Output + Write-Output "To deactivate this environment, run this:" + Write-Output + Write-Output " deactivate" + Write-Output + } + } + else { + pw_red "Error during $_PW_NAME--see messages above." + } + } + else { + pw_red "Error during $_PW_NAME--see messages above." + } +} +function _pw_hello($arg_1) { + + if ($PW_BANNER_FUNC.Length -gt 0) { + + $_PW_BANNER_FUNC = "PW_BANNER_FUNC" + } + + if ($PW_ENVSETUP_QUIET.Length -eq 0) { + pw_green " WELCOME TO...`n" + pw_magenta $_PW_BANNER + pw_green "$arg_1" + } + +} +function pw_eval_sourced($arg_1, $arg_2) { + + if ("$arg_1" -eq 0) { + + if ([string]::IsNullOrEmpty($arg_2)) { + + $GLOBAL:_PW_NAME = [System.IO.Path]::GetFileNameWithoutExtension($arg_2) + } + else { + $GLOBAL:_PW_NAME = [System.IO.Path]::GetFileNameWithoutExtension($Global:BOOTSTRAP_PATH) + } + + + pw_red " Error: Attempting to $_PW_NAME in a subshell + Since $_PW_NAME.sh modifies your shell's environment variables, + it must be sourced rather than executed. In particular, + 'bash $_PW_NAME.sh' will not work since the modified + environment will get destroyed at the end of the script. + Instead, source the script's contents in your shell: + \$ source $_PW_NAME.sh" + } +} + +function pw_check_root($arg_1) { + + If ($arg_1 -match " ") { + pw_red " Error: The Pigweed path contains spaces + The path '$arg_1' contains spaces. + Pigweed's Python environment currently requires Pigweed to be + at a path without spaces. Please checkout Pigweed in a + directory without spaces and retry running bootstrap." + } +} + +function pw_get_env_root() { + # PW_ENVIRONMENT_ROOT allows developers to specify where the environment + # should be installed. bootstrap.sh scripts should not use that variable to + # store the result of this function. This separation allows scripts to assume + # PW_ENVIRONMENT_ROOT came from the developer and not from a previous + # bootstrap possibly from another workspace. + + if ($Env:PW_ENVIRONMENT_ROOT.Length -eq 0) { + + + if ($env:PW_PROJECT_ROOT.Length -gt 0) { + + "$env:PW_PROJECT_ROOT\.environment" + + } + else { + "$env:PW_ROOT\.environment" + } + } + else { + + "$Env:PW_ENVIROMENT_ROOT" + } +} + +function pw_bootstrap() { + Param( + [parameter(Mandatory = $true)] + [String] + $shell_file, + [parameter(Mandatory = $true)] + [String] + $install_dir, + [parameter(Mandatory = $true)] + [String] + $config_file, + [parameter(Mandatory = $true)] + [String] + $virtualenv_gn_out_dir + ) + + _pw_hello " BOOTSTRAP! Bootstrap may take a few minutes; please be patient. " + + if ((Test-Path alias:python)) { + + pw_red "Error: 'python' is an alias + The shell has a 'python' alias set. This causes many obscure + Python-related issues both in and out of Pigweed. Please remove + the Python alias from your shell init file or at least run the + following command before bootstrapping Pigweed. + + Remove-Item Alias:python (powershell version 5.x)" + + exit + } + + + $local:pythonAlias = @("python", "python3", "python2") + + if ($PW_BOOTSTRAP_PYTHON.Length -gt 0) { + + $_PW_PYTHON = "$PW_BOOTSTRAP_PYTHON" + + } + else { + For ($i = 0; $i -lt $pythonAlias.Length; $i++) { + + if ((Get-Command $pythonAlias[$i]) 2> $null) { + + $_PW_PYTHON = $pythonAlias[$i] + break + } + + } + if ([string]::IsNullOrEmpty($_PW_PYTHON)) { + + pw_red "Error: Python is not present on the system + Pigweed's bootstrap process requires a local system Python. + Please install Python on your system, add it to your PATH + and re-try running bootstrap." + return + } + + } + pip install mypy-protobuf > $null + if ($Env:_PW_ENV_SETUP.Length -gt 0) { + ${$_PW_PYTHON $Env:_PW_ENV_SETUP $shell_file $install_dir $config_file $virtualenv_gn_out_dir} + $_PW_ENV_SETUP_STATUS = $LASTEXITCODE + } + else { + & $_PW_PYTHON "$env:PW_ROOT/pw_env_setup/py/pw_env_setup/env_setup.py" --shell-file "$shell_file" ` + --install-dir "$install_dir" ` + --config-file "$Global:PROJECT_ROOT_DIR\$config_file" ` + --virtualenv-gn-out-dir "$virtualenv_gn_out_dir" + + $_PW_ENV_SETUP_STATUS = $LASTEXITCODE + } + + + # Create the environment README file. Use quotes to prevent alias expansion. + Copy-Item "$env:PW_ROOT/pw_env_setup/destination.md" -Destination "$env:PW_ACTUAL_ENVIRONMENT_ROOT/README.md" +} + + +function _pw_banner() { + + #checks if enviroment variables PW_ENVSETUP_QUIET and PW_ENVSETUP_NO_BANNER are not set by user otherwise display banner + if ($PW_ENVSETUP_QUIET.Length -eq 0 -and $PW_ENVSETUP_NO_BANNER -eq 0) { + + pw_magenta $_PW_BANNER + } + +} +function cleanup_env() { + + + Remove-Item -Path Env:\PW_PROJECT_ROOT + Remove-Item -Path Env:\PW_ROOT + Remove-Item -Path Env:\PW_DOCTOR_SKIP_CIPD_CHECKS + + +} +function bootstrap_or_activate($arguments) { + + if ($arguments.Count -eq 0) { + + $BOOTSTRAP_PATH = $MyInvocation.MyCommand.Definition + $BOOTSTRAP_NAME = (Split-Path $MyInvocation.MyCommand.Definition -Leaf) + } + else { + $BOOTSTRAP_PATH = $arguments[0] + $BOOTSTRAP_NAME = (Split-Path $BOOTSTRAP_PATH -Leaf) + } + + $_CONFIG_FILE = "\scripts\environment.json" + + if (Test-Path env:PW_CONFIG_FILE) { + + $_CONFIG_FILE = $env:PW_CONFIG_FILE + } + $directoryInfo = Get-ChildItem $Global:PROJECT_ROOT_DIR\third_party\pigweed\repo | Measure-Object + + check_for_git + if ($BOOTSTRAP_NAME -eq "bootstrap.ps1" -Or $directoryInfo.count -eq 0) { + try { + git submodule update --init + } + catch { + throw "bootsrapping failed with error code $LASTEXITCODE" + } + } + + " + █ + █ + ▄ █ ▄ █ ▌ + ▀▀█████▀▀ ▄▓▀▀▀▄,▄▀▀▀▀▄ ╓▄▀▀▀▀▄█ ▀▀█▀▀▀▀▀█▀▀ ,▄▀▀▀▀▄ ▄▀▀ + ▀█▄ ▄█▀ █ █ █ ▐▌ █ █ █ .█▄▄▄▄▄▄█⌐ ▐▌ + ▀█▄ ▄█▀ █ █ █ ▐▌ █ █ █ █ ▐▌ + ▄██▀▀█ █▀▀██▄ █ █ █ ╙▀▄▄▄Φ▀█ ▀▄▄ ▀▄▄ ▀▄▄▄▄▀^ ▐▌ +▀▀ █ █ ▀▀ + + +" + New-Item -Path Env:\PW_PROJECT_ROOT -Value "$Global:PROJECT_ROOT_DIR" -ErrorAction SilentlyContinue > $null + New-Item -Path Env:\PW_ROOT -Value "$Global:PROJECT_ROOT_DIR\third_party\pigweed\repo" -ErrorAction SilentlyContinue > $null + New-Item -Path Env:\PW_ACTIVATE_SKIP_CHECKS -Value '1' -ErrorAction SilentlyContinue > $null + + + $PW_ACTUAL_ENVIRONMENT = pw_get_env_root + $_SETUP_BAT = "$PW_ACTUAL_ENVIRONMENT\activate.bat" + + + if (("$BOOTSTRAP_NAME" -eq "bootstrap.bat") -or (!(Test-Path -Path $_SETUP_BAT))) { + + pw_bootstrap ` + -shell_file "$_SETUP_BAT" ` + -install_dir "$PW_ACTUAL_ENVIRONMENT" ` + -config_file "$_CHIP_ROOT\$_CONFIG_FILE" ` + -virtualenv_gn_out_dir "$PW_ACTUAL_ENVIRONMENT\gn_out" + + pw_finalize bootstrap "$_SETUP_BAT" + } + else { + + pw_activate + pw_finalize activate "$_SETUP_BAT" + } +} + +try { + + $_PW_BANNER_FUNC = "_pw_banner" + bootstrap_or_activate $args +} +catch { + + Write-Output "Exception occured" +} diff --git a/scripts/examples/gn_efr32_example.ps1 b/scripts/examples/gn_efr32_example.ps1 new file mode 100644 index 00000000000000..2e6480146ce6c9 --- /dev/null +++ b/scripts/examples/gn_efr32_example.ps1 @@ -0,0 +1,210 @@ + +########################################################################################### +# function: check_args # +# Purpose: validates arguments passed to the script # +########################################################################################### +function check_args($commandLineArgs) { + + + if ($commandLineArgs.Count -eq 0) { + Write-Output "Build script for EFR32 Matter apps +Format: +./scripts/examples/gn_efr32_example.ps1 [] + + + Root Location of the app e.g: examples/lighting-app/efr32/ + + + Desired location for the output files + + + Identifier of the board for which this app is built + Currently Supported : + BRD4161A + BRD4163A + BRD4164A + BRD4166A + BRD4170A + BRD4186A + BRD4187A + BRD4304A + + - optional noteworthy build options for EFR32 + chip_build_libshell + Enable libshell support. (Default false) + chip_logging + Current value (Default true) + chip_openthread_ftd + Use openthread Full Thread Device, else, use Minimal Thread Device. (Default true) + efr32_sdk_root + Location for an alternate or modified efr32 SDK + enable_heap_monitoring + Monitor & log memory usage at runtime. (Default false) + enable_openthread_cli + Enables openthread cli without matter shell. (Default true) + kvs_max_entries + Set the maxium Kvs entries that can be store in NVM (Default 75) + Thresholds: 30 <= kvs_max_entries <= 255 + show_qr_code + Enables QR code on LCD for devices with an LCD + setupDiscriminator + Discriminatoor value used for BLE connexion. (Default 3840) + setupPinCode + PIN code for PASE session establishment. (Default 20202021) + enable_sleepy_device + Enable Sleepy end device. (Default false) + Must also set chip_openthread_ftd=false + use_rs911x + Build wifi example with extension board rs911x. (Default false) + use_wf200 + Build wifi example with extension board wf200. (Default false) + 'import("//with_pw_rpc.gni")' + Use to build the example with pigweed RPC + OTA_periodic_query_timeout + Periodic query timeout variable for OTA in seconds + Presets + --sed + enable sleepy end device, set thread mtd + For minimum consumption, disable openthread cli and qr code + --wifi + build wifi example variant for given exansion board +" + exit + } + if ($commandLineArgs.Count -ilt 3) { + + Write-Output "ERROR: not enough command line arguments. + ./scripts/examples/gn_efr32_example.ps1 []" + exit + } + try { + + if (Split-Path $commandLineArgs[0] -IsAbsolute) { + + $Global:EXAMPLE_DIR = $commandLineArgs[0] + } + else { + $Global:EXAMPLE_DIR = (Join-Path $PROJECT_ROOT_DIR $commandLineArgs[0]) + + } + if (!(Test-Path -Path $Global:EXAMPLE_DIR)) { + Write-Output "Path of Example doesnt exist!" + exit + } + } + catch { + Write-Output "Error: Path of Example to build is required" + exit + } + try { + if (Split-Path $commandLineArgs[1] -IsAbsolute) { + + $Global:OUT_DIR = $commandLineArgs[1] + } + else { + $Global:OUT_DIR = (Join-Path $PROJECT_ROOT_DIR $commandLineArgs[1]) + + } + } + catch { + { "Error: Output folder path is required" } + exit + } + + try { + if (@("BRD4161A", "BRD4163A", "BRD4164A", "BRD4166A", "BRD4170A", "BRD4186A", "BRD4186A", "BRD4187A", "BRD4304A").Contains($commandLineArgs[2])) { + + $Global:BOARD = $commandLineArgs[2] + + } + else { + Write-Output "$($commandLineArgs[2]) is not a recognized board" + } + } + catch { + Write-Output "$($(commandLineArgs[2])) is not a recognized board" + exit + } + if ($commandLineArgs.Count -gt 3) { + + $argsCount = $commandLineArgs.Length + for ($i = 3; $i -lt $argsCount; $i++) { + Switch ($commandLineArgs[$i]) { + --wifi { + if ($commandLineArgs.Contains("rs911x") -Or $commandLineArgs.Contains("wf200")) { + if ($commandLineArgs.Contains("rs911x")) { + $Global:optArgs += "use_rs911x=true " + } + else { + $Global:optArgs += "use_wf200=true " + } + $Global:USE_WIFI = $true + } + else { + Write-host "--wifi requires rs911x or wf200" + exit 1 + } + + } + --sed { + $Global:optArgs += "enable_sleepy_device=true chip_openthread_ftd=false " + } + --chip_enable_wifi_ipv4 { + $Global:optArgs += "chip_enable_wifi_ipv4=true " + } + default { + if ("$($commandLineArgs[$i])" -eq "use_rs911x=true" -or $commandLineArgs[$i] -eq "use_wf200=true" ) { + $Global:USE_WIFI = $true + } + if ($commandLineArgs[$i] -eq "rs911x" -or $commandLineArgs[$i] -eq "wf200" ) { + continue + } + $Global:optArgs += "$($commandLineArgs[$i]) " + } + + } + + } + } +} + + +########################################################################################### +# function: generate_binaries # +# Purpose: creates ninja.build file using gn and generates the binaries using ninja # +########################################################################################### +function generate_binaries() { + + if ($Global:USE_WIFI) { + + gn gen --check --fail-on-unused-args --export-compile-commands --root="$Global:EXAMPLE_DIR" --dotfile="$Global:EXAMPLE_DIR\build_for_wifi_gnfile.gn" --args="efr32_board=\`"$Global:BOARD\`" $Global:optArgs" "$Global:OUT_DIR\$Global:BOARD" + } + elseif ($Global:optArgs.Length -eq 0) { + + gn gen --check --fail-on-unused-args --export-compile-commands --root="$Global:EXAMPLE_DIR" --args="efr32_board=\`"$Global:BOARD\`"" "$Global:OUT_DIR\$Global:BOARD" + } + else { + gn gen --check --fail-on-unused-args --export-compile-commands --root="$Global:EXAMPLE_DIR" --args="efr32_board=\`"$Global:BOARD\`" $Global:optArgs" "$Global:OUT_DIR\$Global:BOARD" + } + + ninja -v -C "$Global:OUT_DIR\$Global:BOARD" + arm-none-eabi-size -A $Global:OUT_DIR\$Global:BOARD\*.out +} + +try { + + $Global:EXAMPLE_DIR = "" + $Global:PROJECT_ROOT_DIR = (Split-Path -Path (Split-Path -Path $PSScriptRoot)) + $Global:OUT_DIR = "" + $Global:BOARD = "" + $Global:optArgs = "" + $Global:USE_WIFI = $false + + check_args $args + . "$Global:PROJECT_ROOT_DIR\scripts\bootstrap.ps1" + generate_binaries + +} +catch { + "Exception occured $?" +} diff --git a/scripts/windows_setup.ps1 b/scripts/windows_setup.ps1 new file mode 100644 index 00000000000000..532f60c7d23f66 --- /dev/null +++ b/scripts/windows_setup.ps1 @@ -0,0 +1,240 @@ +########################################################################################### +# function: generate_pc_file # +# Purpose: creates a "package config (.pc)" file for openssl # +########################################################################################### + +function generate_pc_file($prefix) { + + New-Item "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config\openssl.pc" -ErrorAction SilentlyContinue > $null + + Set-Content "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config\openssl.pc" "prefix= $prefix" + Add-Content "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config\openssl.pc" 'exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include + +Name: OpenSSL +Description: Secure Sockets Layer and cryptography +Version: 3.0.5 +Requires: +Libs: -L${libdir} -lssl -lcrypto +Libs.private: -ldl -lz +Cflags: -I${includedir} ' + +} +########################################################################################### +# function: clean_up_env # +# Purpose: removes environment variables and directories created by this script # +########################################################################################### +function clean_up_env() { + + if (Test-Path env:PKG_CONFIG_PATH) { + + Remove-Item Env:\PKG_CONFIG_PATH + } + if (Test-Path "$Global:PROJECT_ROOT_DIR\dependencies") { + + Remove-Item "$Global:PROJECT_ROOT_DIR\dependencies" -Recurse + } + +} +function install_dependencies() { + + $pkgConfigUrl = "http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-config_0.26-1_win32.zip" + $pkgConfigDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\pkg-config_0.26-1_win32.zip" + $binFolderPath = "$Global:PROJECT_ROOT_DIR\dependencies" + + $getTextRuntimeUrl = "http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip" + $getTextRuntimeDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\gettext-runtime_0.18.1.1-2_win32.zip" + + $glibUrl = "http://ftp.acc.umu.se/pub/gnome/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip" + $glibDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\glib_2.28.8-1_win32.zip" + + $ninjaDownloadUrl = "https://github.com/ninja-build/ninja/releases/download/v1.11.0/ninja-win.zip" + $ninjaDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\ninja-win.zip" + + $gnDownloadUrl = "https://chrome-infra-packages.appspot.com/dl/gn/gn/windows-amd64/+/latest" + $gnDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\gn-windows-amd64.zip" + + if (!(Test-Path -Path "$binFolderPath\bin\pkg-config.exe" -PathType Leaf)) { + + try { + (New-Object Net.WebClient).DownloadFile($pkgConfigUrl, $pkgConfigDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + + try { + Expand-Archive -LiteralPath $pkgConfigDownloadFolder -DestinationPath $binFolderPath -Force | Out-Null + } + catch { + { "error code $LASTEXITCODE" } + + } + + } + if (!(Test-Path -Path "$binFolderPath\bin\libglib-2.0-0.dll" -PathType Leaf)) { + + + try { + (New-Object Net.WebClient).DownloadFile($glibUrl, $glibDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + + try { + Expand-Archive -LiteralPath $glibDownloadFolder -DestinationPath $binFolderPath -Force | Out-Null + } + catch { + { "error code $LASTEXITCODE" } + } + + + } + if (!(Test-Path -Path "$binFolderPath\bin\intl.dll" -PathType Leaf)) { + + try { + (New-Object Net.WebClient).DownloadFile($getTextRuntimeUrl, $getTextRuntimeDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + + try { + Expand-Archive -LiteralPath $getTextRuntimeDownloadFolder -DestinationPath $binFolderPath -Force | Out-Null + } + catch { + { "error code $LASTEXITCODE" } + } + + + } + if (!(Test-Path -Path "$binFolderPath\ninja.exe" -PathType Leaf)) { + + try { + (New-Object Net.WebClient).DownloadFile($ninjaDownloadUrl, $ninjaDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + + try { + Expand-Archive -LiteralPath $ninjaDownloadFolder -DestinationPath $binFolderPath -Force | Out-Null + } + catch { + { "error code $LASTEXITCODE" } + } + } + if (!(Test-Path -Path "$binFolderPath\gn.exe" -PathType Leaf)) { + + try { + (New-Object Net.WebClient).DownloadFile($gnDownloadUrl, $gnDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + + try { + Expand-Archive -LiteralPath $gnDownloadFolder -DestinationPath $binFolderPath -Force | Out-Null + } + catch { + { "error code $LASTEXITCODE" } + } + } + $a = "" + $b = "" + + foreach ($loc in ($env:Path -split ";")) { + + if ($loc -eq "$Global:PROJECT_ROOT_DIR\dependencies\bin" -and $a -ne "true") { + $a = "true" + $env:Path += "$binFolderPath\bin;" + } + if ($loc -eq "$Global:PROJECT_ROOT_DIR\dependencies" -and $b -ne "true") { + $b = "true" + $env:Path += "$binFolderPath;" + } + + } + if ($a -ne "true") { + $env:Path += "$binFolderPath\bin;" + } + if ($b -ne "true") { + $env:Path += "$binFolderPath;" + } + +} + +########################################################################################### +# function: install_openssl # +# Purpose: installs openssl package # +########################################################################################### + +function install_openssl() { + + + if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64" -or $env:PROCESSOR_ARCHITEW6432 -eq "AMD64") { + $bitness = "64" + $opensslInstallPath = "C:\Program Files\OpenSSL-Win${bitness}" + } + else { + $bitness = "32" + $opensslInstallPath = "C:\Program Files\OpenSSL-Win${bitness}" + } + + $openssl_install_url = "https://slproweb.com/download/Win${bitness}OpenSSL-3_0_5.exe" + $opensslDownloadFolder = "$Global:PROJECT_ROOT_DIR\dependencies\Win${bitness}OpenSSL-3_0_5.exe" + + if (Test-Path -Path $opensslInstallPath) { + + if (!(Test-Path -Path "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config\openssl.pc")) { + + generate_pc_file $opensslInstallPath + } + $env:PKG_CONFIG_PATH += "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config;" + return + } + try { + (New-Object Net.WebClient).DownloadFile($openssl_install_url, $opensslDownloadFolder) + } + catch { + { "Net.WebClient.DownloadFile Object method exited with error code $LASTEXITCODE" } + } + try { + & $opensslDownloadFolder /passive InstallAllUsers=0 PrependPath=1 Include_test=0 TargetDir=$opensslInstallPath | Out-Null + } + catch { + { "Openssl installer exited with error code $LASTEXITCODE" } + } + + generate_pc_file $opensslInstallPath + $env:PKG_CONFIG_PATH += "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config;" + +} + +function setup() { + + New-Item -Path "$Global:PROJECT_ROOT_DIR\dependencies" -ItemType Directory -ErrorAction SilentlyContinue > $null + New-Item -Path "$Global:PROJECT_ROOT_DIR\dependencies\pkg_config" -ItemType Directory -ErrorAction SilentlyContinue > $null + New-Item -Path Env:\PKG_CONFIG_PATH -Value "$PKG_CONFIG_PATH" -ErrorAction SilentlyContinue > $null +} + + +try { + if ($($args[0]) -eq "--setup") { + setup + install_dependencies + install_openssl + + } + elseif ($($args[0]) -eq "--cleanup") { + clean_up_env + } + else { + Write-Host "Format: ./script/windows_setup.ps1 <--setup or --cleanup>" + } +} +catch { + { "Exception occured " } +} \ No newline at end of file