Skip to content

Commit

Permalink
Build under Bazel sandbox instead of /tmp (#479)
Browse files Browse the repository at this point in the history
* Build under bazel sandbox instead of /tmp, and remove redundant printf

Build artifacts under /tmp are not cleaned up after a failed build, for
the ease of debugging.  However, this can quickly fill up the /tmp partition
if the build is large.  Build under the sandbox directory instead, and
rely on standard bazel cleanup scheme.

Also remove a print from the cleanup function, which somehow causes empty
newlines to be printed in bazel build output.

* Avoid infinite recursion in symlink_to_dir.

This is a somewhat hackish approach to exclude *.ext_build_deps from
symlinks when creating the symlink forest. This is necessary in cases
where an entire directory is added to the includes, e.g. when setting
includes = ["."] where the directory itself contains a cmake_external()
rule that depends on the very rule containing the includes = ["."].

* Also avoid using a temp directory when bootstrapping make or cmake itself.

* Remove the ##tmpdir## shell toolchain command.

It is no longer necessary now that all its uses are gone.

Co-authored-by: Lauri Peltonen <[email protected]>
  • Loading branch information
Attila Oláh and scele authored Feb 5, 2021
1 parent 603f3d8 commit 466c32c
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion for_workspace/cmake_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _cmake_tool(ctx):
cmake = ctx.actions.declare_directory("cmake")
script = [
"export BUILD_DIR=##pwd##",
"export BUILD_TMPDIR=##tmpdir##",
"export BUILD_TMPDIR=$${BUILD_DIR}$$.build_tmpdir",
"##copy_dir_contents_to_dir## ./{} $BUILD_TMPDIR".format(root),
"##mkdirs## " + cmake.path,
"cd $$BUILD_TMPDIR$$",
Expand Down
2 changes: 1 addition & 1 deletion for_workspace/make_build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def _make_tool(ctx):
make = ctx.actions.declare_directory("make")
script = [
"export BUILD_DIR=##pwd##",
"export BUILD_TMPDIR=##tmpdir##",
"export BUILD_TMPDIR=$${BUILD_DIR}$$.build_tmpdir",
"##copy_dir_contents_to_dir## ./{} $BUILD_TMPDIR".format(root),
"cd $$BUILD_TMPDIR$$",
"./configure --prefix=$$BUILD_DIR$$/{}".format(make.path),
Expand Down
2 changes: 2 additions & 0 deletions test/expected/inner_fun_text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ IFS=$SAVEIFS
local dirname=$(basename "$1")
mkdir -p "$target/$dirname"
for child in "${children[@]}"; do
if [[ "$dirname" != *.ext_build_deps ]]; then
symlink_to_dir "$child" "$target/$dirname"
fi
done
else
echo "Can not copy $1"
Expand Down
3 changes: 0 additions & 3 deletions toolchains_examples/fancy_platform_commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def touch(path):
def mkdirs(path):
return "mkdir -p " + path

def tmpdir():
return "$(mktemp -d)"

def if_else(condition, if_text, else_text):
return """
if [ {condition} ]; then
Expand Down
6 changes: 4 additions & 2 deletions tools/build_defs/framework.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,9 @@ def cc_external_rule_impl(ctx, attrs):
define_variables = [
set_cc_envs,
"export EXT_BUILD_ROOT=##pwd##",
"export BUILD_TMPDIR=##tmpdir##",
"export EXT_BUILD_DEPS=##tmpdir##",
"export INSTALLDIR=$$EXT_BUILD_ROOT$$/" + empty.file.dirname + "/" + lib_name,
"export BUILD_TMPDIR=$${INSTALLDIR}$$.build_tmpdir",
"export EXT_BUILD_DEPS=$${INSTALLDIR}$$.ext_build_deps",
] + [
"export {key}={value}".format(
key=key,
Expand All @@ -350,6 +350,8 @@ def cc_external_rule_impl(ctx, attrs):
"\n".join(define_variables),
"##path## $$EXT_BUILD_ROOT$$",
"##mkdirs## $$INSTALLDIR$$",
"##mkdirs## $$BUILD_TMPDIR$$",
"##mkdirs## $$EXT_BUILD_DEPS$$",
_print_env(),
"\n".join(_copy_deps_and_tools(inputs)),
"cd $$BUILD_TMPDIR$$",
Expand Down
4 changes: 0 additions & 4 deletions tools/build_defs/shell_toolchain/toolchains/commands.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ PLATFORM_COMMANDS = {
"NB symlinks from the source directory are copied."
),
),
"tmpdir": CommandInfo(
doc = "Creates a temp directory",
arguments = [],
),
"touch": CommandInfo(
arguments = [ArgumentInfo(name = "path", type_ = type(""), doc = "Path to file")],
doc = "Creates a file",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def touch(path):
def mkdirs(path):
return "mkdir -p " + path

def tmpdir():
return "$(mktemp -d)"

def if_else(condition, if_text, else_text):
return """
if [ {condition} ]; then
Expand Down Expand Up @@ -100,7 +97,9 @@ elif [[ -d "$1" ]]; then
IFS=$SAVEIFS
local dirname=$(basename "$1")
for child in "${children[@]}"; do
##symlink_to_dir## "$child" "$target/$dirname"
if [[ "$dirname" != *.ext_build_deps ]]; then
##symlink_to_dir## "$child" "$target/$dirname"
fi
done
else
echo "Can not copy $1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def touch(path):
def mkdirs(path):
return "mkdir -p " + path

def tmpdir():
return "$(mktemp -d)"

def if_else(condition, if_text, else_text):
return """
if [ {condition} ]; then
Expand Down Expand Up @@ -100,7 +97,9 @@ elif [[ -d "$1" ]]; then
local dirname=$(basename "$1")
mkdir -p "$target/$dirname"
for child in "${children[@]}"; do
##symlink_to_dir## "$child" "$target/$dirname"
if [[ "$dirname" != *.ext_build_deps ]]; then
##symlink_to_dir## "$child" "$target/$dirname"
fi
done
else
echo "Can not copy $1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def touch(path):
def mkdirs(path):
return "mkdir -p " + path

def tmpdir():
return "$(mktemp -d)"

def if_else(condition, if_text, else_text):
return """
if [ {condition} ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ def touch(path):
def mkdirs(path):
return "mkdir -p " + path

def tmpdir():
return "$(mktemp -d)"

def if_else(condition, if_text, else_text):
return """
if [ {condition} ]; then
Expand Down Expand Up @@ -99,7 +96,9 @@ elif [[ -d "$1" ]]; then
local children=($($REAL_FIND -H "$1" -maxdepth 1 -mindepth 1))
IFS=$SAVEIFS
for child in "${children[@]}"; do
##symlink_to_dir## "$child" "$target/$(basename $1)"
if [[ "$dirname" != *.ext_build_deps ]]; then
##symlink_to_dir## "$child" "$target/$(basename $1)"
fi
done
else
echo "Can not copy $1"
Expand Down

0 comments on commit 466c32c

Please sign in to comment.