• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.mkdir函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tools.utils.mkdir函数的典型用法代码示例。如果您正苦于以下问题:Python mkdir函数的具体用法?Python mkdir怎么用?Python mkdir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了mkdir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: write_to_file

 def write_to_file(self, report, file_name):
     if report is not None:
         dirname = os.path.dirname(file_name)
         if dirname:
             mkdir(dirname)
         with open(file_name, "w") as f:
             f.write(report)
开发者ID:jaustin,项目名称:mbed,代码行数:7,代码来源:test_exporters.py


示例2: setup_project

def setup_project(mcu, ide, program=None, source_dir=None, build=None):

    # Some libraries have extra macros (called by exporter symbols) to we need to pass
    # them to maintain compilation macros integrity between compiled library and
    # header files we might use with it
    if source_dir:
        # --source is used to generate IDE files to toolchain directly in the source tree and doesn't generate zip file
        project_dir = source_dir
        project_name = TESTS[program] if program else "Unnamed_Project"
        project_temp = join(source_dir[0], 'projectfiles', '%s_%s' % (ide, mcu))
        mkdir(project_temp)
    else:
        test = get_test(program)
        if not build:
            # Substitute the library builds with the sources
            # TODO: Substitute also the other library build paths
            if MBED_LIBRARIES in test.dependencies:
                test.dependencies.remove(MBED_LIBRARIES)
                test.dependencies.append(MBED_BASE)

        # Build the project with the same directory structure of the mbed online IDE
        project_name = test.id
        project_dir = [join(EXPORT_WORKSPACE, project_name)]
        project_temp = EXPORT_TMP
        setup_user_prj(project_dir[0], test.source_dir, test.dependencies)

    return project_dir, project_name, project_temp
开发者ID:Neuromancer2701,项目名称:mbedROS2_STF7,代码行数:27,代码来源:project_api.py


示例3: setup_user_prj

def setup_user_prj(user_dir, prj_path, lib_paths=None):
    """
    Setup a project with the same directory structure of the mbed online IDE
    """
    mkdir(user_dir)

    # Project Path
    copy_tree(prj_path, join(user_dir, "src"))

    # Project Libraries
    user_lib = join(user_dir, "lib")
    mkdir(user_lib)

    if lib_paths is not None:
        for lib_path in lib_paths:
            copy_tree(lib_path, join(user_lib, basename(lib_path)))
开发者ID:TemcoHeng,项目名称:mbed,代码行数:16,代码来源:__init__.py


示例4: assemble

    def assemble(self, source, object, includes):
        # Preprocess first, then assemble
        dir = join(dirname(object), '.temp')
        mkdir(dir)
        tempfile = join(dir, basename(object) + '.E.s')
        
        # Build preprocess assemble command
        cmd_pre = self.asm + self.get_compile_options(self.get_symbols(True), includes) + ["-E", "-o", tempfile, source]

        # Build main assemble command
        cmd = self.asm + ["-o", object, tempfile]

        # Call cmdline hook
        cmd_pre = self.hook.get_cmdline_assembler(cmd_pre)
        cmd = self.hook.get_cmdline_assembler(cmd)
       
        # Return command array, don't execute
        return [cmd_pre, cmd]
开发者ID:SoCM,项目名称:ELEC143,代码行数:18,代码来源:arm.py


示例5: scan_and_copy_resources

    def scan_and_copy_resources(self, prj_paths, trg_path, relative=False):
        # Copy only the file for the required target and toolchain
        lib_builds = []
        # Create the configuration object
        config = Config(self.target, prj_paths)
        for src in ['lib', 'src']:
            resources = reduce(add, [self.__scan_and_copy(join(path, src), trg_path) for path in prj_paths])
            lib_builds.extend(resources.lib_builds)

            # The repository files
            for repo_dir in resources.repo_dirs:
                repo_files = self.__scan_all(repo_dir)
                for path in proj_paths :
                    self.toolchain.copy_files(repo_files, trg_path, rel_path=join(path, src))

        # The libraries builds
        for bld in lib_builds:
            build_url = open(bld).read().strip()
            lib_data = self.build_url_resolver(build_url)
            lib_path = lib_data['path'].rstrip('\\/')
            self.__scan_and_copy(lib_path, join(trg_path, lib_data['name']))

            # Create .hg dir in mbed build dir so it's ignored when versioning
            hgdir = join(trg_path, lib_data['name'], '.hg')
            mkdir(hgdir)
            fhandle = file(join(hgdir, 'keep.me'), 'a')
            fhandle.close()

        if not relative:
            # Final scan of the actual exported resources
            resources = self.toolchain.scan_resources(trg_path)
            resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
        else:
            # use the prj_dir (source, not destination)
            resources = self.toolchain.scan_resources(prj_paths[0])
            for path in prj_paths[1:]:
                resources.add(toolchain.scan_resources(path))

        # Loads the resources into the config system which might expand/modify resources based on config data
        self.resources = config.load_resources(resources)

        # And add the configuration macros to the toolchain
        self.config_macros = config.get_config_data_macros()
