コード例 #1
0
    def _run(self, command):
        result = []
        system_dir = join(util.get_home_dir(), 'packages', 'system')

        if isdir(system_dir):
            result = util.exec_command(join(system_dir, command + self.ext),
                                       stdout=util.AsyncPipe(self._on_run_out),
                                       stderr=util.AsyncPipe(self._on_run_out))
        else:
            click.secho('Error: system tools are not installed', fg='red')
            click.secho('Please run:\n' '   apio install system', fg='yellow')
            return 1

        return result
コード例 #2
0
    def _run(self, command):
        result = {}
        system_base_dir = util.get_package_dir('tools-system')
        system_bin_dir = util.safe_join(system_base_dir, 'bin')

        if isdir(system_bin_dir):
            result = util.exec_command(util.safe_join(system_bin_dir,
                                                      command + self.ext),
                                       stdout=util.AsyncPipe(self._on_run_out),
                                       stderr=util.AsyncPipe(self._on_run_out))
        else:
            util._check_package('system')
            return 1

        return result
コード例 #3
0
    def _run_command(self, command, silent=False):
        result = {}
        system_base_dir = util.get_package_dir('tools-system')
        system_bin_dir = util.safe_join(system_base_dir, 'bin')

        on_stdout = None if silent else self._on_stdout
        on_stderr = self._on_stderr

        if util.check_package(self.name, self.version, self.spec_version,
                              system_bin_dir):
            result = util.exec_command(util.safe_join(system_bin_dir,
                                                      command + self.ext),
                                       stdout=util.AsyncPipe(on_stdout),
                                       stderr=util.AsyncPipe(on_stderr))

        return result
コード例 #4
0
    def _execute_scons(self, command, variables, board):
        terminal_width, _ = click.get_terminal_size()
        start_time = time.time()

        if command == 'build' or \
           command == 'upload' or \
           command == 'time':
            if board:
                processing_board = board
            else:
                processing_board = 'custom board'
            click.echo('[%s] Processing %s' % (
                datetime.datetime.now().strftime('%c'),
                click.style(processing_board, fg='cyan', bold=True)))
            click.secho('-' * terminal_width, bold=True)

        if self.profile.get_verbose_mode() > 0:
            click.secho('Executing: {}'.format(
                        ' '.join(util.scons_command + ['-Q', command] +
                                 variables)))

        result = util.exec_command(
            util.scons_command + ['-Q', command] + variables,
            stdout=util.AsyncPipe(self._on_stdout),
            stderr=util.AsyncPipe(self._on_stderr)
        )

        # -- Print result
        exit_code = result.get('returncode')
        is_error = exit_code != 0
        summary_text = ' Took %.2f seconds ' % (time.time() - start_time)
        half_line = '=' * int(
            ((terminal_width - len(summary_text) - 10) / 2))
        click.echo('%s [%s]%s%s' % (
            half_line,
            (click.style(' ERROR ', fg='red', bold=True)
             if is_error else click.style('SUCCESS', fg='green', bold=True)),
            summary_text,
            half_line
        ), err=is_error)

        return exit_code
