Пример #1
0
def install_arduino_toolchain(bii):
    '''Arduino Toolchain uses AVR-GCC & AVR-G++ compilers
    '''
    hive_disk_image = bii.hive_disk_image
    user_io = bii.user_io
    paths = hive_disk_image.paths
    arduino_cmake = load_resource(DEV_ARDUINO_DIR, "cmake/Arduino.cmake")
    bii_ard_path = os.path.join(paths.bii, "Platform/Arduino.cmake")
    save_blob_if_modified(bii_ard_path, Blob(arduino_cmake))

    toolchain = load_resource(DEV_ARDUINO_DIR, "cmake/arduino_toolchain.cmake")
    bii_ard_path = os.path.join(paths.bii, "arduino_toolchain.cmake")

    arduino_sdk_path = hive_disk_image.settings.arduino.sdk
    toolchain += 'SET(ARDUINO_SDK_PATH "%s")\n' % arduino_sdk_path

    SDK_PATH_LIBRARIES = '''SET(SDK_PATH_LIBS "{{libs_dir}}")
        SET(ALL_LIBS_DIR    {% for name in libs_names %}
                            ${SDK_PATH_LIBS}/{{name}}/src
                            ${SDK_PATH_LIBS}/{{name}}
                            {% endfor %})
        INCLUDE_DIRECTORIES(${ALL_LIBS_DIR})
        '''

    SDK_PATH_AVR_LIBS = '''
    SET(SDK_AVR_PATH_LIBS "{{libs_dir}}")
    SET(ALL_LIBS_DIR    {% for name in libs_names %}
                        ${SDK_AVR_PATH_LIBS}/{{name}}/src
                        ${SDK_AVR_PATH_LIBS}/{{name}}
                        {% endfor %})
    INCLUDE_DIRECTORIES(${ALL_LIBS_DIR})
        '''

    libraries_info, libs_recurse_names = _get_libraries_folders(user_io, hive_disk_image)
    libraries_path, list_libraries = libraries_info['common']
    include_libraries_path = Template(SDK_PATH_LIBRARIES).render(libs_dir=libraries_path,
                                                                 libs_names=list_libraries)
    avr_libs_info = libraries_info.get('avr')
    if avr_libs_info:
        libs_path, list_libraries = avr_libs_info
        include_libraries_path += Template(SDK_PATH_AVR_LIBS).render(libs_dir=libs_path,
                                                                     libs_names=list_libraries)

    toolchain += include_libraries_path
    settings = hive_disk_image.settings.arduino
    boards_settings = cmake_board_settings(settings.sdk, settings.version)
    # Problems with encoding of 1.5.8, yun with accent
    boards_settings = boards_settings.decode("utf-8").encode("ascii", "ignore")
    toolchain += boards_settings

    set_lib_recurses = ["set(%s_RECURSE True)" % lib for lib in libs_recurse_names]
    toolchain += "\n".join(set_lib_recurses)
    modified = save_blob_if_modified(bii_ard_path, Blob(toolchain))
    if modified:
        user_io.out.warn("Arduino toolchain defined, regenerating project")
        hive_disk_image.delete_build_folder()

    user_io.out.write('Creating toolchain for Arduino\n', Color.BRIGHT_BLUE)
    user_io.out.success('Run "bii configure -t arduino" to activate it')
    user_io.out.success('Run "bii configure -t" to disable it')
Пример #2
0
 def _copy_data(self, block_targets, resources):
     """ Data dependencies are copied to the BIN folder of the project, with the
     same relative block_name path
     """
     for block_target in block_targets.itervalues():
         for data in block_target.data:
             r = resources[data]
             datapath = os.path.join(self.client_hive_manager.paths.bin, data)
             save_blob_if_modified(datapath, r.content.load)
Пример #3
0
 def _copy_data(self, block_targets, resources):
     """ Data dependencies are copied to the BIN folder of the project, with the
     same relative block_name path
     """
     for block_target in block_targets.itervalues():
         for data in block_target.data:
             r = resources[data]
             datapath = os.path.join(self.client_hive_manager.paths.bin, data)
             save_blob_if_modified(datapath, r.content.load)