开发者ID:TemcoHeng,项目名称:mbed,代码行数:43,代码来源:exporters.py


示例6: copy_files

    def copy_files(self, files_paths, trg_path, rel_path=None):

        # Handle a single file
        if type(files_paths) != ListType: files_paths = [files_paths]

        for source in files_paths:
            if source is None:
                files_paths.remove(source)

        for source in files_paths:
            if rel_path is not None:
                relative_path = relpath(source, rel_path)
            else:
                _, relative_path = split(source)

            target = join(trg_path, relative_path)

            if (target != source) and (self.need_update(target, [source])):
                self.progress("copy", relative_path)
                mkdir(dirname(target))
                copyfile(source, target)
开发者ID:jaustin,项目名称:mbed,代码行数:21,代码来源:__init__.py


示例7: link_program

    def link_program(self, r, tmp_path, name):
        needed_update = False
        ext = "bin"
        if hasattr(self.target, "OUTPUT_EXT"):
            ext = self.target.OUTPUT_EXT

        if hasattr(self.target, "OUTPUT_NAMING"):
            self.var("binary_naming", self.target.OUTPUT_NAMING)
            if self.target.OUTPUT_NAMING == "8.3":
                name = name[0:8]
                ext = ext[0:3]

        # Create destination directory
        head, tail = split(name)
        new_path = join(tmp_path, head)
        mkdir(new_path)

        filename = name + "." + ext
        elf = join(tmp_path, name + ".elf")
        bin = join(tmp_path, filename)
        map = join(tmp_path, name + ".map")

        if self.need_update(elf, r.objects + r.libraries + [r.linker_script]):
            needed_update = True
            self.progress("link", name)
            self.link(elf, r.objects, r.libraries, r.lib_dirs, r.linker_script)

        if self.need_update(bin, [elf]):
            needed_update = True
            self.progress("elf2bin", name)

            self.binary(r, elf, bin)

        self.mem_stats(map)

        self.var("compile_succeded", True)
        self.var("binary", filename)

        return bin, needed_update
开发者ID:DanKupiniak,项目名称:mbed,代码行数:39,代码来源:__init__.py


示例8: build_project

def build_project(src_paths, build_path, target, toolchain_name,
                  libraries_paths=None, linker_script=None,
                  clean=False, notify=None, verbose=False, name=None,
                  macros=None, inc_dirs=None, jobs=1, silent=False,
                  report=None, properties=None, project_id=None,
                  project_description=None, extra_verbose=False, config=None,
                  app_config=None, build_profile=None):
    """ Build a project. A project may be a test or a user program.

    Positional arguments:
    src_paths - a path or list of paths that contain all files needed to build
                the project
    build_path - the directory where all of the object files will be placed
    target - the MCU or board that the project will compile for
    toolchain_name - the name of the build tools

    Keyword arguments:
    libraries_paths - The location of libraries to include when linking
    linker_script - the file that drives the linker to do it's job
    clean - Rebuild everything if True
    notify - Notify function for logs
    verbose - Write the actual tools command lines used if True
    name - the name of the project
    macros - additional macros
    inc_dirs - additional directories where include files may be found
    jobs - how many compilers we can run at once
    silent - suppress printing of progress indicators
    report - a dict where a result may be appended
    properties - UUUUHHHHH beats me
    project_id - the name put in the report
    project_description - the human-readable version of what this thing does
    extra_verbose - even more output!
    config - a Config object to use instead of creating one
    app_config - location of a chosen mbed_app.json file
    build_profile - a dict of flags that will be passed to the compiler
    """

    # Convert src_path to a list if needed
    if type(src_paths) != ListType:
        src_paths = [src_paths]
    # Extend src_paths wiht libraries_paths
    if libraries_paths is not None:
        src_paths.extend(libraries_paths)
        inc_dirs.extend(map(dirname, libraries_paths))

    # Build Directory
    if clean and exists(build_path):
        rmtree(build_path)
    mkdir(build_path)

    # Pass all params to the unified prepare_toolchain()
    toolchain = prepare_toolchain(
        src_paths, build_path, target, toolchain_name, macros=macros,
        clean=clean, jobs=jobs, notify=notify, silent=silent, verbose=verbose,
        extra_verbose=extra_verbose, config=config, app_config=app_config,
        build_profile=build_profile)

    # The first path will give the name to the library
    if name is None:
        name = basename(normpath(abspath(src_paths[0])))
    toolchain.info("Building project %s (%s, %s)" %
                   (name, toolchain.target.name, toolchain_name))

    # Initialize reporting
    if report != None:
        start = time()
        # If project_id is specified, use that over the default name
        id_name = project_id.upper() if project_id else name.upper()
        description = project_description if project_description else name
        vendor_label = toolchain.target.extra_labels[0]
        prep_report(report, toolchain.target.name, toolchain_name, id_name)
        cur_result = create_result(toolchain.target.name, toolchain_name,
                                   id_name, description)
        if properties != None:
            prep_properties(properties, toolchain.target.name, toolchain_name,
                            vendor_label)

    try:
        # Call unified scan_resources
        resources = scan_resources(src_paths, toolchain, inc_dirs=inc_dirs)

        # Change linker script if specified
        if linker_script is not None:
            resources.linker_script = linker_script

        # Compile Sources
        objects = toolchain.compile_sources(resources, resources.inc_dirs)
        resources.objects.extend(objects)

        # Link Program
        if toolchain.config.has_regions:
            res, _ = toolchain.link_program(resources, build_path, name + "_application")
            region_list = list(toolchain.config.regions)
            region_list = [r._replace(filename=res) if r.active else r
                           for r in region_list]
            res = join(build_path, name) + ".bin"
            merge_region_list(region_list, res)
        else:
            res, _ = toolchain.link_program(resources, build_path, name)

