コード例 #1
0
ファイル: cmaketool.py プロジェクト: MordodeMaru/client
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
ファイル: runners_tools.py プロジェクト: MordodeMaru/client
def create_noderunner(project_path, blocks_folder, deps_folder):
    if platform.system() == 'Windows':
        runner = "noderunner.bat"
    else:
        runner = "noderunner.sh"
    runners_template = load_resource(DEV_NODE_DIR, os.path.join("runners", runner))
    runner_path = os.path.join(project_path, runner)
    runner_content = runners_template.format(blocks_path=blocks_folder, deps_path=deps_folder)
    save(runner_path, runner_content)
    os.chmod(runner_path, stat.S_IRWXU)
コード例 #3
0
ファイル: runners_tools.py プロジェクト: toeb/client
def create_noderunner(project_path, blocks_folder, deps_folder):
    if platform.system() == 'Windows':
        runner = "noderunner.bat"
    else:
        runner = "noderunner.sh"
    runners_template = load_resource(DEV_NODE_DIR,
                                     os.path.join("runners", runner))
    runner_path = os.path.join(project_path, runner)
    runner_content = runners_template.format(blocks_path=blocks_folder,
                                             deps_path=deps_folder)
    save(runner_path, runner_content)
    os.chmod(runner_path, stat.S_IRWXU)
コード例 #4
0
ファイル: cmaketool.py プロジェクト: MordodeMaru/client
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))
コード例 #5
0
ファイル: cmaketool.py プロジェクト: toeb/client
    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
コード例 #6
0
ファイル: cmaketool.py プロジェクト: toeb/client
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))
コード例 #7
0
ファイル: cmaketool.py プロジェクト: toeb/client
    def _get_project_cmakelists(self, block_targets):
        cmakelists_template = load_resource(DEV_CPP_DIR,
                                            "cmake/CMakeLists.txt")

        blocks_include = []
        blocks_prebuild_step = []

        root_block = self.bii_paths.root_block
        CMAKELISTS_INCLUDES = "BII_INCLUDE_BLOCK({path_block_name})"
        CMAKELISTS_PREBUILD = "BII_PREBUILD_STEP({path_block_name})"
        for block_name, block_target in block_targets.iteritems():
            if block_target.is_dep:
                rel_block_path = self.bii_paths.deps_relative
            else:
                rel_block_path = self.bii_paths.blocks_relative
            if block_name == root_block:
                block_path = root_block
            else:
                block_path = os.path.join(rel_block_path,
                                          block_target.block_name).replace(
                                              '\\', '/')
            blocks_include.append(
                CMAKELISTS_INCLUDES.format(path_block_name=block_path))
            blocks_prebuild_step.append(
                CMAKELISTS_PREBUILD.format(path_block_name=block_path))

        biicode_env_dir = self.bii_paths.user_bii_home.replace('\\', '/')
        return cmakelists_template.format(
            project_name=self.bii_paths.project_name,
            prebuild_steps="\n".join(blocks_prebuild_step),
            include_blocks="\n".join(blocks_include),
            biicode_env_dir=biicode_env_dir,
            blocks=self.bii_paths.blocks_relative,
            deps=self.bii_paths.deps_relative,
            cmake=self.bii_paths.cmake_relative,
            bin=self.bii_paths.bin_relative,
            lib=self.bii_paths.lib_relative,
            project_root=self.bii_paths.project_root.replace('\\', '/'))
コード例 #8
0
ファイル: cmaketool.py プロジェクト: toeb/client
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')