Пример #4
0
    def settings(self, *parameters):
        '''Configure Raspberry Pi project settings'''
        parser = argparse.ArgumentParser(description=self.settings.__doc__,
                                         prog="bii %s:settings" % self.group)
        parser.add_argument('--user', help='Your RPi user session, e.g.: pi')
        parser.add_argument("--ip", help="Your RPi IP, e.g.: 50.1.2.3")
        parser.add_argument(
            "--directory",
            help="Directory where you'll send the binary files, e.g.: bin")
        args = parser.parse_args(*parameters)  # for -h

        settings = self.hive_disk_image.settings
        if any([args.user, args.ip, args.directory]):
            rpi_settings_args(args, settings)
        else:
            rpi_settings_wizard(self.user_io, settings)

        #Write to disk
        self.hive_disk_image.settings = settings
        self.user_io.out.info('Settings saved in:  %s' % self.paths.settings)

        toolchain_rpi_path = os.path.join(self.paths.bii,
                                          "rpi_toolchain.cmake")
        if not os.path.exists(toolchain_rpi_path):
            if OSInfo.is_linux():
                self.user_io.out.write('Creating toolchain for Raspberry PI\n',
                                       Color.BLUE)
                c_path, cpp_path = find_gnu_arm()
                if not c_path or not cpp_path:
                    self.user_io.out.error(
                        "Unable to find RPI cross-compilers.\n"
                        "Try executing bii setup:rpi")

                content = []
                content.append("INCLUDE(CMakeForceCompiler)")
                content.append("SET(CMAKE_SYSTEM_NAME Linux)")
                content.append("SET(CMAKE_SYSTEM_VERSION 1)")
                content.append("SET(CMAKE_C_COMPILER %s)" % c_path)
                content.append("SET(CMAKE_CXX_COMPILER %s)" % cpp_path)
                content = os.linesep.join(content)
                save_blob_if_modified(toolchain_rpi_path, Blob(content))

                self.user_io.out.success(
                    'Run "bii configure -t rpi" to activate it')
                self.user_io.out.success(
                    'Run "bii configure -t" to disable it')
            else:
                self.user_io.out.error(
                    "Toolchain for R-Pi only available in Linux now")
                self.user_io.out.error(
                    "You can try to define your own bii/rpi_toolchain.cmake")
Пример #5
0
 def _create_vars_cmake_files(self, block_targets):
     b = False
     for block_target in block_targets.itervalues():
         bii_vars_path = os.path.join(self.bii_paths.cmake,
                                      block_target.filename)
         modified = save_blob_if_modified(bii_vars_path,
                                          Blob(block_target.dumps()))
         b = b or modified
     return b
Пример #6
0
    def settings(self, *parameters):
        '''Configure Raspberry Pi project settings'''
        parser = argparse.ArgumentParser(description=self.settings.__doc__,
                                         prog="bii %s:settings" % self.group)
        parser.add_argument('--user', help='Your RPi user session, e.g.: pi')
        parser.add_argument("--ip", help="Your RPi IP, e.g.: 50.1.2.3")
        parser.add_argument("--directory", help="Directory where you'll send the binary files, e.g.: bin")
        args = parser.parse_args(*parameters)  # for -h

        settings = self.hive_disk_image.settings
        if any([args.user, args.ip, args.directory]):
            rpi_settings_args(args, settings)
        else:
            rpi_settings_wizard(self.user_io, settings)

        #Write to disk
        self.hive_disk_image.settings = settings
        self.user_io.out.info('Settings saved in:  %s' % self.paths.settings)

        toolchain_rpi_path = os.path.join(self.paths.bii, "rpi_toolchain.cmake")
        if not os.path.exists(toolchain_rpi_path):
            if OSInfo.is_linux():
                self.user_io.out.write('Creating toolchain for Raspberry PI\n', Color.BLUE)
                c_path, cpp_path = find_gnu_arm()
                if not c_path or not cpp_path:
                    self.user_io.out.error("Unable to find RPI cross-compilers.\n"
                                           "Try executing bii setup:rpi")

                content = []
                content.append("INCLUDE(CMakeForceCompiler)")
                content.append("SET(CMAKE_SYSTEM_NAME Linux)")
                content.append("SET(CMAKE_SYSTEM_VERSION 1)")
                content.append("SET(CMAKE_C_COMPILER %s)" % c_path)
                content.append("SET(CMAKE_CXX_COMPILER %s)" % cpp_path)
                content = os.linesep.join(content)
                save_blob_if_modified(toolchain_rpi_path, Blob(content))

                self.user_io.out.success('Run "bii configure -t rpi" to activate it')
                self.user_io.out.success('Run "bii configure -t" to disable it')
            else:
                self.user_io.out.error("Toolchain for R-Pi only available in Linux now")
                self.user_io.out.error("You can try to define your own bii/rpi_toolchain.cmake")
Пример #7
0
def regenerate_arduino_settings_cmake(bii):
    '''
    Regenerate arduino_settings.cmake from current settings
    '''
    hive_disk_image = bii.hive_disk_image
    current_settings = hive_disk_image.settings

    # Now process settings
    arduino_settings_cmake = load_resource(DEV_ARDUINO_DIR, "cmake/arduino_settings.cmake")

    ard_settings = current_settings.arduino
    board = board_mapping.get(ard_settings.board, ard_settings.board)
    arduino_settings_cmake = arduino_settings_cmake.format(board=board,
                                                           port=ard_settings.port,
                                                           programmer=ard_settings.programmer
                                                           or "usbtinyisp",
                                                           serial="")
    settings_path = os.path.join(hive_disk_image.paths.bii,
                                 "arduino_settings.cmake")
    save_blob_if_modified(settings_path, Blob(arduino_settings_cmake))