#.........这里部分代码省略.........
开发者ID:akselsm,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例9: build_lib

def build_lib(lib_id, target, toolchain_name, verbose=False,
              clean=False, macros=None, notify=None, jobs=1, silent=False,
              report=None, properties=None, extra_verbose=False,
              build_profile=None):
    """ Legacy method for building mbed libraries

    Positional arguments:
    lib_id - the library's unique identifier
    target - the MCU or board that the project will compile for
    toolchain_name - the name of the build tools

    Keyword arguments:
    clean - Rebuild everything if True
    verbose - Write the actual tools command lines used if True
    macros - additional macros
    notify - Notify function for logs
    jobs - how many compilers we can run at once
    silent - suppress printing of progress indicators
    report - a dict where a result may be appended
    properties - UUUUHHHHH beats me
    extra_verbose - even more output!
    build_profile - a dict of flags that will be passed to the compiler
    """
    lib = Library(lib_id)
    if not lib.is_supported(target, toolchain_name):
        print('Library "%s" is not yet supported on target %s with toolchain %s'
              % (lib_id, target.name, toolchain_name))
        return False

    # We need to combine macros from parameter list with macros from library
    # definition
    lib_macros = lib.macros if lib.macros else []
    if macros:
        macros.extend(lib_macros)
    else:
        macros = lib_macros

    src_paths = lib.source_dir
    build_path = lib.build_dir
    dependencies_paths = lib.dependencies
    inc_dirs = lib.inc_dirs
    inc_dirs_ext = lib.inc_dirs_ext

    if type(src_paths) != ListType:
        src_paths = [src_paths]

    # The first path will give the name to the library
    name = basename(src_paths[0])

    if report != None:
        start = time()
        id_name = name.upper()
        description = name
        vendor_label = target.extra_labels[0]
        cur_result = None
        prep_report(report, target.name, toolchain_name, id_name)
        cur_result = create_result(target.name, toolchain_name, id_name,
                                   description)

        if properties != None:
            prep_properties(properties, target.name, toolchain_name,
                            vendor_label)

    for src_path in src_paths:
        if not exists(src_path):
            error_msg = "The library source folder does not exist: %s", src_path

            if report != None:
                cur_result["output"] = error_msg
                cur_result["result"] = "FAIL"
                add_result_to_report(report, cur_result)

            raise Exception(error_msg)

    try:
        # Toolchain instance
        # Create the desired build directory structure
        bin_path = join(build_path, mbed2_obj_path(target.name, toolchain_name))
        mkdir(bin_path)
        tmp_path = join(build_path, '.temp', mbed2_obj_path(target.name,
                                                            toolchain_name))
        mkdir(tmp_path)

        toolchain = prepare_toolchain(
            src_paths, tmp_path, target, toolchain_name, macros=macros,
            notify=notify, silent=silent, extra_verbose=extra_verbose,
            build_profile=build_profile, jobs=jobs, clean=clean)

        toolchain.info("Building library %s (%s, %s)" %
                       (name.upper(), target.name, toolchain_name))

        # Take into account the library configuration (MBED_CONFIG_FILE)
        config = toolchain.config
        config.add_config_files([MBED_CONFIG_FILE])

        # Scan Resources
        resources = []
        for src_path in src_paths:
            resources.append(toolchain.scan_resources(src_path))