コード例 #5
0
    def run(self, command, variables=[], board=None):
        """Executes scons for building"""

        packages_dir = os.path.join(util.get_home_dir(), 'packages')
        icestorm_dir = os.path.join(packages_dir, 'toolchain-icestorm', 'bin')
        iverilog_dir = os.path.join(packages_dir, 'toolchain-iverilog', 'bin')
        scons_dir = os.path.join(packages_dir, 'tool-scons', 'script')
        sconstruct_name = 'SConstruct'

        # Give the priority to the packages installed by apio
        os.environ['PATH'] = os.pathsep.join(
            [iverilog_dir, icestorm_dir, os.environ['PATH']])

        # Add environment variables
        os.environ['IVL'] = os.path.join(packages_dir, 'toolchain-iverilog',
                                         'lib', 'ivl')
        os.environ['VLIB'] = os.path.join(packages_dir, 'toolchain-iverilog',
                                          'vlib', 'system.v')

        # -- Check for the scons
        if not isdir(scons_dir):
            click.secho('Error: scons toolchain is not installed', fg='red')
            click.secho('Please run:\n' '   apio install scons', fg='yellow')

        # -- Check for the icestorm tools
        if not isdir(icestorm_dir):
            click.secho('Error: icestorm toolchain is not installed', fg='red')
            click.secho('Please run:\n'
                        '   apio install icestorm',
                        fg='yellow')

        # -- Check for the iverilog tools
        if not isdir(iverilog_dir):
            click.secho('Error: iverilog toolchain is not installed', fg='red')
            click.secho('Please run:\n'
                        '   apio install iverilog',
                        fg='yellow')

        # -- Check for the SConstruct file
        if not isfile(join(util.get_project_dir(), sconstruct_name)):
            click.secho('Using default SConstruct file')
            variables += [
                '-f',
                join(dirname(__file__), '..', 'resources', sconstruct_name)
            ]

        # -- Execute scons
        if isdir(scons_dir) and isdir(icestorm_dir) and isdir(iverilog_dir):
            terminal_width, _ = click.get_terminal_size()
            start_time = time.time()

            if command == 'build' or \
               command == 'upload' or \
               command == 'time':
                if board:
                    processing_board = board
                else:
                    processing_board = 'custom board'
                click.echo(
                    "[%s] Processing %s" %
                    (datetime.datetime.now().strftime("%c"),
                     click.style(processing_board, fg="cyan", bold=True)))
                click.secho("-" * terminal_width, bold=True)

            click.secho("Executing: scons -Q {0} {1}".format(
                command, ' '.join(variables)))
            result = util.exec_command([
                os.path.normpath(sys.executable),
                os.path.join(scons_dir, 'scons'), '-Q', command
            ] + variables,
                                       stdout=util.AsyncPipe(self._on_run_out),
                                       stderr=util.AsyncPipe(self._on_run_err))

            # -- Print result
            exit_code = result['returncode']
            is_error = exit_code != 0
            summary_text = " Took %.2f seconds " % (time.time() - start_time)
            half_line = "=" * int(
                ((terminal_width - len(summary_text) - 10) / 2))
            click.echo(
                "%s [%s]%s%s" %
                (half_line,
                 (click.style(" ERROR ", fg="red", bold=True) if is_error else
                  click.style("SUCCESS", fg="green", bold=True)), summary_text,
                 half_line),
                err=is_error)

            if False:
                if is_error:
                    print("""
  ______                     _
 |  ____|                   | |
 | |__   _ __ _ __ ___  _ __| |
 |  __| | '__| '__/ _ \| '__| |
 | |____| |  | | | (_) | |  |_|
 |______|_|  |_|  \___/|_|  (_)
""")
                else:
                    print("""
   _____                             _
  / ____|                           | |
 | (___  _   _  ___ ___ ___  ___ ___| |
  \___ \| | | |/ __/ __/ _ \/ __/ __| |
  ____) | |_| | (_| (_|  __/\__ \__ \_|
 |_____/ \__,_|\___\___\___||___/___(_)
""")

            return exit_code
        else:
            return 1
コード例 #6
0
ファイル: scons.py プロジェクト: jpenalbae/apio
    def run(self, command, variables=[], board=None, deps=[]):
        """Executes scons for building"""

        # -- Check for the SConstruct file
        if not isfile(util.safe_join(util.get_project_dir(), 'SConstruct')):
            click.secho('Info: default SConstruct file')
            variables += ['-f']
            variables += [
                util.safe_join(util.get_folder('resources'), 'SConstruct')
            ]

        # -- Resolve packages
        if self.profile.check_exe_default():
            # Run on `default` config mode
            if not util.resolve_packages(self.resources.packages, deps):
                # Exit if a package is not installed
                return 1
        else:
            click.secho('Info: native config mode')

        # -- Execute scons
        terminal_width, _ = click.get_terminal_size()
        start_time = time.time()

        if command == 'build' or \
           command == 'upload' or \
           command == 'time':
            if board:
                processing_board = board
            else:
                processing_board = 'custom board'
            click.echo('[%s] Processing %s' %
                       (datetime.datetime.now().strftime('%c'),
                        click.style(processing_board, fg='cyan', bold=True)))
            click.secho('-' * terminal_width, bold=True)

        if self.profile.get_verbose_mode() > 0:
            click.secho('Executing: scons -Q {0} {1}'.format(
                command, ' '.join(variables)))

        result = util.exec_command(util.scons_command + ['-Q', command] +
                                   variables,
                                   stdout=util.AsyncPipe(self._on_run_out),
                                   stderr=util.AsyncPipe(self._on_run_err))

        # -- Print result
        exit_code = result['returncode']
        is_error = exit_code != 0
        summary_text = ' Took %.2f seconds ' % (time.time() - start_time)
        half_line = '=' * int(((terminal_width - len(summary_text) - 10) / 2))
        click.echo('%s [%s]%s%s' %
                   (half_line,
                    (click.style(' ERROR ', fg='red', bold=True) if is_error
                     else click.style('SUCCESS', fg='green', bold=True)),
                    summary_text, half_line),
                   err=is_error)

        if False:
            if is_error:
                print("""
  ______                     _
 |  ____|                   | |
 | |__   _ __ _ __ ___  _ __| |
 |  __| | '__| '__/ _ \| '__| |
 | |____| |  | | | (_) | |  |_|
 |______|_|  |_|  \___/|_|  (_)
""")
            else:
                print("""
   _____                             _
  / ____|                           | |
 | (___  _   _  ___ ___ ___  ___ ___| |
  \___ \| | | |/ __/ __/ _ \/ __/ __| |
  ____) | |_| | (_| (_|  __/\__ \__ \_|
 |_____/ \__,_|\___\___\___||___/___(_)
""")

        return exit_code