def __new__(cls, name, actions):
     flat_actions = list(recursively_flatten_list(actions))
     for action in flat_actions:
         if isinstance(action, LegocastleStep):
             raise LegocastleStepError(
                 'Your config has a step() nested inside a step()')
     return super(LegocastleStep, cls).__new__(cls, name, flat_actions)
    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 _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
Beispiel #4
0
    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
Beispiel #5
0
 def _render_impl(self, steps):
     return raw_shell(shell_join('\n', recursively_flatten_list(steps)))
Beispiel #6
0
 def _render_impl(self, steps):
     return raw_shell(shell_join('\n', recursively_flatten_list(steps)))