#.........这里部分代码省略.........
开发者ID:akselsm,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例10: build_library

def build_library(src_paths, build_path, target, toolchain_name,
                  dependencies_paths=None, name=None, clean=False,
                  archive=True, notify=None, verbose=False, macros=None,
                  inc_dirs=None, jobs=1, silent=False, report=None,
                  properties=None, extra_verbose=False, project_id=None,
                  remove_config_header_file=False, app_config=None,
                  build_profile=None):
    """ Build a library

    Positional arguments:
    src_paths - a path or list of paths that contain all files needed to build
                the library
    build_path - the directory where all of the object files will be placed
    target - the MCU or board that the project will compile for
    toolchain_name - the name of the build tools

    Keyword arguments:
    dependencies_paths - The location of libraries to include when linking
    name - the name of the library
    clean - Rebuild everything if True
    archive - whether the library will create an archive file
    notify - Notify function for logs
    verbose - Write the actual tools command lines used if True
    macros - additional macros
    inc_dirs - additional directories where include files may be found
    jobs - how many compilers we can run at once
    silent - suppress printing of progress indicators
    report - a dict where a result may be appended
    properties - UUUUHHHHH beats me
    extra_verbose - even more output!
    project_id - the name that goes in the report
    remove_config_header_file - delete config header file when done building
    app_config - location of a chosen mbed_app.json file
    build_profile - a dict of flags that will be passed to the compiler
    """

    # Convert src_path to a list if needed
    if type(src_paths) != ListType:
        src_paths = [src_paths]

    # Build path
    if archive:
        # Use temp path when building archive
        tmp_path = join(build_path, '.temp')
        mkdir(tmp_path)
    else:
        tmp_path = build_path

    # Clean the build directory
    if clean and exists(tmp_path):
        rmtree(tmp_path)
    mkdir(tmp_path)

    # Pass all params to the unified prepare_toolchain()
    toolchain = prepare_toolchain(
        src_paths, build_path, target, toolchain_name, macros=macros,
        clean=clean, jobs=jobs, notify=notify, silent=silent,
        verbose=verbose, extra_verbose=extra_verbose, app_config=app_config,
        build_profile=build_profile)

    # The first path will give the name to the library
    if name is None:
        name = basename(normpath(abspath(src_paths[0])))
    toolchain.info("Building library %s (%s, %s)" %
                   (name, toolchain.target.name, toolchain_name))

    # Initialize reporting
    if report != None:
        start = time()
        # If project_id is specified, use that over the default name
        id_name = project_id.upper() if project_id else name.upper()
        description = name
        vendor_label = toolchain.target.extra_labels[0]
        prep_report(report, toolchain.target.name, toolchain_name, id_name)
        cur_result = create_result(toolchain.target.name, toolchain_name,
                                   id_name, description)
        if properties != None:
            prep_properties(properties, toolchain.target.name, toolchain_name,
                            vendor_label)

    for src_path in src_paths:
        if not exists(src_path):
            error_msg = "The library source folder does not exist: %s", src_path
            if report != None:
                cur_result["output"] = error_msg
                cur_result["result"] = "FAIL"
                add_result_to_report(report, cur_result)
            raise Exception(error_msg)

    try:
        # Call unified scan_resources
        resources = scan_resources(src_paths, toolchain,
                                   dependencies_paths=dependencies_paths,
                                   inc_dirs=inc_dirs)


        # Copy headers, objects and static libraries - all files needed for
        # static lib
        toolchain.copy_files(resources.headers, build_path, resources=resources)
        toolchain.copy_files(resources.objects, build_path, resources=resources)
#.........这里部分代码省略.........
开发者ID:akselsm,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例11: static_analysis_scan

