When cmake_external script fails, do not delete build directory. (#166)

* When cmake_external script fails, do not delete build directory.

Fixes #162.
This commit is contained in:
irengrig 2018-12-04 14:32:59 +01:00 committed by GitHub
parent c82068dd2d
commit 7fdfc7cade
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 2 deletions

View File

@ -238,15 +238,33 @@ def cc_external_rule_impl(ctx, attrs):
"export INSTALLDIR=$EXT_BUILD_ROOT/" + empty.file.dirname + "/" + lib_name,
]
trap_function = [
"function cleanup() {",
"local ecode=$?",
"if [ $ecode -eq 0 ]; then",
"echo \"rules_foreign_cc: Cleaning temp directories\"",
"rm -rf $BUILD_TMPDIR $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name,
"else",
"echo \"\"",
"echo \"rules_foreign_cc: Keeping temp build directory $BUILD_TMPDIR\
and dependencies directory $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name + " for debug.\"",
"echo \"rules_foreign_cc: Please note that the directories inside a sandbox are still\
cleaned unless you specify '--sandbox_debug' Bazel command line flag.\"",
"echo \"\"",
"fi",
"}",
]
script_lines = [
"echo \"\n{}\n\"".format(version_and_lib),
"set -e",
"source " + shell_utils,
"\n".join(define_variables),
"\n".join(trap_function),
"mkdir -p $EXT_BUILD_DEPS",
"mkdir -p $INSTALLDIR",
_print_env(),
"trap \"{ rm -rf $BUILD_TMPDIR $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name + "; }\" EXIT",
"trap \"cleanup\" EXIT",
"\n".join(_copy_deps_and_tools(inputs)),
# replace placeholder with the dependencies root
"define_absolute_paths $EXT_BUILD_DEPS $EXT_BUILD_DEPS",

View File

@ -238,15 +238,33 @@ def cc_external_rule_impl(ctx, attrs):
"export INSTALLDIR=$EXT_BUILD_ROOT/" + empty.file.dirname + "/" + lib_name,
]
trap_function = [
"function cleanup() {",
"local ecode=$?",
"if [ $ecode -eq 0 ]; then",
"echo \"rules_foreign_cc: Cleaning temp directories\"",
"rm -rf $BUILD_TMPDIR $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name,
"else",
"echo \"\"",
"echo \"rules_foreign_cc: Keeping temp build directory $BUILD_TMPDIR\
and dependencies directory $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name + " for debug.\"",
"echo \"rules_foreign_cc: Please note that the directories inside a sandbox are still\
cleaned unless you specify '--sandbox_debug' Bazel command line flag.\"",
"echo \"\"",
"fi",
"}",
]
script_lines = [
"echo \"\n{}\n\"".format(version_and_lib),
"set -e",
"source " + shell_utils,
"\n".join(define_variables),
"\n".join(trap_function),
"mkdir -p $EXT_BUILD_DEPS",
"mkdir -p $INSTALLDIR",
_print_env(),
"trap \"{ rm -rf $BUILD_TMPDIR $EXT_BUILD_ROOT/bazel_foreign_cc_deps_" + lib_name + "; }\" EXIT",
"trap \"cleanup\" EXIT",
"\n".join(_copy_deps_and_tools(inputs)),
# replace placeholder with the dependencies root
"define_absolute_paths $EXT_BUILD_DEPS $EXT_BUILD_DEPS",