Beispiel #1
0
    def _run_pristine(self):
        _banner('making build dir {} pristine'.format(self.build_dir))
        if not is_zephyr_build(self.build_dir):
            log.die('Refusing to run pristine on a folder that is not a '
                    'Zephyr build system')

        cache = CMakeCache.from_build_dir(self.build_dir)
        cmake_args = ['-P', cache['ZEPHYR_BASE'] + '/cmake/pristine.cmake']
        run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
Beispiel #2
0
def clean_up(path):
    try:
        run_cmake(['-P', str(path / 'pristine.cmake')],
                  capture_output=True)
    except CalledProcessError:
        # Do our best to clean up even though CMake failed.
        log.wrn(f'Failed to make {path} pristine; '
                'removing known generated files...')
        for subpath in ['CMakeCache.txt', 'CMakeFiles', 'build.ninja',
                        'cmake_install.cmake', 'rules.ninja']:
            remove_if_exists(Path(path) / subpath)
Beispiel #3
0
    def _run_pristine(self):
        _banner('making build dir {} pristine'.format(self.build_dir))

        zb = os.environ.get('ZEPHYR_BASE')
        if not zb:
            log.die('Internal error: ZEPHYR_BASE not set in the environment, '
                    'and should have been by the main script')

        if not is_zephyr_build(self.build_dir):
            log.die('Refusing to run pristine on a folder that is not a '
                    'Zephyr build system')

        cmake_args = ['-P', '{}/cmake/pristine.cmake'.format(zb)]
        run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
Beispiel #4
0
    def _run_cmake(self, board, origin, cmake_opts):
        if board is None and config_getboolean('board_warn', True):
            log.wrn('This looks like a fresh build and BOARD is unknown;',
                    "so it probably won't work. To fix, use",
                    '--board=<your-board>.')
            log.inf('Note: to silence the above message, run',
                    "'west config build.board_warn false'")

        if not self.run_cmake:
            return

        _banner('generating a build system')

        if board is not None and origin != 'CMakeCache.txt':
            cmake_opts = ['-DBOARD={}'.format(board)]
        else:
            cmake_opts = []
        if self.args.cmake_opts:
            cmake_opts.extend(self.args.cmake_opts)

        user_args = config_get('cmake-args', None)
        if user_args:
            cmake_opts.extend(shlex.split(user_args))

        config_sysbuild = config_getboolean('sysbuild', False)
        if self.args.sysbuild or (config_sysbuild
                                  and not self.args.no_sysbuild):
            cmake_opts.extend([
                '-S{}'.format(SYSBUILD_PROJ_DIR),
                '-DAPP_DIR:PATH={}'.format(self.source_dir)
            ])
        else:
            # self.args.no_sysbuild == True or config sysbuild False
            cmake_opts.extend(['-S{}'.format(self.source_dir)])

        # Invoke CMake from the current working directory using the
        # -S and -B options (officially introduced in CMake 3.13.0).
        # This is important because users expect invocations like this
        # to Just Work:
        #
        # west build -- -DOVERLAY_CONFIG=relative-path.conf
        final_cmake_args = [
            '-DWEST_PYTHON={}'.format(sys.executable),
            '-B{}'.format(self.build_dir),
            '-G{}'.format(config_get('generator', DEFAULT_CMAKE_GENERATOR))
        ]
        if cmake_opts:
            final_cmake_args.extend(cmake_opts)
        run_cmake(final_cmake_args, dry_run=self.args.dry_run)
Beispiel #5
0
    def _run_pristine(self):
        _banner('making build dir {} pristine'.format(self.build_dir))
        if not is_zephyr_build(self.build_dir):
            log.die('Refusing to run pristine on a folder that is not a '
                    'Zephyr build system')

        cache = CMakeCache.from_build_dir(self.build_dir)

        app_src_dir = cache.get('APPLICATION_SOURCE_DIR')
        app_bin_dir = cache.get('APPLICATION_BINARY_DIR')

        cmake_args = [f'-DBINARY_DIR={app_bin_dir}',
                      f'-DSOURCE_DIR={app_src_dir}',
                      '-P', cache['ZEPHYR_BASE'] + '/cmake/pristine.cmake']
        run_cmake(cmake_args, cwd=self.build_dir, dry_run=self.args.dry_run)
Beispiel #6
0
    def do_run(self, args, unknown_args):
        cmake_args = ['-P', f'{ZEPHYR_CMAKE}/boards.cmake']
        lines = run_cmake(cmake_args, capture_output=True)
        arch_re = re.compile(r'\s*([\w-]+)\:')
        board_re = re.compile(r'\s*([\w-]+)\s*')
        arch = None
        boards = collections.OrderedDict()
        for line in lines:
            match = arch_re.match(line)
            if match:
                arch = match.group(1)
                boards[arch] = []
                continue
            match = board_re.match(line)
            if match:
                if not arch:
                    log.die(
                        'Invalid board output from CMake: {}'.format(lines))
                board = match.group(1)
                boards[arch].append(board)

        for arch in boards:
            for board in boards[arch]:
                try:
                    result = args.format.format(name=board, arch=arch)
                    print(result)
                except KeyError as e:
                    # The raised KeyError seems to just put the first
                    # invalid argument in the args tuple, regardless of
                    # how many unrecognizable keys there were.
                    log.die('unknown key "{}" in format string "{}"'.format(
                        e.args[0], args.format))