Пример #8
0
    def _create_cmakelists(self, block_targets):
        '''creates 3 files:
        CMakeLists.txt, only if not existing, including the other two files
        bii_targets.cmake, the file containing the ADD_LIBRARY and ADD_EXECUTABLES, with the
                        configuration of flags per target and files
        bii_vars.cmake, is a file with variables declarations that are afterwards used in
                        bii_targets.cmake'''
        cmakelists_path = os.path.join(self.bii_paths.cmake, "CMakeLists.txt")
        bii_macros_path = os.path.join(self.bii_paths.cmake, 'biicode.cmake')
        bii_macros_content = load_resource(DEV_CPP_DIR, "cmake/biicode.cmake")

        self._create_default_blocks_cmakelists(block_targets)
        # following is a virtual call, may call child class method
        cmakelists_content = self._get_project_cmakelists(block_targets)

        a = save_blob_if_modified(cmakelists_path, Blob(cmakelists_content))
        b = self._create_vars_cmake_files(block_targets)
        c = save_blob_if_modified(bii_macros_path, Blob(bii_macros_content))

        return a or b or c
Пример #9
0
def regenerate_arduino_settings_cmake(bii):
    '''
    Regenerate arduino_settings.cmake from current settings
    '''
    hive_disk_image = bii.hive_disk_image
    current_settings = hive_disk_image.settings

    # Now process settings
    arduino_settings_cmake = load_resource(DEV_ARDUINO_DIR,
                                           "cmake/arduino_settings.cmake")

    ard_settings = current_settings.arduino
    board = board_mapping.get(ard_settings.board, ard_settings.board)
    arduino_settings_cmake = arduino_settings_cmake.format(
        board=board,
        port=ard_settings.port,
        programmer=ard_settings.programmer or "usbtinyisp",
        serial="")
    settings_path = os.path.join(hive_disk_image.paths.bii,
                                 "arduino_settings.cmake")
    save_blob_if_modified(settings_path, Blob(arduino_settings_cmake))
Пример #10
0
def install_arduino_toolchain(bii):
    '''Arduino Toolchain uses AVR-GCC & AVR-G++ compilers
    '''
    hive_disk_image = bii.hive_disk_image
    user_io = bii.user_io
    paths = hive_disk_image.paths
    arduino_cmake = load_resource(DEV_ARDUINO_DIR, "cmake/Arduino.cmake")
    bii_ard_path = os.path.join(paths.bii, "Platform/Arduino.cmake")
    save_blob_if_modified(bii_ard_path, Blob(arduino_cmake))

    toolchain = load_resource(DEV_ARDUINO_DIR, "cmake/arduino_toolchain.cmake")
    bii_ard_path = os.path.join(paths.bii, "arduino_toolchain.cmake")

    arduino_sdk_path = hive_disk_image.settings.arduino.sdk
    toolchain += 'SET(ARDUINO_SDK_PATH "%s")\n' % arduino_sdk_path

    SDK_PATH_LIBRARIES = '''SET(SDK_PATH_LIBS "{{libs_dir}}")
        SET(ALL_LIBS_DIR    {% for name in libs_names %}
                            ${SDK_PATH_LIBS}/{{name}}/src
                            ${SDK_PATH_LIBS}/{{name}}
                            {% endfor %})
        INCLUDE_DIRECTORIES(${ALL_LIBS_DIR})
        '''

    SDK_PATH_AVR_LIBS = '''
    SET(SDK_AVR_PATH_LIBS "{{libs_dir}}")
    SET(ALL_LIBS_DIR    {% for name in libs_names %}
                        ${SDK_AVR_PATH_LIBS}/{{name}}/src
                        ${SDK_AVR_PATH_LIBS}/{{name}}
                        {% endfor %})
    INCLUDE_DIRECTORIES(${ALL_LIBS_DIR})
        '''

    libraries_info, libs_recurse_names = _get_libraries_folders(
        user_io, hive_disk_image)
    libraries_path, list_libraries = libraries_info['common']
    include_libraries_path = Template(SDK_PATH_LIBRARIES).render(
        libs_dir=libraries_path, libs_names=list_libraries)
    avr_libs_info = libraries_info.get('avr')
    if avr_libs_info:
        libs_path, list_libraries = avr_libs_info
        include_libraries_path += Template(SDK_PATH_AVR_LIBS).render(
            libs_dir=libs_path, libs_names=list_libraries)

    toolchain += include_libraries_path
    settings = hive_disk_image.settings.arduino
    boards_settings = cmake_board_settings(settings.sdk, settings.version)
    # Problems with encoding of 1.5.8, yun with accent
    boards_settings = boards_settings.decode("utf-8").encode("ascii", "ignore")
    toolchain += boards_settings

    set_lib_recurses = [
        "set(%s_RECURSE True)" % lib for lib in libs_recurse_names
    ]
    toolchain += "\n".join(set_lib_recurses)
    modified = save_blob_if_modified(bii_ard_path, Blob(toolchain))
    if modified:
        user_io.out.warn("Arduino toolchain defined, regenerating project")
        hive_disk_image.delete_build_folder()

    user_io.out.write('Creating toolchain for Arduino\n', Color.BRIGHT_BLUE)
    user_io.out.success('Run "bii configure -t arduino" to activate it')
    user_io.out.success('Run "bii configure -t" to disable it')