Skip to content

Commit

Permalink
add error handling when _setup_util.py fails, e.g. due to disk full (fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Dec 13, 2013
1 parent 649dd14 commit 46a676e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
53 changes: 33 additions & 20 deletions cmake/templates/_setup_util.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from __future__ import print_function
import argparse
import copy
import errno
import os
import platform
import sys
Expand Down Expand Up @@ -244,24 +245,36 @@ def _parse_arguments(args=None):

if __name__ == '__main__':
try:
args = _parse_arguments()
except Exception as e:
print(e, file=sys.stderr)
exit(1)

# environment at generation time
CMAKE_PREFIX_PATH = '@CMAKE_PREFIX_PATH_AS_IS@'.split(';')
# prepend current workspace if not already part of CPP
base_path = os.path.dirname(__file__)
if base_path not in CMAKE_PREFIX_PATH:
CMAKE_PREFIX_PATH.insert(0, base_path)
CMAKE_PREFIX_PATH = os.pathsep.join(CMAKE_PREFIX_PATH)

environ = dict(os.environ)
lines = []
if not args.extend:
lines += rollback_env_variables(environ, ENV_VAR_SUBFOLDERS)
lines += prepend_env_variables(environ, ENV_VAR_SUBFOLDERS, CMAKE_PREFIX_PATH)
lines += find_env_hooks(environ, CMAKE_PREFIX_PATH)
print('\n'.join(lines))
try:
args = _parse_arguments()
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)

# environment at generation time
CMAKE_PREFIX_PATH = '@CMAKE_PREFIX_PATH_AS_IS@'.split(';')
# prepend current workspace if not already part of CPP
base_path = os.path.dirname(__file__)
if base_path not in CMAKE_PREFIX_PATH:
CMAKE_PREFIX_PATH.insert(0, base_path)
CMAKE_PREFIX_PATH = os.pathsep.join(CMAKE_PREFIX_PATH)

environ = dict(os.environ)
lines = []
if not args.extend:
lines += rollback_env_variables(environ, ENV_VAR_SUBFOLDERS)
lines += prepend_env_variables(environ, ENV_VAR_SUBFOLDERS, CMAKE_PREFIX_PATH)
lines += find_env_hooks(environ, CMAKE_PREFIX_PATH)
print('\n'.join(lines))

# need to explicitly flush the output
sys.stdout.flush()
except IOError as e:
# and catch potantial "broken pipe" if stdout is not writable
# which can happen when piping the output to a file but the disk is full
if e.errno == errno.EPIPE:
print(e, file=sys.stderr)
sys.exit(2)
raise

sys.exit(0)
14 changes: 14 additions & 0 deletions cmake/templates/setup.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ if [ $? -ne 0 -o ! -f "$_SETUP_TMP" ]; then
return 1
fi
CATKIN_SHELL=$CATKIN_SHELL "$_SETUP_UTIL" $@ > $_SETUP_TMP
_RC=$?
if [ $_RC -ne 0 ]; then
if [ $_RC -eq 2 ]; then
echo "Could not write the output of '$_SETUP_UTIL' to temporary file '$_SETUP_TMP': may be the disk if full?"
else
echo "Failed to run '\"$_SETUP_UTIL\" $@': return code $_RC"
fi
unset _RC
unset _SETUP_UTIL
rm -f $_SETUP_TMP
unset _SETUP_TMP
return 1
fi
unset _RC
unset _SETUP_UTIL
. $_SETUP_TMP
rm -f $_SETUP_TMP
Expand Down

0 comments on commit 46a676e

Please sign in to comment.