Пример #1
0
def execCommand(args, following_args):
    # standard library modules
    import logging

    # validate, , validate things, internal
    from yotta.lib import validate
    # ordered_json, , order-preserving json handling, internal
    from yotta.lib import ordered_json
    # fsutils, , filesystem utils, internal
    from yotta.lib.fsutils import rmF
    # list, , the yotta list subcommand, internal
    from yotta import list as yotta_list

    # first remove any existing shrinkwrap:
    rmF('yotta-shrinkwrap.json')

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    if not args.target:
        logging.error('No target has been set, use "yotta target" to set one.')
        return 1

    target, errors = c.satisfyTarget(args.target)
    if errors:
        for error in errors:
            logging.error(error)
        return 1

    installed_modules = c.getDependenciesRecursive(target=target,
                                                   available_components=[
                                                       (c.getName(), c)
                                                   ],
                                                   test='toplevel')

    dependency_list = yotta_list.resolveDependencyGraph(target,
                                                        c,
                                                        installed_modules,
                                                        test='toplevel')

    errors = checkDependenciesForShrinkwrap(dependency_list)
    if len(errors):
        logging.error("Dependency errors prevent shrinkwrap creation:")
        for error in errors:
            logging.error(error)
        logging.error("Perhaps you need to `yotta install` first?")
        return 1

    with open('yotta-shrinkwrap.json', 'w') as f:
        f.write(
            ordered_json.dumps(
                prepareShrinkwarp(dependency_list, target.hierarchy)))
Пример #2
0
def execCommand(args, following_args):
    # standard library modules
    import logging

    # validate, , validate things, internal
    from yotta.lib import validate
    # ordered_json, , order-preserving json handling, internal
    from yotta.lib import ordered_json
    # fsutils, , filesystem utils, internal
    from yotta.lib.fsutils import rmF
    # list, , the yotta list subcommand, internal
    from yotta import list as yotta_list

    # first remove any existing shrinkwrap:
    rmF('yotta-shrinkwrap.json')

    c = validate.currentDirectoryModule()
    if not c:
        return 1
    if not args.target:
        logging.error('No target has been set, use "yotta target" to set one.')
        return 1

    target, errors = c.satisfyTarget(args.target)
    if errors:
        for error in errors:
            logging.error(error)
        return 1

    installed_modules = c.getDependenciesRecursive(
                      target = target,
        available_components = [(c.getName(), c)],
                        test = 'toplevel'
    )

    dependency_list = yotta_list.resolveDependencyGraph(target, c, installed_modules, test='toplevel')

    errors = checkDependenciesForShrinkwrap(dependency_list)
    if len(errors):
        logging.error("Dependency errors prevent shrinkwrap creation:")
        for error in errors:
            logging.error(error)
        logging.error("Perhaps you need to `yotta install` first?")
        return 1

    with open('yotta-shrinkwrap.json', 'w') as f:
        f.write(ordered_json.dumps(prepareShrinkwarp(dependency_list, target.hierarchy)))
Пример #3
0
    def getConfigData(self, all_dependencies, component, builddir, build_info_header_path):
        ''' returns (path_to_config_header, cmake_set_definitions) '''
        # ordered_json, , read/write ordered json, internal
        from yotta.lib import ordered_json
        add_defs_header = ''
        set_definitions = ''
        # !!! backwards-compatible "TARGET_LIKE" definitions for the top-level
        # of the config. NB: THESE WILL GO AWAY
        definitions = []
        definitions.append(('TARGET', sanitizePreprocessorSymbol(self.target.getName())))
        definitions.append(('TARGET_LIKE_%s' % sanitizePreprocessorSymbol(self.target.getName()),None))

        # make the path to the build-info header available both to CMake and
        # in the preprocessor:
        full_build_info_header_path = replaceBackslashes(os.path.abspath(build_info_header_path))
        logger.debug('build info header include path: "%s"', full_build_info_header_path)
        definitions.append(('YOTTA_BUILD_INFO_HEADER', '"'+full_build_info_header_path+'"'))

        for target in self.target.getSimilarTo_Deprecated():
            if '*' not in target:
                definitions.append(('TARGET_LIKE_%s' % sanitizePreprocessorSymbol(target),None))

        merged_config = self.target.getMergedConfig()
        logger.debug('target configuration data: %s', merged_config)
        definitions += self._definitionsForConfig(merged_config, ['YOTTA', 'CFG'])

        add_defs_header += '// yotta config data (including backwards-compatible definitions)\n'

        for k, v in definitions:
            if v is not None:
                add_defs_header += '#define %s %s\n' % (k, v)
                set_definitions += 'set(%s %s)\n' % (k, v)
            else:
                add_defs_header += '#define %s\n' % k
                set_definitions += 'set(%s TRUE)\n' % k

        add_defs_header += '\n// version definitions\n'

        for dep in list(all_dependencies.values()) + [component]:
            add_defs_header += "#define YOTTA_%s_VERSION_STRING \"%s\"\n" % (sanitizePreprocessorSymbol(dep.getName()), str(dep.getVersion()))
            add_defs_header += "#define YOTTA_%s_VERSION_MAJOR %d\n" % (sanitizePreprocessorSymbol(dep.getName()), dep.getVersion().major())
            add_defs_header += "#define YOTTA_%s_VERSION_MINOR %d\n" % (sanitizePreprocessorSymbol(dep.getName()), dep.getVersion().minor())
            add_defs_header += "#define YOTTA_%s_VERSION_PATCH %d\n" % (sanitizePreprocessorSymbol(dep.getName()), dep.getVersion().patch())

        # use -include <definitions header> instead of lots of separate
        # defines... this is compiler specific, but currently testing it
        # out for gcc-compatible compilers only:
        config_include_file = os.path.join(builddir, 'yotta_config.h')
        config_json_file    = os.path.join(builddir, 'yotta_config.json')
        set_definitions += 'set(YOTTA_CONFIG_MERGED_JSON_FILE \"%s\")\n' % replaceBackslashes(os.path.abspath(config_json_file))

        self._writeFile(
            config_include_file,
            '#ifndef __YOTTA_CONFIG_H__\n'+
            '#define __YOTTA_CONFIG_H__\n'+
            add_defs_header+
            '#endif // ndef __YOTTA_CONFIG_H__\n'
        )
        self._writeFile(
            config_json_file,
            ordered_json.dumps(merged_config)
        )
        return (config_include_file, set_definitions)