Beispiel #7
0
    def _run_cmake(self, board, origin, cmake_opts):
        _banner('''build configuration:
       source directory: {}
       build directory: {}{}
       BOARD: {}'''.format(
            self.source_dir, self.build_dir,
            ' (created)' if self.created_build_dir else '',
            ('{} (origin: {})'.format(board, origin) if board else 'UNKNOWN')))

        if board is None and config_getboolean('board_warn', True):
            log.wrn('This looks like a fresh build and BOARD is unknown;',
                    "so it probably won't work. To fix, use",
                    '--board=<your-board>.')
            log.inf('Note: to silence the above message, run',
                    "'west config build.board_warn false'")

        if not self.run_cmake:
            log.dbg('Not generating a build system; one is present.')
            return

        _banner('generating a build system')

        if board is not None and origin != 'CMakeCache.txt':
            cmake_opts = ['-DBOARD={}'.format(board)]
        else:
            cmake_opts = []
        if self.args.cmake_opts:
            cmake_opts.extend(self.args.cmake_opts)

        user_args = config_get('cmake-args', None)
        if user_args:
            cmake_opts.extend(shlex.split(user_args))

        # Invoke CMake from the current working directory using the
        # -S and -B options (officially introduced in CMake 3.13.0).
        # This is important because users expect invocations like this
        # to Just Work:
        #
        # west build -- -DOVERLAY_CONFIG=relative-path.conf
        final_cmake_args = [
            '-B{}'.format(self.build_dir), '-S{}'.format(self.source_dir),
            '-G{}'.format(config_get('generator', DEFAULT_CMAKE_GENERATOR))
        ]
        if cmake_opts:
            final_cmake_args.extend(cmake_opts)
        run_cmake(final_cmake_args, dry_run=self.args.dry_run)
Beispiel #8
0
    def _run_cmake(self, cmake_opts):
        if not self.run_cmake:
            log.dbg('not running cmake; build system is present')
            return

        # Invoke CMake from the current working directory using the
        # -S and -B options (officially introduced in CMake 3.13.0).
        # This is important because users expect invocations like this
        # to Just Work:
        #
        # west build -- -DOVERLAY_CONFIG=relative-path.conf
        final_cmake_args = [
            '-B{}'.format(self.build_dir), '-S{}'.format(self.source_dir),
            '-G{}'.format(DEFAULT_CMAKE_GENERATOR)
        ]
        if self.args.board:
            final_cmake_args.append('-DBOARD={}'.format(self.args.board))
        if cmake_opts:
            final_cmake_args.extend(cmake_opts)
        run_cmake(final_cmake_args)
Beispiel #9
0
def run_cmake_export(path):
    # Run a package installation script.
    #
    # Filtering out lines that start with -- ignores the normal
    # CMake status messages and instead only prints the important
    # information.

    lines = run_cmake(['-P', str(path / 'zephyr_export.cmake')],
                      capture_output=True)
    msg = [line for line in lines if not line.startswith('-- ')]
    log.inf('\n'.join(msg))
Beispiel #10
0
    def do_run(self, args, unknown_args):
        zephyr_config_package_path = PurePath(__file__).parents[2] \
            / 'share' / 'zephyr-package' / 'cmake'

        cmake_args = [
            '-S', f'{zephyr_config_package_path}', '-B',
            f'{zephyr_config_package_path}'
        ]
        lines = run_cmake(cmake_args, capture_output=True)

        # Let's clean up, as Zephyr has now been exported, and we no longer
        # need the generated files.
        cmake_args = [
            '--build', f'{zephyr_config_package_path}', '--target', 'pristine'
        ]
        run_cmake(cmake_args, capture_output=True)

        # Let's ignore the normal CMake printing and instead only print
        # the important information.
        msg = [line for line in lines if not line.startswith('-- ')]
        print('\n'.join(msg))
Beispiel #11
0
def run_cmake_and_clean_up(path):
    # Run a package installation script, cleaning up afterwards.
    #
    # Filtering out lines that start with -- ignores the normal
    # CMake status messages and instead only prints the important
    # information.

    try:
        lines = run_cmake(['-S', str(path), '-B', str(path)],
                          capture_output=True)
    finally:
        msg = [line for line in lines if not line.startswith('-- ')]
        log.inf('\n'.join(msg))
        clean_up(path)
Beispiel #12
0
    def do_run(self, args, unknown_args):
        zb = os.environ.get('ZEPHYR_BASE')
        if not zb:
            log.die('Internal error: ZEPHYR_BASE not set in the environment, '
                    'and should have been by the main script')

        cmake_args = [
            '-DBOARD_ROOT_SPACE_SEPARATED={}'.format(zb), '-P',
            '{}/cmake/boards.cmake'.format(zb)
        ]
        lines = run_cmake(cmake_args, capture_output=True)
        arch_re = re.compile(r'\s*([\w-]+)\:')
        board_re = re.compile(r'\s*([\w-]+)\s*')
        arch = None
        boards = collections.OrderedDict()
        for line in lines:
            match = arch_re.match(line)
            if match:
                arch = match.group(1)
                boards[arch] = []
                continue
            match = board_re.match(line)
            if match:
                if not arch:
                    log.die(
                        'Invalid board output from CMake: {}'.format(lines))
                board = match.group(1)
                boards[arch].append(board)

        for arch in boards:
            for board in boards[arch]:
                try:
                    result = args.format.format(name=board, arch=arch)
                    print(result)
                except KeyError as e:
                    # The raised KeyError seems to just put the first
                    # invalid argument in the args tuple, regardless of
                    # how many unrecognizable keys there were.
                    log.die('unknown key "{}" in format string "{}"'.format(
                        e.args[0], args.format))