forked from sandialabs/spack-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.sh
207 lines (185 loc) · 6.54 KB
/
start.sh
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
#
# Copyright (c) 2022, National Technology & Engineering Solutions of Sandia,
# LLC (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
# Government retains certain rights in this software.
#
# This software is released under the BSD 3-clause license. See LICENSE file
# for more details.
#
cmd() {
echo "+ $@"
eval "$@"
}
########################################################
# Tests
########################################################
if [[ -z ${SPACK_MANAGER} ]]; then
echo "Env variable SPACK_MANAGER not set. You must set this variable."
return 125
fi
if [[ ! -x $(which python3) ]]; then
echo "Warning: spack-manager is only designed to work with python 3."
echo "You may use spack, but spack-manager specific commands will fail."
fi
# convenience function for getting to the spack-manager directory
function cd-sm(){
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "Convenience function for navigating to the spack-manager directory"
return
fi
cd ${SPACK_MANAGER}
}
# function to initialize spack-manager's spack instance
function spack-start() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "This function loads spack into your active shell"
return
fi
source $SPACK_MANAGER/scripts/spack_start.sh
}
# function to quickly activate an environment
function quick-activate() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "This function loads spack and activates the spack environment whose directory you provide as an argument"
return
fi
cmd "spack-start"
cmd "spack env activate -p -d $1"
}
# convenience function for quickly creating an environment
# and activating it in the current shell
function quick-create() {
cmd "spack-start"
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "*************************************************************
HELP MESSAGE:
quick-create sets up a basic spack environment
The next typical steps after running this command are to add specs
and calling spack manager develop to clone dev specs, adding externals
etc.
The base command and it's help are echoed below:
"
cmd "spack manager create-env $@"
echo "*************************************************************"
return
fi
cmd "spack manager create-env $@"
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-create prematurely\n"
return 1
fi
EPATH=$(cat $SPACK_MANAGER/.tmp/created_env_path.txt)
cmd "spack env activate --dir ${EPATH} --prompt"
}
# same as quick-create but calls create-env-dev instead
# can be used to add externals
function quick-create-dev() {
cmd "spack-start"
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "*************************************************************
HELP MESSAGE:
quick-create-dev sets up a developer environment
where all specs are develop specs that will be automatically cloned
from the default repos
The next typical steps after running this command are to add externals if
you want them, or run spack install.
The base command and it's help are echoed below:
"
cmd "spack manager create-dev-env $@"
echo "*************************************************************"
return
fi
cmd "spack manager create-dev-env $@"
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-create prematurely\n"
return 1
fi
EPATH=$(cat $SPACK_MANAGER/.tmp/created_env_path.txt)
cmd "spack env activate --dir ${EPATH} --prompt"
}
# function to create, activate, concretize and attempt to install a develop environment all in one step
function quick-develop() {
cmd "spack-start"
# since we want this to run in the active shell
# we mush manually return instead of exiting with set -e
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-develop prematurely\n"
return 1
fi
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "*************************************************************
HELP MESSAGE:
quick-develop sets up a developer environment and installs it
This command is designed to require minimal arguments and simple setup
with the caveat of accepting all the defaults for:
- repo and branch cloned for your packages
- latest external snapshot with the default compilers/configurations
The base command and it's help are echoed below:
"
cmd "spack manager create-dev-env $@"
echo "*************************************************************"
return
fi
cmd "spack manager create-dev-env $*"
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-develop prematurely\n"
return 1
fi
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
return
fi
EPATH=$(cat $SPACK_MANAGER/.tmp/created_env_path.txt)
cmd "spack env activate --dir ${EPATH} --prompt"
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-develop prematurely\n"
return 1
fi
cmd "spack manager external --latest"
if [[ $? != 0 ]]; then
printf "\nERROR: Exiting quick-develop prematurely\n"
return 1
fi
}
# function to remove spack prompt from the shell
function remove-spack-prompt() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "This command removes a spack added shell prompt (if it exists) that signifies the current environment name."
return
fi
if [[ -n "${SPACK_OLD_PS1}" ]]; then
PS1=${SPACK_OLD_PS1}
unset SPACK_OLD_PS1
fi
}
# function for diving into the build environment from a spack build
function build-env-dive() {
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "This command will setup and dive into the build environment of the spec provided in a new subshell, and then move into the build directory."
return
fi
if [[ -z ${SPACK_ENV} ]]; then
echo "You must have an active environment to use build-env-dive."
return 1
fi
cmd "spack build-env --dump ${SPACK_MANAGER}/.tmp/spack-build-env.txt $*"
cmd "bash --rcfile <(echo '. ${SPACK_MANAGER}/.tmp/spack-build-env.txt; spack cd -b $*')"
}
# function for cleaning spack-manager and spack directories
function sm-clean(){
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "This command will clean out spack and spack-manager caches and other problematic directories"
return
fi
echo "Remove user cache of configs:"
cmd "rm -rf ~/.spack"
echo "Remove Spack-Manager cache:"
# leave for legacy purposes
cmd "rm -rf ${SPACK_MANAGER}/.cache"
# new config path
cmd "rm -rf ${SPACK_MANAGER}/.spack"
echo "Use the native Spack clean system":
cmd "spack clean --all"
echo "Cleaning out pycache from spack-manager repos:"
cmd "find ${SPACK_MANAGER}/repos -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete"
}