~ajdobbs/maus/scifi-efficiency-2

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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/bin/bash

FILE_STD=install.log

if [ ! -z "$MAUS_ROOT_DIR" ]; then
   echo "FATAL: Trying to build with \$MAUS_ROOT_DIR set. Please start a new"
   echo "FATAL: session (and don't source an existing MAUS installation)"
   echo "FATAL: before attempting to build"
   exit 1;
fi

if [ -f $FILE_STD ];
then
    rm $FILE_STD
fi

echo
echo "   Welcome to the all-in-one MAUS installer script. "
echo "You can get the details of the progress "
echo "(or ensure it is doing something) by running:"
echo
echo "  tail -f $FILE_STD"
echo
echo "and if you run into a problem with the installation, then please please"
echo "please post your error here:"
echo
echo "   http://micewww.pp.rl.ac.uk/projects/maus/issues/new"
echo
echo "so we can build up a database of errors people have seen and how they"
echo "solved them.  Be sure to attach the files:"
echo
echo "   $FILE_STD"
echo

# Assign the location of the third party libraries  
# In order of preference the location is set to:
# 1. The first command line argument passed to the install script
# 2. Any existing environment variable called "maus_third_party" e.g. if set by user's .bashrc file
# 3. The current maus working directory, as held by the variable MAUS_ROOT_DIR
# If not location is found then the script aborts 

while [[ $# > 1 ]]
do
key="$1"

case $key in
    -j|--num-threads)
    if expr "$2" : '-\?[0-9]\+$' >/dev/null
    then
        MAUS_NUM_THREADS="$2"
    fi
    shift
    ;;
    -t|--third-party-dir)
    MAUS_THIRD_PARTY="$2"
    shift
    ;;
    -u|--unpacker)
    MAUS_UNPACKER_VERSION="$2"
    shift
    ;;
    -v|--verbosity)
    if [ $2 -eq 0 ] || [ $2 -eq 1 ]; then
      MAUS_BUILD_VERBOSITY="$2"
    fi
    shift
    ;;
    --use-system-gcc)
    if [ "$2" = true ] || [ "$2" = false ]; then
    USE_SYSTEM_GCC="$2"
    fi
    shift
    ;;
esac
shift
done

# Set default to build GCC as a third party
if [ -z "$USE_SYSTEM_GCC" ]; then
    USE_SYSTEM_GCC=false
fi
if [ "$USE_SYSTEM_GCC" != true ] && [ "$USE_SYSTEM_GCC" != false ]; then
    USE_SYSTEM_GCC=false
fi
if [ "$USE_SYSTEM_GCC" = true ]; then
  echo
  echo "Using system GCC"
  echo
else
  echo
  echo "Will build GCC as a third party"
  echo
fi

if [ -z "$MAUS_NUM_THREADS" ]; then
  MAUS_NUM_THREADS=1
fi
echo "Number of threads to build with:" "${MAUS_NUM_THREADS}"
echo

if [ "$MAUS_THIRD_PARTY" ]; then
    echo "Your MAUS_THIRD_PARTY is:"
    echo ${MAUS_THIRD_PARTY}
    echo
elif [ "${maus_third_party}" ]; then
    MAUS_THIRD_PARTY=${maus_third_party}
    echo "Your MAUS_THIRD_PARTY is:"
    echo ${MAUS_THIRD_PARTY}
    echo
else
    echo "No MAUS_THIRD_PARTY set, installing third party libraries locally"
    echo
fi

if [ -z "$MAUS_UNPACKER_VERSION" ]; then
  MAUS_UNPACKER_VERSION="StepIV"
fi
if [ "$MAUS_UNPACKER_VERSION" = "StepI" ] || [ "$MAUS_UNPACKER_VERSION" = "StepIV" ];  then
  echo "MAUS Unpacker version to use:" "${MAUS_UNPACKER_VERSION}"
  echo
else
  echo "FATAL: Bad MAUS_UNPACKER_VERSION supplied"
  echo "FATAL: Please use either StepI or StepIV or leave unset"
  exit 1
fi

if [ -z "$MAUS_BUILD_VERBOSITY" ]; then
  MAUS_BUILD_VERBOSITY=0
fi

uname -a 2>>$FILE_STD 1>>$FILE_STD 
echo "Configuring..."
if [ "$MAUS_THIRD_PARTY" ]; then
    ./configure -t $MAUS_THIRD_PARTY -u $MAUS_UNPACKER_VERSION 2>> $FILE_STD 1>> $FILE_STD
    echo "Sourcing the environment..."
    source env.sh 2>>$FILE_STD 1>>$FILE_STD
    echo "Installing field maps in MAUS_ROOT_DIR..."
    if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
        ./third_party/bash/45beamline_fieldmaps.bash 2>>$FILE_STD 1>>$FILE_STD
    else
        ./third_party/bash/45beamline_fieldmaps.bash 2>&1 | tee -a $FILE_STD
    fi
    # Check new ROOT version alone is used
    source ${MAUS_THIRD_PARTY}/third_party/build/root/bin/thisroot.sh
else
    if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
        ./configure -u $MAUS_UNPACKER_VERSION 2>>$FILE_STD 1>>$FILE_STD
    else
        ./configure -u $MAUS_UNPACKER_VERSION 2>&1 | tee -a $FILE_STD
    fi
    echo "Sourcing the environment..."
    source env.sh 2>>$FILE_STD 1>>$FILE_STD
    echo "Building third party libraries (takes a while...)"
    if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
        ./third_party/build_all.bash -j $MAUS_NUM_THREADS --use-system-gcc $USE_SYSTEM_GCC 2>>$FILE_STD 1>>$FILE_STD
    else
        ./third_party/build_all.bash -j $MAUS_NUM_THREADS --use-system-gcc $USE_SYSTEM_GCC 2>&1 | tee -a $FILE_STD
    fi
    echo "Resource the environment (catches the new ROOT version)"
    source env.sh 2>>$FILE_STD 1>>$FILE_STD
    # Check new ROOT version alone is used
    source ${MAUS_ROOT_DIR}/third_party/build/root/bin/thisroot.sh
fi

if [ -z "$MAUS_THIRD_PARTY" ]; then
    export MAUS_THIRD_PARTY=$MAUS_ROOT_DIR
fi

# Check new ROOT version alone is used
source ${MAUS_THIRD_PARTY}/third_party/build/root/bin/thisroot.sh

# Check if the needed empty directories are present, if not make them
if [ ! -d ${MAUS_ROOT_DIR}/build ]; then
    mkdir ${MAUS_ROOT_DIR}/build &>/dev/null
fi
if [ ! -d ${MAUS_ROOT_DIR}/tmp ]; then
    mkdir ${MAUS_ROOT_DIR}/tmp &>/dev/null
fi
if [ ! -d ${MAUS_ROOT_DIR}/tests/integrations/plots ]; then
    mkdir ${MAUS_ROOT_DIR}/tests/integration/plots &>/dev/null
fi
if [ ! -d ${MAUS_ROOT_DIR}/tests/py_unit/test_geometry/testCases/testGDMLtoMAUSModule ]; then
    mkdir ${MAUS_ROOT_DIR}/tests/py_unit/test_geometry/testCases/testGDMLtoMAUSModule &>/dev/null
fi

echo "Cleaning the MAUS build state"
if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
    scons -c 2>>$FILE_STD 1>>$FILE_STD
else
    scons -c 2>&1 | tee -a $FILE_STD
fi

echo "Building MAUS"
if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
    (scons build -j${MAUS_NUM_THREADS} || (echo "FAIL! See logs.x" && exit 1))  2>>$FILE_STD 1>>$FILE_STD
else
    (scons build -j${MAUS_NUM_THREADS} || (echo "FAIL! See logs.x" && exit 1))  2>&1 | tee -a $FILE_STD
fi
if [ $? != 0 ]; then
    cat $FILE_STD
    echo "FAIL Failed to make MAUS using scons. Fatal error - aborting"
    exit 1
fi

echo "Run the tests"
if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
    bash ${MAUS_ROOT_DIR}/tests/unit_tests.bash  2>>$FILE_STD 1>>$FILE_STD
else
    bash ${MAUS_ROOT_DIR}/tests/unit_tests.bash  2>&1 | tee -a $FILE_STD
fi
if [ $? != 0 ]
then
    cat $FILE_STD
    echo "FAIL Failed unit tests. Fatal error - aborting"
    exit 1
fi

if [ $MAUS_BUILD_VERBOSITY -eq 0 ]; then
    bash ${MAUS_ROOT_DIR}/tests/style_tests.bash  2>>$FILE_STD 1>>$FILE_STD
else
    bash ${MAUS_ROOT_DIR}/tests/style_tests.bash  2>&1 | tee -a $FILE_STD
fi
if [ $? != 0 ]
then
    cat $FILE_STD
    echo "FAIL Failed style tests"
    exit 1
fi