def _render_impl(self, actions): next_workdir = None shipit_projects = [] build_steps = [] for action in recursively_flatten_list(actions): if isinstance(action, LegocastleFBCheckout): next_workdir = ShellQuoted('"$(hg root)/"{d}', ).format( d=path_join(self.option('shipit_project_dir'), action.project_and_path), ) shipit_projects.append( action.project_and_path.split('/', 1)[0]) elif isinstance(action, LegocastleStep): pre_actions = [ShellQuoted('set -ex')] if next_workdir is not None: pre_actions.append(self.workdir(next_workdir)) next_workdir = None shell_steps = [] for a in itertools.chain(pre_actions, action.actions): if isinstance(a, LegocastleWorkdir): # Pass the last working directory to the next step, # since Legocastle doesn't remember it. next_workdir = a.dir shell_steps.append( ShellQuoted( # Don't evaluate {d} twice. '_wd={d} ; mkdir -p "$_wd" && cd "$_wd"'). format(d=a.dir)) else: shell_steps.append(a) build_steps.append({ 'name': action.name, 'shell': raw_shell(shell_join('\n', shell_steps)), 'required': True, }) else: raise LegocastleStepError( 'You have a top-level action {0} that is not a step()'. format(repr(action))) return shipit_projects, build_steps
def parse_args_to_fbcode_builder_opts(add_args_fn, top_level_opts, opts, help): ''' Provides some standard arguments: --debug, --option, --shell-quoted-option Then, calls `add_args_fn(parser)` to add application-specific arguments. `opts` are first used as defaults for the various command-line arguments. Then, the parsed arguments are mapped back into `opts`, which then become the values for `FBCodeBuilder.option()`, to be used both by the builder and by `get_steps_fn()`. `help` is printed in response to the `--help` argument. ''' top_level_opts = set(top_level_opts) parser = argparse.ArgumentParser( description=help, formatter_class=argparse.RawDescriptionHelpFormatter ) add_args_fn(parser) parser.add_argument( '--option', nargs=2, metavar=('KEY', 'VALUE'), action='append', default=[ (k, v) for k, v in opts.items() if k not in top_level_opts and not isinstance(v, ShellQuoted) ], help='Set project-specific options. These are assumed to be raw ' 'strings, to be shell-escaped as needed. Default: %(default)s.', ) parser.add_argument( '--shell-quoted-option', nargs=2, metavar=('KEY', 'VALUE'), action='append', default=[ (k, raw_shell(v)) for k, v in opts.items() if k not in top_level_opts and isinstance(v, ShellQuoted) ], help='Set project-specific options. These are assumed to be shell-' 'quoted, and may be used in commands as-is. Default: %(default)s.', ) parser.add_argument('--debug', action='store_true', help='Log more') args = parser.parse_args() logging.basicConfig( level=logging.DEBUG if args.debug else logging.INFO, format='%(levelname)s: %(message)s' ) # Map command-line args back into opts. logging.debug('opts before command-line arguments: {0}'.format(opts)) new_opts = {} for key in top_level_opts: val = getattr(args, key) # Allow clients to unset a default by passing a value of None in opts if val is not None: new_opts[key] = val for key, val in args.option: new_opts[key] = val for key, val in args.shell_quoted_option: new_opts[key] = ShellQuoted(val) logging.debug('opts after command-line arguments: {0}'.format(new_opts)) return new_opts
def _render_impl(self, actions): next_workdir = None shipit_projects = [] build_steps = [] for action in recursively_flatten_list(actions): if isinstance(action, LegocastleFBCheckout): next_workdir = ShellQuoted('"$(hg root)/"{d}', ).format( d=path_join(self.option('shipit_project_dir'), action.project_and_path), ) shipit_projects.append( action.project_and_path.split('/', 1)[0]) elif isinstance(action, LegocastleStep): pre_actions = [ShellQuoted('set -ex')] if action.name != 'Setup' and \ self.option("PYTHON_VENV", "OFF") == "ON": pre_actions.append(self.python_venv()) pre_actions.append( ShellQuoted(""" case "$OSTYPE" in darwin*) BREW_PREFIX=/var/tmp/homebrew # The apple-provided flex and bison tools are too old to successfully # build thrift. Ensure that we resolve to the homebrew versions. # Note that homebrew doesn't link these into its bin dir to avoid # these newer versions taking precedence, so we need to reach into # the cellar path. The glob is to make this script less prone to # problems if/when the version is bumped. BISON_BIN=$(echo $BREW_PREFIX/Cellar/bison/*/bin) FLEX_BIN=$(echo $BREW_PREFIX/Cellar/flex/*/bin) export CMAKE_SYSTEM_PREFIX_PATH=$BREW_PREFIX export PKG_CONFIG_PATH=$BREW_PREFIX/opt/openssl/lib/pkgconfig export PATH=$BISON_BIN:$FLEX_BIN:$BREW_PREFIX/bin:$PATH export HOMEBREW_NO_AUTO_UPDATE=1 export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ ;; esac """)) if next_workdir is not None: pre_actions.append(self.workdir(next_workdir)) next_workdir = None shell_steps = [] for a in itertools.chain(pre_actions, action.actions): if isinstance(a, LegocastleWorkdir): # Pass the last working directory to the next step, # since Legocastle doesn't remember it. next_workdir = a.dir shell_steps.append( ShellQuoted( # Don't evaluate {d} twice. '_wd={d} ; mkdir -p "$_wd" && cd "$_wd"'). format(d=a.dir)) else: shell_steps.append(a) build_steps.append({ 'name': action.name, 'shell': raw_shell(shell_join('\n', shell_steps)), 'required': True, }) else: raise LegocastleStepError( 'You have a top-level action {0} that is not a step()'. format(repr(action))) return shipit_projects, build_steps
def _render_impl(self, actions): # This exists to transfer the current working directory to the next # step, since Legocastle doesn't remember it. Although this is # potentially quadratic, we have to replay ALL workdir calls from # the previous step because these might contain variable expansions, # making it impossible to distinguish relative directories from # absolute. Consider this step: # [ # builder.fb_github_project_workdir('foo/bar') # ... # builder.workdir('baz') # Now should be at foo/bar/baz # ] # # If we just replayed the last workdir('baz'), we would not end up # in '<github_prefix>/foo/bar/baz', but rather in `<unknown>/baz`. next_step_workdirs = [] shipit_projects = [] build_steps = [] for action in recursively_flatten_list(actions): if isinstance(action, LegocastleFBCheckout): # This is guaranteed to be absolute, so drop the unnecessary # history. next_step_workdirs = [ ShellQuoted('"$(hg root)/"{d}', ).format(d=path_join( self.option('shipit_project_dir'), action.project_and_path), ) ] shipit_projects.append( action.project_and_path.split('/', 1)[0]) elif isinstance(action, LegocastleStep): pre_actions = [ShellQuoted('set -ex')] if action.name != 'Setup' and \ self.option("PYTHON_VENV", "OFF") == "ON": pre_actions.extend(self.python_venv()) pre_actions.append( ShellQuoted(""" case "$OSTYPE" in darwin*) BREW_PREFIX=/var/tmp/homebrew # The apple-provided flex and bison tools are too old to successfully # build thrift. Ensure that we resolve to the homebrew versions. # Note that homebrew doesn't link these into its bin dir to avoid # these newer versions taking precedence, so we need to reach into # the cellar path. The glob is to make this script less prone to # problems if/when the version is bumped. BISON_BIN=$(echo $BREW_PREFIX/Cellar/bison/*/bin) FLEX_BIN=$(echo $BREW_PREFIX/Cellar/flex/*/bin) export CMAKE_SYSTEM_PREFIX_PATH=$BREW_PREFIX export PKG_CONFIG_PATH=$BREW_PREFIX/opt/openssl/lib/pkgconfig export PATH=$BISON_BIN:$FLEX_BIN:$BREW_PREFIX/bin:$PATH export HOMEBREW_NO_AUTO_UPDATE=1 export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ ;; esac """)) pre_actions.extend(self.workdir(w) for w in next_step_workdirs) shell_steps = [] for a in itertools.chain(pre_actions, action.actions): if isinstance(a, LegocastleWorkdir): next_step_workdirs.append(a.dir) shell_steps.append( ShellQuoted( # Don't evaluate {d} twice. '_wd={d} ; mkdir -p "$_wd" && cd "$_wd"'). format(d=a.dir)) else: shell_steps.append(a) build_steps.append({ 'name': action.name, 'shell': raw_shell(shell_join('\n', shell_steps)), 'required': True, }) else: raise LegocastleStepError( 'You have a top-level action {0} that is not a step()'. format(repr(action))) return shipit_projects, build_steps
def _render_impl(self, steps): return raw_shell(shell_join('\n', recursively_flatten_list(steps)))
def parse_args_to_fbcode_builder_opts(add_args_fn, top_level_opts, opts, help): """ Provides some standard arguments: --debug, --option, --shell-quoted-option Then, calls `add_args_fn(parser)` to add application-specific arguments. `opts` are first used as defaults for the various command-line arguments. Then, the parsed arguments are mapped back into `opts`, which then become the values for `FBCodeBuilder.option()`, to be used both by the builder and by `get_steps_fn()`. `help` is printed in response to the `--help` argument. """ top_level_opts = set(top_level_opts) parser = argparse.ArgumentParser( description=help, formatter_class=argparse.RawDescriptionHelpFormatter) add_args_fn(parser) parser.add_argument( "--option", nargs=2, metavar=("KEY", "VALUE"), action="append", default=[(k, v) for k, v in opts.items() if k not in top_level_opts and not isinstance(v, ShellQuoted) ], help="Set project-specific options. These are assumed to be raw " "strings, to be shell-escaped as needed. Default: %(default)s.", ) parser.add_argument( "--shell-quoted-option", nargs=2, metavar=("KEY", "VALUE"), action="append", default=[(k, raw_shell(v)) for k, v in opts.items() if k not in top_level_opts and isinstance(v, ShellQuoted)], help="Set project-specific options. These are assumed to be shell-" "quoted, and may be used in commands as-is. Default: %(default)s.", ) parser.add_argument("--debug", action="store_true", help="Log more") args = parser.parse_args() logging.basicConfig( level=logging.DEBUG if args.debug else logging.INFO, format="%(levelname)s: %(message)s", ) # Map command-line args back into opts. logging.debug("opts before command-line arguments: {0}".format(opts)) new_opts = {} for key in top_level_opts: val = getattr(args, key) # Allow clients to unset a default by passing a value of None in opts if val is not None: new_opts[key] = val for key, val in args.option: new_opts[key] = val for key, val in args.shell_quoted_option: new_opts[key] = ShellQuoted(val) logging.debug("opts after command-line arguments: {0}".format(new_opts)) return new_opts