@@ -189,6 +189,16 @@ validate_opt () {
189189    done 
190190}
191191
192+ absolutify () {
193+     FILE_PATH=" ${1} " 
194+     FILE_PATH_DIRNAME=" $( dirname ${FILE_PATH} ) " 
195+     FILE_PATH_BASENAME=" $( basename ${FILE_PATH} ) " 
196+     FILE_ABS_PATH=" $( cd ${FILE_PATH_DIRNAME}  &&  pwd) " 
197+     FILE_PATH=" ${FILE_ABS_PATH} /${FILE_PATH_BASENAME} " 
198+     #  This is the return value
199+     ABSOLUTIFIED=" ${FILE_PATH} " 
200+ }
201+ 
192202CFG_SRC_DIR=" $( cd $( dirname $0 )   &&  pwd)  /" 
193203CFG_SELF=" $0 " 
194204CFG_ARGS=" $@ " 
@@ -212,6 +222,7 @@ BOOL_OPTIONS=""
212222VAL_OPTIONS=" " 
213223
214224flag uninstall " only uninstall from the installation prefix" 
225+ opt verify 1 " verify that the installed binaries run correctly" 
215226valopt prefix " /usr/local"   " set installation prefix" 
216227#  NB This isn't quite the same definition as in `configure`.
217228#  just using 'lib' instead of CFG_LIBDIR_RELATIVE
@@ -230,28 +241,50 @@ validate_opt
230241
231242#  OK, let's get installing ...
232243
244+ #  Sanity check: can we run the binaries?
245+ if  [ -z  " ${CFG_DISABLE_VERIFY} "   ]
246+ then 
247+     #  Don't do this if uninstalling. Failure here won't help in any way.
248+     if  [ -z  " ${CFG_UNINSTALL} "   ]
249+     then 
250+         msg " verifying platform can run binaries" 
251+         " ${CFG_SRC_DIR} /bin/rustc"   --version >  /dev/null
252+         if  [ $?  -ne  0 ]
253+         then 
254+             err " can't execute rustc binary on this platform" 
255+         fi 
256+     fi 
257+ fi 
258+ 
233259#  Sanity check: can we can write to the destination?
260+ msg " verifying destination is writable" 
234261umask  022 &&  mkdir -p " ${CFG_LIBDIR} " 
235- need_ok " can't write to destination. consider ' sudo' ." 
236- touch " ${CFG_LIBDIR} /rust-install-probe"   2 >  /dev/null
262+ need_ok " can't write to destination. consider \` sudo\` ." 
263+ touch " ${CFG_LIBDIR} /rust-install-probe"   >  /dev/null
237264if  [ $?  -ne  0 ]
238265then 
239-     err " can't write to destination. consider ' sudo' ." 
266+     err " can't write to destination. consider \` sudo\` ." 
240267fi 
241- rm " ${CFG_LIBDIR} /rust-install-probe" 
268+ rm -f  " ${CFG_LIBDIR} /rust-install-probe" 
242269need_ok " failed to remove install probe" 
243270
244271#  Sanity check: don't install to the directory containing the installer.
245272#  That would surely cause chaos.
273+ msg " verifying destination is not the same as source" 
246274INSTALLER_DIR=" $( cd $( dirname $0 )   &&  pwd) " 
247275PREFIX_DIR=" $( cd ${CFG_PREFIX}  &&  pwd) " 
248276if  [ " ${INSTALLER_DIR} "   =  " ${PREFIX_DIR} "   ]
249277then 
250278    err " can't install to same directory as installer" 
251279fi 
252280
281+ #  Using an absolute path to libdir in a few places so that the status
282+ #  messages are consistently using absolute paths.
283+ absolutify " ${CFG_LIBDIR} " 
284+ ABS_LIBDIR=" ${ABSOLUTIFIED} " 
285+ 
253286#  The file name of the manifest we're going to create during install
254- INSTALLED_MANIFEST=" ${CFG_LIBDIR } /rustlib/manifest" 
287+ INSTALLED_MANIFEST=" ${ABS_LIBDIR } /rustlib/manifest" 
255288
256289#  First, uninstall from the installation prefix.
257290#  Errors are warnings - try to rm everything in the manifest even if some fail.
263296        msg " removing $p " 
264297        if  [ -f  " $p "   ]
265298        then 
266-             rm " $p " 
299+             rm -f  " $p " 
267300            if  [ $?  -ne  0 ]
268301            then 
269302                warn " failed to remove $p " 
@@ -273,8 +306,16 @@ then
273306        fi 
274307    done  <  " ${INSTALLED_MANIFEST} " 
275308
309+     #  If we fail to remove rustlib below, then the installed manifest will
310+     #  still be full; the installed manifest needs to be empty before install.
311+     msg " removing ${INSTALLED_MANIFEST} " 
312+     rm -f " ${INSTALLED_MANIFEST} " 
313+     #  For the above reason, this is a hard error
314+     need_ok " failed to remove installed manifest" 
315+ 
276316    #  Remove 'rustlib' directory
277-     rm -r " ${CFG_LIBDIR} /rustlib" 
317+     msg " removing ${ABS_LIBDIR} /rustlib" 
318+     rm -Rf " ${ABS_LIBDIR} /rustlib" 
278319    if  [ $?  -ne  0 ]
279320    then 
280321        warn " failed to remove rustlib" 
298339
299340#  Create the installed manifest, which we will fill in with absolute file paths
300341mkdir -p " ${CFG_LIBDIR} /rustlib" 
342+ need_ok " failed to create rustlib" 
301343touch " ${INSTALLED_MANIFEST} " 
344+ need_ok " failed to create installed manifest" 
302345
303346#  Now install, iterate through the new manifest and copy files
304347while  read  p;  do 
@@ -324,10 +367,8 @@ while read p; do
324367
325368    #  Make the path absolute so we can uninstall it later without
326369    #  starting from the installation cwd
327-     FILE_INSTALL_PATH_DIRNAME=" $( dirname ${FILE_INSTALL_PATH} ) " 
328-     FILE_INSTALL_PATH_BASENAME=" $( basename ${FILE_INSTALL_PATH} ) " 
329-     FILE_INSTALL_ABS_PATH=" $( cd ${FILE_INSTALL_PATH_DIRNAME}  &&  pwd) " 
330-     FILE_INSTALL_PATH=" ${FILE_INSTALL_ABS_PATH} /${FILE_INSTALL_PATH_BASENAME} " 
370+     absolutify " ${FILE_INSTALL_PATH} " 
371+     FILE_INSTALL_PATH=" ${ABSOLUTIFIED} " 
331372
332373    #  Install the file
333374    msg " ${FILE_INSTALL_PATH} " 
@@ -346,6 +387,22 @@ while read p; do
346387#  The manifest lists all files to install
347388done  <  " ${CFG_SRC_DIR} /lib/rustlib/manifest.in" 
348389
390+ #  Sanity check: can we run the installed binaries?
391+ if  [ -z  " ${CFG_DISABLE_VERIFY} "   ]
392+ then 
393+     msg " verifying installed binaries are executable" 
394+     " ${CFG_PREFIX} /bin/rustc"   --version >  /dev/null
395+     if  [ $?  -ne  0 ]
396+     then 
397+         ERR=" can't execute installed rustc binary. " 
398+         ERR=" ${ERR} installation may be broken. " 
399+         ERR=" ${ERR} if this is expected then rerun install.sh with \` --disable-verify\`  " 
400+         ERR=" ${ERR} or \` make install\`  with \` --disable-verify-install\` " 
401+         err " ${ERR} " 
402+     fi 
403+ fi 
404+ 
405+ 
349406echo 
350407echo  "     Rust is ready to roll." 
351408echo 
0 commit comments