Ejemplo n.º 1
0
Archivo: main.py Proyecto: rgundi/west
def main(argv=None):
    # Makes ANSI color escapes work on Windows, and strips them when
    # stdout/stderr isn't a terminal
    colorama.init()

    if argv is None:
        argv = sys.argv[1:]
    args, unknown = parse_args(argv)

    # Read the configuration files
    config.read_config()

    for_stack_trace = 'run as "west -v ... {} ..." for a stack trace'.format(
        args.command)
    try:
        args.handler(args, unknown)
    except WestUpdated:
        # West has been automatically updated. Restart ourselves to run the
        # latest version, with the same arguments that we were given.
        os.execv(sys.executable, [sys.executable] + sys.argv)
    except KeyboardInterrupt:
        sys.exit(0)
    except CalledProcessError as cpe:
        log.err('command exited with status {}: {}'.format(
            cpe.args[0], quote_sh_list(cpe.args[1])))
        if args.verbose:
            raise
        else:
            log.inf(for_stack_trace)
    except CommandContextError as cce:
        log.die('command', args.command, 'cannot be run in this context:',
                *cce.args)
Ejemplo n.º 2
0
def test_update(clean_west_topdir):
    # Test the 'west update' command. It calls through to the same backend
    # functions that are used for automatic updates and 'west init'
    # reinitialization.

    # Create placeholder local repos
    create_repo('west/manifest')
    create_repo('west/west')

    # Create a simple configuration file. Git requires absolute paths for local
    # repositories.
    clean_west_topdir.join('west/config').write('''
[manifest]
remote = {0}/remote-repos/manifest
revision = master

[west]
remote = {0}/remote-repos/west
revision = master
'''.format(clean_west_topdir))

    config.read_config()

    # Fetch the net-tools repository
    cmd('fetch --no-update net-tools')

    # Add commits to the local repos
    for path in 'west/manifest', 'west/west', NET_TOOLS_PATH:
        add_commit(path, 'local')

    # Check that resetting the manifest repository removes the local commit
    cmd('update --reset-manifest')
    assert head_subject('west/manifest') == 'initial'
    assert head_subject('west/west') == 'local'  # Unaffected
    assert head_subject(NET_TOOLS_PATH) == 'local'  # Unaffected

    # Check that resetting the west repository removes the local commit
    cmd('update --reset-west')
    assert head_subject('west/west') == 'initial'
    assert head_subject(NET_TOOLS_PATH) == 'local'  # Unaffected

    # Check that resetting projects removes the local commit
    cmd('update --reset-projects')
    assert head_subject(NET_TOOLS_PATH) == 'initial'

    # Add commits to the upstream special repos
    for path in 'remote-repos/manifest', 'remote-repos/west':
        add_commit(path, 'upstream')

    # Check that updating the manifest repository gets the upstream commit
    cmd('update --update-manifest')
    assert head_subject('west/manifest') == 'upstream'
    assert head_subject('west/west') == 'initial'  # Unaffected

    # Check that updating the West repository triggers a restart
    with pytest.raises(project.WestUpdated):
        cmd('update --update-west')
Ejemplo n.º 3
0
def config_file_project_setup(tmpdir):
    tmpdir.join('.west/.west_topdir').ensure()
    tmpdir.join('.west/config').write('''
[manifest]
path = manifestproject
''')

    # Switch to the top-level West installation directory
    tmpdir.chdir()

    config.read_config()

    return tmpdir
Ejemplo n.º 4
0
def west_init_tmpdir(repos_tmpdir):
    '''Fixture for a tmpdir with 'remote' repositories and 'west init' run.

    Uses the remote repositories from the repos_tmpdir fixture to
    create a west installation using the system bootstrapper's init
    command -- and thus the test environment must install the
    bootstrapper from the current west source code tree under test.

    The contents of the west installation aren't checked at all.
    This is left up to the test cases.

    The directory that 'west init' created is returned as a
    py.path.local, with the current working directory set there.'''
    west_tmpdir = repos_tmpdir.join('west_installation')
    cmd('init -m "{}" "{}"'.format(str(repos_tmpdir.join('repos', 'zephyr')),
                                   str(west_tmpdir)))
    west_tmpdir.chdir()
    config.read_config()
    return west_tmpdir
Ejemplo n.º 5
0
def main(argv=None):
    # Makes ANSI color escapes work on Windows, and strips them when
    # stdout/stderr isn't a terminal
    colorama.init()

    # Read the configuration files
    config.read_config()

    # Load any external command specs. If the config file isn't
    # fully set up yet, ignore the error. This allows west init to
    # work properly.
    try:
        externals = get_external_commands()
    except MalformedConfig:
        externals = {}

    if argv is None:
        argv = sys.argv[1:]
    args, unknown = parse_args(argv, externals)

    for_stack_trace = 'run as "west -v ... {} ..." for a stack trace'.format(
        args.command)
    try:
        args.handler(args, unknown)
    except WestUpdated:
        # West has been automatically updated. Restart ourselves to run the
        # latest version, with the same arguments that we were given.
        os.execv(sys.executable, [sys.executable] + argv)
    except KeyboardInterrupt:
        sys.exit(0)
    except CalledProcessError as cpe:
        log.err('command exited with status {}: {}'.format(
            cpe.args[0], quote_sh_list(cpe.args[1])))
        if args.verbose:
            raise
        else:
            log.inf(for_stack_trace)
    except CommandContextError as cce:
        log.err('command', args.command, 'cannot be run in this context:',
                *cce.args)
        sys.exit(cce.returncode)
    except CommandError as ce:
        sys.exit(ce.returncode)
Ejemplo n.º 6
0
def test_extension_command_duplicate(repos_tmpdir):
    # Test to ensure that in case to subprojects introduces same command, it
    # will print a warning.
    rr = repos_tmpdir.join('repos')
    remote_kconfiglib = str(rr.join('Kconfiglib'))
    remote_zephyr = str(rr.join('zephyr'))
    remote_west = str(rr.join('west'))

    add_commit(remote_zephyr,
               'test added extension command',
               files={
                   'west.yml':
                   textwrap.dedent('''\
                      west:
                        url: file://{west}
                      manifest:
                        defaults:
                          remote: test-local

                        remotes:
                          - name: test-local
                            url-base: file://{rr}

                        projects:
                          - name: Kconfiglib
                            revision: zephyr
                            path: subdir/Kconfiglib
                            west-commands: scripts/west-commands.yml
                          - name: net-tools
                            west-commands: scripts/west-commands.yml
                        self:
                          path: zephyr
                      '''.format(west=remote_west, rr=str(rr)))
               })

    # Initialize the net-tools repository.
    add_commit(remote_kconfiglib,
               'add west commands',
               files={
                   'scripts/west-commands.yml':
                   textwrap.dedent('''\
                      west-commands:
                        - file: scripts/test.py
                          commands:
                            - name: test
                              class: Test
                      '''),
                   'scripts/test.py':
                   textwrap.dedent('''\
                      from west.commands import WestCommand
                      class Test(WestCommand):
                          def __init__(self):
                              super(Test, self).__init__(
                                  'test',
                                  'test application',
                                  '')
                          def do_add_parser(self, parser_adder):
                              parser = parser_adder.add_parser(self.name)
                              return parser
                          def do_run(self, args, ignored):
                              print('Testing kconfig test command')
                      '''),
               })
    west_tmpdir = repos_tmpdir.join('west_installation')
    cmd('init -m "{}" "{}"'.format(str(repos_tmpdir.join('repos', 'zephyr')),
                                   str(west_tmpdir)))
    west_tmpdir.chdir()
    config.read_config()
    cmd('update')

    actual = cmd('test', stderr=subprocess.STDOUT)
    warning = 'WARNING: ignoring project net-tools external command "test";'\
              ' command "test" already defined as extension command\n'
    command_out = 'Testing kconfig test command\n'

    assert actual == warning + command_out
Ejemplo n.º 7
0
def test_extension_command_multiproject(repos_tmpdir):
    # Test to ensure that multiple projects can define extension commands and
    # that those are correctly presented and executed.
    rr = repos_tmpdir.join('repos')
    remote_kconfiglib = str(rr.join('Kconfiglib'))
    remote_zephyr = str(rr.join('zephyr'))
    remote_west = str(rr.join('west'))

    # Update the manifest to specify extension commands in Kconfiglib.
    add_commit(remote_zephyr,
               'test added extension command',
               files={
                   'west.yml':
                   textwrap.dedent('''\
                      west:
                        url: file://{west}
                      manifest:
                        defaults:
                          remote: test-local

                        remotes:
                          - name: test-local
                            url-base: file://{rr}

                        projects:
                          - name: Kconfiglib
                            revision: zephyr
                            path: subdir/Kconfiglib
                            west-commands: scripts/west-commands.yml
                          - name: net-tools
                            west-commands: scripts/west-commands.yml
                        self:
                          path: zephyr
                      '''.format(west=remote_west, rr=str(rr)))
               })

    # Add an extension command to the Kconfiglib remote.
    add_commit(remote_kconfiglib,
               'add west commands',
               files={
                   'scripts/west-commands.yml':
                   textwrap.dedent('''\
                      west-commands:
                        - file: scripts/test.py
                          commands:
                            - name: kconfigtest
                              class: Test
                      '''),
                   'scripts/test.py':
                   textwrap.dedent('''\
                      from west.commands import WestCommand
                      class Test(WestCommand):
                          def __init__(self):
                              super(Test, self).__init__(
                                  'kconfigtest',
                                  'Kconfig test application',
                                  '')
                          def do_add_parser(self, parser_adder):
                              parser = parser_adder.add_parser(self.name)
                              return parser
                          def do_run(self, args, ignored):
                              print('Testing kconfig test')
                      '''),
               })
    west_tmpdir = repos_tmpdir.join('west_installation')
    cmd('init -m "{}" "{}"'.format(str(repos_tmpdir.join('repos', 'zephyr')),
                                   str(west_tmpdir)))
    west_tmpdir.chdir()
    config.read_config()
    cmd('update')

    help_text = cmd('-h')
    expected = textwrap.dedent('''\
        commands from project at "subdir/Kconfiglib":
          kconfigtest:          (no help provided; try "west kconfigtest -h")

        commands from project at "net-tools":
          test:                 test-help
        ''')

    assert expected in help_text

    actual = cmd('test')
    assert actual == 'Testing test command 1\n'

    actual = cmd('kconfigtest')
    assert actual == 'Testing kconfig test\n'