Exemplo n.º 1
0
def glob(dirname, *patterns, **kwargs):
    recursive = kwargs.get('recursive', True)
    subdir = kwargs.get('subdir', '')

    result = SpaceList()
    scan_dir = os.path.join(dirname, subdir)
    if not os.path.isdir(scan_dir):
        return result

    for entry in os.listdir(scan_dir):
        path = os.path.join(scan_dir, entry)
        if os.path.isdir(path) and recursive:
            subglob = glob(dirname, *patterns, recursive=True,
                           subdir=os.path.join(subdir, entry))
            result.extend(subglob)
        elif os.path.isfile(path) and any(fnmatch.fnmatch(entry, p) for p in patterns):
            result.append(GlobFile(os.path.join(subdir, entry), dirname))

    return result
Exemplo n.º 2
0
 def recursive_inc_lib_flags(self, libdirs):
     flags = SpaceList()
     for d in libdirs:
         flags.append('-I' + d)
         flags.extend('-I' + subd for subd in list_subdirs(
             d, recursive=True, exclude=['examples', 'extras']))
     return flags
Exemplo n.º 3
0
    def setup_flags(self, args):
        board = self.e.board_model(args.board_model)
        boardVariant = args.cpu if ('cpu' in args) else None

        mcu = '-mmcu=' + BoardModels.getValueForVariant(
            board, boardVariant, 'build', 'mcu')
        # Hard-code the flags that are essential to building the sketch
        self.e['cppflags'] = SpaceList([
            mcu,
            '-DF_CPU=' + BoardModels.getValueForVariant(
                board, boardVariant, 'build', 'f_cpu'),
            '-DARDUINO=' + str(self.e.arduino_lib_version.as_int()),
            '-DARDUINO_ARCH_' + args.arch.upper(),
            '-I' + self.e['arduino_core_dir'],
        ])
        # Add additional flags as specified
        self.e['cppflags'] += SpaceList(shlex.split(args.cppflags))

        try:
            self.e['cppflags'].append('-DUSB_VID=%s' %
                                      BoardModels.getValueForVariant(
                                          board, boardVariant, 'build', 'vid'))
        except KeyError:
            None
        try:
            self.e['cppflags'].append('-DUSB_PID=%s' %
                                      BoardModels.getValueForVariant(
                                          board, boardVariant, 'build', 'pid'))
        except KeyError:
            None

        if self.e.arduino_lib_version.major:
            variant_dir = os.path.join(self.e.arduino_variants_dir,
                                       board['build']['variant'])
            self.e.cppflags.append('-I' + variant_dir)

        self.e['cflags'] = SpaceList(shlex.split(args.cflags))
        self.e['cxxflags'] = SpaceList(shlex.split(args.cxxflags))
        self.e['asmflags'] = SpaceList(shlex.split(args.asmflags))

        # Again, hard-code the flags that are essential to building the sketch
        self.e['ldflags'] = SpaceList([mcu])
        self.e['ldflags'] += SpaceList(
            ['-Wl,' + flag for flag in shlex.split(args.ldflags)])

        self.e['names'] = {
            'obj': '%s.o',
            'lib': 'lib%s.a',
            'cpp': '%s.cpp',
            'asm': '%s.S',
            'deps': '%s.d',
        }
Exemplo n.º 4
0
    def scan_dependencies(self):
        self.e['deps'] = SpaceList()

        lib_dirs = [self.e.arduino_core_dir] + \
            list_subdirs(self.e.lib_dir) + \
            list_subdirs(self.e.arduino_libraries_dir) + \
            list_subdirs(self.e.arduino_core_libraries_dir) + \
            list_subdirs(self.e.arduino_user_libraries_dir)
        inc_flags = self.recursive_inc_lib_flags(lib_dirs)

        # If lib A depends on lib B it have to appear before B in final
        # list so that linker could link all together correctly
        # but order of `_scan_dependencies` is not defined, so...

        # 1. Get dependencies of sources in arbitrary order
        used_libs = list(
            self._scan_dependencies(self.e.src_dir, lib_dirs, inc_flags))

        # 2. Get dependencies of dependency libs themselves: existing dependencies
        # are moved to the end of list maintaining order, new dependencies are appended
        scanned_libs = set()
        while scanned_libs != set(used_libs):
            for lib in set(used_libs) - scanned_libs:
                dep_libs = self._scan_dependencies(lib, lib_dirs, inc_flags)

                i = 0
                for ulib in used_libs[:]:
                    if ulib in dep_libs:
                        # dependency lib used already, move it to the tail
                        used_libs.append(used_libs.pop(i))
                        dep_libs.remove(ulib)
                    else:
                        i += 1

                # append new dependencies to the tail
                used_libs.extend(dep_libs)
                scanned_libs.add(lib)

        self.e['used_libs'] = used_libs
        self.e['cppflags'].extend(self.recursive_inc_lib_flags(used_libs))
Exemplo n.º 5
0
def glob(dirname, *patterns, **kwargs):
    recursive = kwargs.get('recursive', True)
    subdir = kwargs.get('subdir', '')

    result = SpaceList()
    scan_dir = os.path.join(dirname, subdir)
    if not os.path.isdir(scan_dir):
        return result

    for entry in os.listdir(scan_dir):
        path = os.path.join(scan_dir, entry)
        if os.path.isdir(path) and recursive:
            subglob = glob(dirname, *patterns, recursive=True,
                           subdir=os.path.join(subdir, entry))
            result.extend(subglob)
        elif os.path.isfile(path) and any(fnmatch.fnmatch(entry, p) for p in patterns):
            result.append(GlobFile(os.path.join(subdir, entry), dirname))

    return result
Exemplo n.º 6
0
    def setup_flags(self, args):
        board = self.e.board_model(args.board_model)
        mcu = '-mmcu=' + board['build']['mcu']
        # Hard-code the flags that are essential to building the sketch
        self.e['cppflags'] = SpaceList([
            mcu,
            '-DF_CPU=' + board['build']['f_cpu'],
            '-DARDUINO=' + str(self.e.arduino_lib_version.as_int()),
            '-I' + self.e['arduino_core_dir'],
        ])
        # Add additional flags as specified
        self.e['cppflags'] += SpaceList(shlex.split(args.cppflags))

        if 'vid' in board['build']:
            self.e['cppflags'].append('-DUSB_VID=%s' % board['build']['vid'])
        if 'pid' in board['build']:
            self.e['cppflags'].append('-DUSB_PID=%s' % board['build']['pid'])

        if self.e.arduino_lib_version.major:
            variant_dir = os.path.join(self.e.arduino_variants_dir,
                                       board['build']['variant'])
            self.e.cppflags.append('-I' + variant_dir)

        self.e['cflags'] = SpaceList(shlex.split(args.cflags))
        self.e['cxxflags'] = SpaceList(shlex.split(args.cxxflags))

        # Again, hard-code the flags that are essential to building the sketch
        self.e['ldflags'] = SpaceList([mcu])
        self.e['ldflags'] += SpaceList(
            ['-Wl,' + flag for flag in shlex.split(args.ldflags)])

        self.e['names'] = {
            'obj': '%s.o',
            'lib': 'lib%s.a',
            'cpp': '%s.cpp',
            'deps': '%s.d',
        }
Exemplo n.º 7
0
 def recursive_inc_lib_flags(self, libdirs):
     flags = SpaceList()
     for d in libdirs:
         flags.append('-I' + d)
         flags.extend('-I' + subd for subd in list_subdirs(d, recursive=True, exclude=['examples', 'extras']))
     return flags