3 from __future__
import absolute_import
4 from __future__
import division
5 from __future__
import print_function
6 from __future__
import unicode_literals
9 shell_builder.py allows running the fbcode_builder logic 10 on the host rather than in a container. 12 It emits a bash script with set -exo pipefail configured such that 13 any failing step will cause the script to exit with failure. 18 python fbcode_builder/shell_builder.py > ~/run.sh 23 import distutils.spawn
25 from fbcode_builder
import FBCodeBuilder
26 from shell_quoting
import (
27 raw_shell, shell_comment, shell_join, ShellQuoted
29 from utils
import recursively_flatten_list
32 class ShellFBCodeBuilder(FBCodeBuilder):
38 ShellQuoted(
'mkdir -p {d} && cd {d}').
format(
43 def run(self, shell_cmd):
44 return ShellQuoted(
'{cmd}').
format(cmd=shell_cmd)
46 def step(self, name, actions):
47 assert '\n' not in name,
'Name {0} would span > 1 line'.
format(name)
49 return [ShellQuoted(
'### {0} ###'.
format(name)), b] + actions + [b]
53 ShellQuoted(
'set -exo pipefail'),
56 ccache_dir = self.
option(
'ccache_dir')
60 'export CCACHE_DIR={ccache_dir} ' 61 'CC="ccache ${{CC:-gcc}}" CXX="ccache ${{CXX:-g++}}"' 62 ).
format(ccache_dir=ccache_dir)
71 ShellQuoted(
'cp -r {dir} {dest_name}').
format(
79 here = os.path.dirname(os.path.realpath(__file__))
80 maybe_root = os.path.dirname(os.path.dirname(here))
81 if os.path.isdir(os.path.join(maybe_root,
'.git')):
84 "I expected shell_builder.py to be in the " 85 "build/fbcode_builder subdir of a git repo")
89 escaped = repo_root.replace(
'/',
'sZs').
replace(
'\\',
'sZs').
replace(
':',
'')
90 return os.path.join(os.path.expandvars(
"$HOME"),
'.fbcode_builder-' + escaped)
93 if __name__ ==
'__main__':
94 from utils
import read_fbcode_builder_config, build_fbcode_builder_config
101 builder.add_option(
'projects_dir', temp)
102 if distutils.spawn.find_executable(
'ccache'):
103 builder.add_option(
'ccache_dir',
104 os.environ.get(
'CCACHE_DIR', os.path.join(temp,
'.ccache')))
105 builder.add_option(
'prefix', os.path.join(temp,
'installed'))
106 builder.add_option(
'make_parallelism', 4)
108 '{project}:local_repo_dir'.
format(project=config[
'github_project']),
112 print(builder.render(steps))
def step(self, name, actions)
def comment(self, comment)
def has_option(self, name)
def _render_impl(self, steps)
void BENCHFUN() replace(size_t iters, size_t arg)
def recursively_flatten_list(l)
def persistent_temp_dir(repo_root)
def build_fbcode_builder_config(config)
def read_fbcode_builder_config(filename)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
def option(self, name, default=None)
def copy_local_repo(self, dir, dest_name)
def shell_join(delim, it)