diff --git a/foreign_cc/built_tools/private/built_tools_framework.bzl b/foreign_cc/built_tools/private/built_tools_framework.bzl index 5d5e15ae..b9591bed 100644 --- a/foreign_cc/built_tools/private/built_tools_framework.bzl +++ b/foreign_cc/built_tools/private/built_tools_framework.bzl @@ -63,6 +63,9 @@ def built_tool_rule_impl(ctx, script_lines, out_dir, mnemonic): "export EXT_BUILD_ROOT=##pwd##", "export INSTALLDIR=$$EXT_BUILD_ROOT$$/{}".format(out_dir.path), "export BUILD_TMPDIR=$$INSTALLDIR$$.build_tmpdir", + "##rm_rf## $$INSTALLDIR$$", + "##rm_rf## $$BUILD_TMPDIR$$", + "##mkdirs## $$INSTALLDIR$$", "##mkdirs## $$BUILD_TMPDIR$$", "##copy_dir_contents_to_dir## ./{} $$BUILD_TMPDIR$$".format(root), "cd $$BUILD_TMPDIR$$", diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl index e3135035..fecbfffd 100644 --- a/foreign_cc/private/framework.bzl +++ b/foreign_cc/private/framework.bzl @@ -396,6 +396,8 @@ def cc_external_rule_impl(ctx, attrs): "##script_prelude##", ] + env_prelude + [ "##path## $$EXT_BUILD_ROOT$$", + "##rm_rf## $$BUILD_TMPDIR$$", + "##rm_rf## $$EXT_BUILD_DEPS$$", "##mkdirs## $$INSTALLDIR$$", "##mkdirs## $$BUILD_TMPDIR$$", "##mkdirs## $$EXT_BUILD_DEPS$$", diff --git a/foreign_cc/private/framework/toolchains/commands.bzl b/foreign_cc/private/framework/toolchains/commands.bzl index f990485a..148a4a53 100644 --- a/foreign_cc/private/framework/toolchains/commands.bzl +++ b/foreign_cc/private/framework/toolchains/commands.bzl @@ -203,6 +203,10 @@ PLATFORM_COMMANDS = { "Replace the target symlink with resolved file it points to if `file` is a symlink" ), ), + "rm_rf": _command_info( + arguments = [_argument_info(name = "path", data_type = type(""), doc = "Path to directory")], + doc = "Recursively removes the given path", + ), "script_extension": _command_info( arguments = [], doc = "Return the extension for the current set of commands (`.sh` for bash, `.ps1` for powershell)", diff --git a/foreign_cc/private/framework/toolchains/linux_commands.bzl b/foreign_cc/private/framework/toolchains/linux_commands.bzl index 4ae32b39..b0c8d842 100644 --- a/foreign_cc/private/framework/toolchains/linux_commands.bzl +++ b/foreign_cc/private/framework/toolchains/linux_commands.bzl @@ -41,6 +41,9 @@ def disable_tracing(): def mkdirs(path): return "mkdir -p " + path +def rm_rf(path): + return "rm -rf " + path + def if_else(condition, if_text, else_text): return """ if [ {condition} ]; then diff --git a/foreign_cc/private/framework/toolchains/macos_commands.bzl b/foreign_cc/private/framework/toolchains/macos_commands.bzl index 7251906c..bf93d2cd 100644 --- a/foreign_cc/private/framework/toolchains/macos_commands.bzl +++ b/foreign_cc/private/framework/toolchains/macos_commands.bzl @@ -41,6 +41,9 @@ def disable_tracing(): def mkdirs(path): return "mkdir -p " + path +def rm_rf(path): + return "rm -rf " + path + def if_else(condition, if_text, else_text): return """\ if [ {condition} ]; then diff --git a/foreign_cc/private/framework/toolchains/windows_commands.bzl b/foreign_cc/private/framework/toolchains/windows_commands.bzl index 97de3466..355d1e44 100644 --- a/foreign_cc/private/framework/toolchains/windows_commands.bzl +++ b/foreign_cc/private/framework/toolchains/windows_commands.bzl @@ -41,6 +41,9 @@ def disable_tracing(): def mkdirs(path): return "mkdir -p " + path +def rm_rf(path): + return "rm -rf " + path + def if_else(condition, if_text, else_text): return """\ if [ {condition} ]; then