summaryrefslogtreecommitdiff
path: root/share/spack/setup-env.ps1
blob: d3bed93d9ba3f28ffc6066a8be8ff248d7ba877f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

Push-Location $PSScriptRoot/../..
$Env:SPACK_ROOT = $PWD.Path
Push-Location $PWD/..
$Env:spackinstdir = $PWD.Path
Pop-Location

Set-Variable -Name python_pf_ver -Value (Get-Command -Name python -ErrorAction SilentlyContinue).Path

# If python_pf_ver is not defined, we cannot find Python on the Path
# We next look for Spack vendored copys
if ($null -eq $python_pf_ver)
{
    $python_pf_ver_list = Resolve-Path -Path "$PWD\Python*"
    if ($python_pf_ver_list.Length -gt 0)
    {
        $py_path = $python_pf_ver_list[$python_pf_ver_list.Length-1].Path
        $py_exe = "$py_path\python.exe"
    }
    else {
        Write-Error -Message "Python was not found on system"
        Write-Output "Please install Python or add Python to the PATH"
    }
}
else{
    Set-Variable -Name py_exe -Value $python_pf_ver
}

if (!$null -eq $py_path)
{
    $Env:Path = "$py_path;$Env:Path"
}

if (!$null -eq $py_exe)
{
    & "$py_exe" "$Env:SPACK_ROOT\bin\haspywin.py"
}

$Env:Path = "$Env:SPACK_ROOT\bin;$Env:Path"
if ($null -eq $Env:EDITOR)
{
    $Env:EDITOR = "notepad"
}

# Set spack shell so we can detect powershell context
$Env:SPACK_SHELL="pwsh"

doskey /exename=powershell.exe spack=$Env:SPACK_ROOT\bin\spack.ps1 $args

Write-Output "*****************************************************************"
Write-Output "**************** Spack Package Manager **************************"
Write-Output "*****************************************************************"

function global:prompt
{
    $pth = $(Convert-Path $(Get-Location)) | Split-Path -leaf
    "[spack] PS $pth>"
}
Pop-Location