def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, extra_verbose=False):
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean

    # Source and Build Paths
    BUILD_TARGET = join(MBED_LIBRARIES, "TARGET_" + target.name)
    BUILD_TOOLCHAIN = join(BUILD_TARGET, "TOOLCHAIN_" + toolchain.name)
    mkdir(BUILD_TOOLCHAIN)

    TMP_PATH = join(MBED_LIBRARIES, '.temp', toolchain.obj_path)
    mkdir(TMP_PATH)

    # CMSIS
    toolchain.info("Static analysis for %s (%s, %s)" % ('CMSIS', target.name, toolchain_name))
    cmsis_src = join(MBED_TARGETS_PATH, "cmsis")
    resources = toolchain.scan_resources(cmsis_src)

    # Copy files before analysis
    toolchain.copy_files(resources.headers, BUILD_TARGET)
    toolchain.copy_files(resources.linker_script, BUILD_TOOLCHAIN)

    # Gather include paths, c, cpp sources and macros to transfer to cppcheck command line
    includes = ["-I%s"% i for i in resources.inc_dirs]
    includes.append("-I%s"% str(BUILD_TARGET))
    c_sources = " ".join(resources.c_sources)
    cpp_sources = " ".join(resources.cpp_sources)
    macros = ["-D%s"% s for s in toolchain.get_symbols() + toolchain.macros]

    includes = map(str.strip, includes)
    macros = map(str.strip, macros)

    check_cmd = CPPCHECK_CMD
    check_cmd += CPPCHECK_MSG_FORMAT
    check_cmd += includes
    check_cmd += macros

    # We need to pass some params via file to avoid "command line too long in some OSs"
    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    tmp_file.writelines(line + '\n' for line in c_sources.split())
    tmp_file.writelines(line + '\n' for line in cpp_sources.split())
    tmp_file.close()
    check_cmd += ["--file-list=%s"% tmp_file.name]

    _stdout, _stderr, _rc = run_cmd(check_cmd)
    if verbose:
        print _stdout
    print _stderr

    # =========================================================================

    # MBED
    toolchain.info("Static analysis for %s (%s, %s)" % ('MBED', target.name, toolchain_name))

    # Common Headers
    toolchain.copy_files(toolchain.scan_resources(MBED_API).headers, MBED_LIBRARIES)
    toolchain.copy_files(toolchain.scan_resources(MBED_HAL).headers, MBED_LIBRARIES)

    # Target specific sources
    HAL_SRC = join(MBED_TARGETS_PATH, "hal")
    hal_implementation = toolchain.scan_resources(HAL_SRC)

    # Copy files before analysis
    toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files, BUILD_TARGET, HAL_SRC)
    incdirs = toolchain.scan_resources(BUILD_TARGET)

    target_includes = ["-I%s" % i for i in incdirs.inc_dirs]
    target_includes.append("-I%s"% str(BUILD_TARGET))
    target_includes.append("-I%s"% str(HAL_SRC))
    target_c_sources = " ".join(incdirs.c_sources)
    target_cpp_sources = " ".join(incdirs.cpp_sources)
    target_macros = ["-D%s"% s for s in toolchain.get_symbols() + toolchain.macros]

    # Common Sources
    mbed_resources = toolchain.scan_resources(MBED_COMMON)

    # Gather include paths, c, cpp sources and macros to transfer to cppcheck command line
    mbed_includes = ["-I%s" % i for i in mbed_resources.inc_dirs]
    mbed_includes.append("-I%s"% str(BUILD_TARGET))
    mbed_includes.append("-I%s"% str(MBED_COMMON))
    mbed_includes.append("-I%s"% str(MBED_API))
    mbed_includes.append("-I%s"% str(MBED_HAL))
    mbed_c_sources = " ".join(mbed_resources.c_sources)
    mbed_cpp_sources = " ".join(mbed_resources.cpp_sources)

    target_includes = map(str.strip, target_includes)
    mbed_includes = map(str.strip, mbed_includes)
    target_macros = map(str.strip, target_macros)

    check_cmd = CPPCHECK_CMD
    check_cmd += CPPCHECK_MSG_FORMAT
    check_cmd += target_includes
    check_cmd += mbed_includes
    check_cmd += target_macros

    # We need to pass some parames via file to avoid "command line too long in some OSs"
    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    tmp_file.writelines(line + '\n' for line in target_c_sources.split())
#.........这里部分代码省略.........
开发者ID:c1728p9,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例12: static_analysis_scan_library