Пример #4
0
def formatDependencyGraphAsJSON(dep_graph):
    from yotta.lib import ordered_json

    return ordered_json.dumps(dep_graph)
Пример #5
0
    def getConfigData(self, all_dependencies, component, builddir,
                      build_info_header_path):
        ''' returns (path_to_config_header, cmake_set_definitions) '''
        # ordered_json, , read/write ordered json, internal
        from yotta.lib import ordered_json
        add_defs_header = ''
        set_definitions = ''
        # !!! backwards-compatible "TARGET_LIKE" definitions for the top-level
        # of the config. NB: THESE WILL GO AWAY
        definitions = []
        definitions.append(
            ('TARGET', sanitizePreprocessorSymbol(self.target.getName())))
        definitions.append(
            ('TARGET_LIKE_%s' %
             sanitizePreprocessorSymbol(self.target.getName()), None))

        # make the path to the build-info header available both to CMake and
        # in the preprocessor:
        full_build_info_header_path = replaceBackslashes(
            os.path.abspath(build_info_header_path))
        logger.debug('build info header include path: "%s"',
                     full_build_info_header_path)
        definitions.append(('YOTTA_BUILD_INFO_HEADER',
                            '"' + full_build_info_header_path + '"'))

        for target in self.target.getSimilarTo_Deprecated():
            if '*' not in target:
                definitions.append(
                    ('TARGET_LIKE_%s' % sanitizePreprocessorSymbol(target),
                     None))

        merged_config = self.target.getMergedConfig()
        logger.debug('target configuration data: %s', merged_config)
        definitions += self._definitionsForConfig(merged_config,
                                                  ['YOTTA', 'CFG'])

        add_defs_header += '// yotta config data (including backwards-compatible definitions)\n'

        for k, v in definitions:
            if v is not None:
                add_defs_header += '#define %s %s\n' % (k, v)
                set_definitions += 'set(%s %s)\n' % (k, v)
            else:
                add_defs_header += '#define %s\n' % k
                set_definitions += 'set(%s TRUE)\n' % k

        add_defs_header += '\n// version definitions\n'

        for dep in list(all_dependencies.values()) + [component]:
            add_defs_header += "#define YOTTA_%s_VERSION_STRING \"%s\"\n" % (
                sanitizePreprocessorSymbol(dep.getName()), str(
                    dep.getVersion()))
            add_defs_header += "#define YOTTA_%s_VERSION_MAJOR %d\n" % (
                sanitizePreprocessorSymbol(
                    dep.getName()), dep.getVersion().major())
            add_defs_header += "#define YOTTA_%s_VERSION_MINOR %d\n" % (
                sanitizePreprocessorSymbol(
                    dep.getName()), dep.getVersion().minor())
            add_defs_header += "#define YOTTA_%s_VERSION_PATCH %d\n" % (
                sanitizePreprocessorSymbol(
                    dep.getName()), dep.getVersion().patch())

        # use -include <definitions header> instead of lots of separate
        # defines... this is compiler specific, but currently testing it
        # out for gcc-compatible compilers only:
        config_include_file = os.path.join(builddir, 'yotta_config.h')
        config_json_file = os.path.join(builddir, 'yotta_config.json')
        set_definitions += 'set(YOTTA_CONFIG_MERGED_JSON_FILE \"%s\")\n' % replaceBackslashes(
            os.path.abspath(config_json_file))

        self._writeFile(
            config_include_file,
            '#ifndef __YOTTA_CONFIG_H__\n' + '#define __YOTTA_CONFIG_H__\n' +
            add_defs_header + '#endif // ndef __YOTTA_CONFIG_H__\n')
        self._writeFile(config_json_file, ordered_json.dumps(merged_config))
        return (config_include_file, set_definitions)
Пример #6
0
def formatDependencyGraphAsJSON(dep_graph):
    from yotta.lib import ordered_json
    return ordered_json.dumps(dep_graph)