def static_analysis_scan_library(src_paths, build_path, target, toolchain_name, cppcheck_cmd, cppcheck_msg_format,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None, jobs=1, extra_verbose=False):
    """ Function scans library (or just some set of sources/headers) for staticly detectable defects """
    if type(src_paths) != ListType:
        src_paths = [src_paths]

    for src_path in src_paths:
        if not exists(src_path):
            raise Exception("The library source folder does not exist: %s", src_path)

    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs

    # The first path will give the name to the library
    name = basename(src_paths[0])
    toolchain.info("Static analysis for library %s (%s, %s)" % (name.upper(), target.name, toolchain_name))

    # Scan Resources
    resources = []
    for src_path in src_paths:
        resources.append(toolchain.scan_resources(src_path))

    # Dependencies Include Paths
    dependencies_include_dir = []
    if dependencies_paths is not None:
        for path in dependencies_paths:
            lib_resources = toolchain.scan_resources(path)
            dependencies_include_dir.extend(lib_resources.inc_dirs)

    # Create the desired build directory structure
    bin_path = join(build_path, toolchain.obj_path)
    mkdir(bin_path)
    tmp_path = join(build_path, '.temp', toolchain.obj_path)
    mkdir(tmp_path)

    # Gather include paths, c, cpp sources and macros to transfer to cppcheck command line
    includes = ["-I%s" % i for i in dependencies_include_dir + src_paths]
    c_sources = " "
    cpp_sources = " "
    macros = ['-D%s' % s for s in toolchain.get_symbols() + toolchain.macros]

    # Copy Headers
    for resource in resources:
        toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
        includes += ["-I%s" % i for i in resource.inc_dirs]
        c_sources += " ".join(resource.c_sources) + " "
        cpp_sources += " ".join(resource.cpp_sources) + " "

    dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)

    includes = map(str.strip, includes)
    macros = map(str.strip, macros)

    check_cmd = cppcheck_cmd
    check_cmd += cppcheck_msg_format
    check_cmd += includes
    check_cmd += macros

    # We need to pass some parameters via file to avoid "command line too long in some OSs"
    # Temporary file is created to store e.g. cppcheck list of files for command line
    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    tmp_file.writelines(line + '\n' for line in c_sources.split())
    tmp_file.writelines(line + '\n' for line in cpp_sources.split())
    tmp_file.close()
    check_cmd += ["--file-list=%s"% tmp_file.name]

    # This will allow us to grab result from both stdio and stderr outputs (so we can show them)
    # We assume static code analysis tool is outputting defects on STDERR
    _stdout, _stderr, _rc = run_cmd_ext(check_cmd)
    if verbose:
        print _stdout
    print _stderr
开发者ID:c1728p9,项目名称:mbed,代码行数:75,代码来源:build_api.py


示例13: build_library

def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False, archive=True,
         notify=None, verbose=False, macros=None, inc_dirs=None,
         jobs=1, silent=False, report=None, properties=None, extra_verbose=False,
         project_id=None):
    """ Prepares resource related objects - toolchain, target, config
    src_paths: the paths to source directories
    build_path: the path of the build directory
    target: ['LPC1768', 'LPC11U24', 'LPC2368']
    toolchain_name: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CR']
    clean: Rebuild everything if True
    notify: Notify function for logs
    verbose: Write the actual tools command lines if True
    inc_dirs: additional include directories which should be included in build
    """

    # Convert src_path to a list if needed
    if type(src_paths) != ListType:
        src_paths = [src_paths]

    # Build path
    if archive:
        # Use temp path when building archive
        tmp_path = join(build_path, '.temp')
        mkdir(tmp_path)
    else:
        tmp_path = build_path

    # Clean the build directory
    if clean:
        if exists(tmp_path):
            rmtree(tmp_path)
    mkdir(tmp_path)

    # Pass all params to the unified prepare_toolchain()
    toolchain = prepare_toolchain(src_paths, target, toolchain_name,
        macros=macros, options=options, clean=clean, jobs=jobs,
        notify=notify, silent=silent, verbose=verbose, extra_verbose=extra_verbose)

    # The first path will give the name to the library
    if name is None:
        name = basename(normpath(abspath(src_paths[0])))
    toolchain.info("Building library %s (%s, %s)" % (name, toolchain.target.name, toolchain_name))

    # Initialize reporting
    if report != None:
        start = time()
        # If project_id is specified, use that over the default name
        id_name = project_id.upper() if project_id else name.upper()
        description = name
        vendor_label = toolchain.target.extra_labels[0]
        prep_report(report, toolchain.target.name, toolchain_name, id_name)
        cur_result = create_result(toolchain.target.name, toolchain_name, id_name, description)
        if properties != None:
            prep_properties(properties, toolchain.target.name, toolchain_name, vendor_label)

    for src_path in src_paths:
        if not exists(src_path):
            error_msg = "The library source folder does not exist: %s", src_path
            if report != None:
                cur_result["output"] = error_msg
                cur_result["result"] = "FAIL"
                add_result_to_report(report, cur_result)
            raise Exception(error_msg)

    try:
        # Call unified scan_resources
        resources = scan_resources(src_paths, toolchain, dependencies_paths=dependencies_paths, inc_dirs=inc_dirs)


        # Copy headers, objects and static libraries - all files needed for static lib
        toolchain.copy_files(resources.headers, build_path, resources=resources)
        toolchain.copy_files(resources.objects, build_path, resources=resources)
        toolchain.copy_files(resources.libraries, build_path, resources=resources)
        if resources.linker_script:
            toolchain.copy_files(resources.linker_script, build_path, resources=resources)

        if resources.hex_files:
            toolchain.copy_files(resources.hex_files, build_path, resources=resources)

        # Compile Sources
        objects = toolchain.compile_sources(resources, abspath(tmp_path), resources.inc_dirs)
        resources.objects.extend(objects)

        if archive:
            toolchain.build_library(objects, build_path, name)

        if report != None:
            end = time()
            cur_result["elapsed_time"] = end - start
            cur_result["output"] = toolchain.get_output()
            cur_result["result"] = "OK"

            add_result_to_report(report, cur_result)
        return True

    except Exception, e:
        if report != None:
            end = time()

#.........这里部分代码省略.........
开发者ID:Neuromancer2701,项目名称:mbedROS2_STF7,代码行数:101,代码来源:build_api.py


示例14: build_mbed_libs

def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
    """ Function returns True is library was built and false if building was skipped """

    if report != None:
        start = time()
        id_name = "MBED"
        description = "mbed SDK"
        vendor_label = target.extra_labels[0]
        cur_result = None
        prep_report(report, target.name, toolchain_name, id_name)
        cur_result = create_result(target.name, toolchain_name, id_name, description)

        if properties != None:
            prep_properties(properties, target.name, toolchain_name, vendor_label)

    # Check toolchain support
    if toolchain_name not in target.supported_toolchains:
        supported_toolchains_text = ", ".join(target.supported_toolchains)
        print '%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
        print '%s target supports %s toolchain%s' % (target.name, supported_toolchains_text, 's' if len(target.supported_toolchains) > 1 else '')

        if report != None:
            cur_result["result"] = "SKIP"
            add_result_to_report(report, cur_result)

        return False

    try:
        # Toolchain
        toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose)
        toolchain.VERBOSE = verbose
        toolchain.jobs = jobs
        toolchain.build_all = clean

        # Source and Build Paths
        BUILD_TARGET = join(MBED_LIBRARIES, "TARGET_" + target.name)
        BUILD_TOOLCHAIN = join(BUILD_TARGET, "TOOLCHAIN_" + toolchain.name)
        mkdir(BUILD_TOOLCHAIN)

        TMP_PATH = join(MBED_LIBRARIES, '.temp', toolchain.obj_path)
        mkdir(TMP_PATH)

        # CMSIS
        toolchain.info("Building library %s (%s, %s)"% ('CMSIS', target.name, toolchain_name))
        cmsis_src = join(MBED_TARGETS_PATH, "cmsis")
        resources = toolchain.scan_resources(cmsis_src)

        toolchain.copy_files(resources.headers, BUILD_TARGET)
        toolchain.copy_files(resources.linker_script, BUILD_TOOLCHAIN)
        toolchain.copy_files(resources.bin_files, BUILD_TOOLCHAIN)

        objects = toolchain.compile_sources(resources, TMP_PATH)
        toolchain.copy_files(objects, BUILD_TOOLCHAIN)

        # mbed
        toolchain.info("Building library %s (%s, %s)" % ('MBED', target.name, toolchain_name))

        # Common Headers
        toolchain.copy_files(toolchain.scan_resources(MBED_API).headers, MBED_LIBRARIES)
        toolchain.copy_files(toolchain.scan_resources(MBED_HAL).headers, MBED_LIBRARIES)

        # Target specific sources
        HAL_SRC = join(MBED_TARGETS_PATH, "hal")
        hal_implementation = toolchain.scan_resources(HAL_SRC)
        toolchain.copy_files(hal_implementation.headers + hal_implementation.hex_files + hal_implementation.libraries, BUILD_TARGET, HAL_SRC)
        incdirs = toolchain.scan_resources(BUILD_TARGET).inc_dirs
        objects = toolchain.compile_sources(hal_implementation, TMP_PATH, [MBED_LIBRARIES] + incdirs)

        # Common Sources
        mbed_resources = toolchain.scan_resources(MBED_COMMON)
        objects += toolchain.compile_sources(mbed_resources, TMP_PATH, [MBED_LIBRARIES] + incdirs)

        # A number of compiled files need to be copied as objects as opposed to
        # being part of the mbed library, for reasons that have to do with the way
        # the linker search for symbols in archives. These are:
        #   - retarget.o: to make sure that the C standard lib symbols get overridden
        #   - board.o: mbed_die is weak
        #   - mbed_overrides.o: this contains platform overrides of various weak SDK functions
        separate_names, separate_objects = ['retarget.o', 'board.o', 'mbed_overrides.o'], []

        for o in objects:
            for name in separate_names:
                if o.endswith(name):
                    separate_objects.append(o)

        for o in separate_objects:
            objects.remove(o)

        toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")

        for o in separate_objects:
            toolchain.copy_files(o, BUILD_TOOLCHAIN)

        if report != None:
            end = time()
            cur_result["elapsed_time"] = end - start
            cur_result["output"] = toolchain.get_output()
            cur_result["result"] = "OK"

            add_result_to_report(report, cur_result)
#.........这里部分代码省略.........
开发者ID:c1728p9,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例15: build_project

def build_project(src_path, build_path, target, toolchain_name,
        libraries_paths=None, options=None, linker_script=None,
        clean=False, notify=None, verbose=False, name=None, macros=None, inc_dirs=None,
        jobs=1, silent=False, report=None, properties=None, project_id=None, project_description=None,
        extra_verbose=False, config=None):
    """ This function builds project. Project can be for example one test / UT
    """

    # Convert src_path to a list if needed
    src_paths = [src_path] if type(src_path) != ListType else src_path

    # We need to remove all paths which are repeated to avoid
    # multiple compilations and linking with the same objects
    src_paths = [src_paths[0]] + list(set(src_paths[1:]))
    first_src_path = src_paths[0] if src_paths[0] != "." and src_paths[0] != "./" else getcwd()
    abs_path = abspath(first_src_path)
    project_name = basename(normpath(abs_path))

    # If the configuration object was not yet created, create it now
    config = config or Config(target, src_paths)

    # If the 'target' argument is a string, convert it to a target instance
    if isinstance(target, str):
        try:
            target = TARGET_MAP[target]
        except KeyError:
            raise KeyError("Target '%s' not found" % target)

    # Toolchain instance
    try:
        toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)
    except KeyError as e:
        raise KeyError("Toolchain %s not supported" % toolchain_name)

    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean

    if name is None:
        # We will use default project name based on project folder name
        name = project_name
        toolchain.info("Building project %s (%s, %s)" % (project_name, target.name, toolchain_name))
    else:
        # User used custom global project name to have the same name for the
        toolchain.info("Building project %s to %s (%s, %s)" % (project_name, name, target.name, toolchain_name))


    if report != None:
        start = time()
        
        # If project_id is specified, use that over the default name
        id_name = project_id.upper() if project_id else name.upper()
        description = project_description if project_description else name
        vendor_label = target.extra_labels[0]
        cur_result = None
        prep_report(report, target.name, toolchain_name, id_name)
        cur_result = create_result(target.name, toolchain_name, id_name, description)

        if properties != None:
            prep_properties(properties, target.name, toolchain_name, vendor_label)

    try:
        # Scan src_path and libraries_paths for resources
        resources = toolchain.scan_resources(src_paths[0])
        for path in src_paths[1:]:
            resources.add(toolchain.scan_resources(path))
        if libraries_paths is not None:
            src_paths.extend(libraries_paths)
            for path in libraries_paths:
                resources.add(toolchain.scan_resources(path))

        if linker_script is not None:
            resources.linker_script = linker_script

        # Build Directory
        if clean:
            if exists(build_path):
                rmtree(build_path)
        mkdir(build_path)

        # We need to add if necessary additional include directories
        if inc_dirs:
            if type(inc_dirs) == ListType:
                resources.inc_dirs.extend(inc_dirs)
            else:
                resources.inc_dirs.append(inc_dirs)

        # Update the configuration with any .json files found while scanning
        config.add_config_files(resources.json_files)
        # And add the configuration macros to the toolchain
        toolchain.add_macros(config.get_config_data_macros())

        # Compile Sources
        for path in src_paths:
            src = toolchain.scan_resources(path)
            objects = toolchain.compile_sources(src, build_path, resources.inc_dirs)
            resources.objects.extend(objects)

        # Link Program
        res, _ = toolchain.link_program(resources, build_path, name)
#.........这里部分代码省略.........
开发者ID:c1728p9,项目名称:mbed,代码行数:101,代码来源:build_api.py


示例16: build_library


#.........这里部分代码省略.........
            raise Exception(error_msg)

    try:
        # Toolchain instance
        toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, silent=silent, extra_verbose=extra_verbose)
        toolchain.VERBOSE = verbose
        toolchain.jobs = jobs
        toolchain.build_all = clean

        toolchain.info("Building library %s (%s, %s)" % (name, target.name, toolchain_name))

        # Scan Resources
        resources = None
        for path in src_paths:
            # Scan resources
            resource = toolchain.scan_resources(path)
            
            # Copy headers, objects and static libraries - all files needed for static lib
            toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
            toolchain.copy_files(resource.objects, build_path, rel_path=resource.base_path)
            toolchain.copy_files(resource.libraries, build_path, rel_path=resource.base_path)
            if resource.linker_script:
                toolchain.copy_files(resource.linker_script, build_path, rel_path=resource.base_path)

            # Extend resources collection
            if not resources:
      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wpt.main函数代码示例发布时间:2022-05-27
下一篇:
Python translate._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap