Exemplo n.º 1
0
def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None, inc_dirs=None):
    """ src_path: the path of the source directory
    build_path: the path of the build directory
    target: ['LPC1768', 'LPC11U24', 'LPC2368']
    toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CS', 'GCC_CR']
    library_paths: List of paths to additional libraries
    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"""
    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)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean

    # The first path will give the name to the library
    name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD 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)

    if inc_dirs:
        dependencies_include_dir.extend(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)

    # Copy Headers
    for resource in resources:
        toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
    dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)

    # Compile Sources
    objects = []
    for resource in resources:
        objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))

    toolchain.build_library(objects, bin_path, name)
Exemplo n.º 2
0
def build_project(src_path,
                  build_path,
                  target,
                  toolchain_name,
                  libraries_paths=None,
                  clean=False,
                  notify=None,
                  verbose=False,
                  name=None):
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean

    if name is None:
        name = basename(src_path)
    toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" %
                   (name.upper(), target.name, toolchain_name))

    # Scan src_path and libraries_paths for resources
    resources = toolchain.scan_resources(src_path)
    if libraries_paths is not None:
        for path in libraries_paths:
            resources.add(toolchain.scan_resources(path))

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

    # Build Program
    return toolchain.build_program(resources, build_path, name)
Exemplo n.º 3
0
    def scan_and_copy_resources(self, prj_path, trg_path):
        # Copy only the file for the required target and toolchain
        lib_builds = []
        for src in ['lib', 'src']:
            resources = self.__scan_and_copy(join(prj_path, src), trg_path)
            lib_builds.extend(resources.lib_builds)

            # The repository files
            for repo_dir in resources.repo_dirs:
                repo_files = self.__scan_all(repo_dir)
                self.toolchain.copy_files(repo_files, trg_path, rel_path=join(prj_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()

        # Final scan of the actual exported resources
        self.resources = self.toolchain.scan_resources(trg_path)
        self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
Exemplo n.º 4
0
def test_export(toolchain, target, expected_error=None):
    if toolchain is None and target is None:
        base_dir = join(EXPORT_TMP, "zip")
    else:
        base_dir = join(EXPORT_TMP, toolchain, target)
    temp_dir = join(base_dir, "temp")
    mkdir(temp_dir)

    zip_path, report = export(
        USER_PRJ, USR_PRJ_NAME, toolchain, target, base_dir, temp_dir, False, fake_build_url_resolver
    )

    if report["success"]:
        move(zip_path, join(EXPORT_DIR, "export_%s_%s.zip" % (toolchain, target)))
        print "[OK]"
    else:
        if expected_error is None:
            print "[ERRROR] %s" % report["errormsg"]
        else:
            if (zip_path is None) and (expected_error in report["errormsg"]):
                print "[OK]"
            else:
                print "[ERROR]"
                print "    zip:", zip_path
                print "    msg:", report["errormsg"]
Exemplo n.º 5
0
def test_export(toolchain, target, expected_error=None):
    if toolchain is None and target is None:
        base_dir = join(EXPORT_TMP, "zip")
    else:
        base_dir = join(EXPORT_TMP, toolchain, target)
    temp_dir = join(base_dir, "temp")
    mkdir(temp_dir)

    zip_path, report = export(USER_PRJ, USR_PRJ_NAME, toolchain, target,
                              base_dir, temp_dir, False, None,
                              fake_build_url_resolver)

    if report['success']:
        move(zip_path,
             join(EXPORT_DIR, "export_%s_%s.zip" % (toolchain, target)))
        print "[OK]"
    else:
        if expected_error is None:
            print '[ERRROR] %s' % report['errormsg']
        else:
            if (zip_path is None) and (expected_error in report['errormsg']):
                print '[OK]'
            else:
                print '[ERROR]'
                print '    zip:', zip_path
                print '    msg:', report['errormsg']
Exemplo n.º 6
0
def build_project(src_path, build_path, target='LPC1768', toolchain_name='ARM',
        libraries_paths=None, clean=False, notify=None, verbose=False, name=None):
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, notify)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean
    
    if name is None:
        name = basename(src_path)
    toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target, toolchain_name))
    
    # Scan src_path and libraries_paths for resources
    resources = toolchain.scan_resources(src_path)
    if libraries_paths is not None:
        for path in libraries_paths:
            resources.add(toolchain.scan_resources(path))
    
    # Build Directory
    if clean:
        if exists(build_path):
            rmtree(build_path)
    mkdir(build_path)
    
    # Build Program
    return toolchain.build_program(resources, build_path, name)
Exemplo n.º 7
0
    def scan_and_copy_resources(self, prj_path, trg_path):
        # Copy only the file for the required target and toolchain
        lib_builds = []
        for src in ['lib', 'src']:
            resources = self.__scan_and_copy(join(prj_path, src), trg_path)
            lib_builds.extend(resources.lib_builds)

            # The repository files
            for repo_dir in resources.repo_dirs:
                repo_files = self.__scan_all(repo_dir)
                self.toolchain.copy_files(repo_files,
                                          trg_path,
                                          rel_path=join(prj_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()

        # Final scan of the actual exported resources
        self.resources = self.toolchain.scan_resources(trg_path)
        self.resources.relative_to(trg_path, self.DOT_IN_RELATIVE_PATH)
Exemplo n.º 8
0
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):
    """ This function builds project. Project can be for example one test / UT
    """
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean
    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:]))

    PROJECT_BASENAME = basename(src_paths[0])

    if name is None:
        # We will use default project name based on project folder name
        name = PROJECT_BASENAME
        toolchain.info("Building project %s (%s, %s)" % (PROJECT_BASENAME.upper(), 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_BASENAME.upper(), name, target.name, toolchain_name))

    # 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)

    # 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
    return toolchain.link_program(resources, build_path, name)
Exemplo n.º 9
0
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):
    """ This function builds project. Project can be for example one test / UT
    """
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean
    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:]))

    PROJECT_BASENAME = basename(src_paths[0])

    if name is None:
        # We will use default project name based on project folder name
        name = PROJECT_BASENAME
        toolchain.info("Building project %s (%s, %s)" % (PROJECT_BASENAME.upper(), 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_BASENAME.upper(), name, target.name, toolchain_name))

    # 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)

    # 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
    return toolchain.link_program(resources, build_path, name)
Exemplo n.º 10
0
def build_library(src_paths,
                  build_path,
                  target,
                  toolchain_name,
                  dependencies_paths=None,
                  options=None,
                  name=None,
                  clean=False,
                  notify=None,
                  verbose=False):
    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, notify)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean

    # The first path will give the name to the library
    name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD 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)

    # Copy Headers
    for resource in resources:
        toolchain.copy_files(resource.headers,
                             build_path,
                             rel_path=resource.base_path)

    # Compile Sources
    objects = []
    for resource in resources:
        objects.extend(
            toolchain.compile_sources(resource, tmp_path,
                                      dependencies_include_dir))

    toolchain.build_library(objects, bin_path, name)
Exemplo n.º 11
0
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None):
    # Check toolchain support
    if toolchain_name not in target.supported_toolchains:
        print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
        return
    
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros)
    toolchain.VERBOSE = verbose
    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("\n>>> BUILD 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)
    
    objects = toolchain.compile_sources(resources, TMP_PATH)
    toolchain.copy_files(objects, BUILD_TOOLCHAIN)
    
    # mbed
    toolchain.info("\n>>> BUILD 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, BUILD_TARGET)
    objects  = toolchain.compile_sources(hal_implementation, TMP_PATH, [MBED_LIBRARIES, BUILD_TARGET])
    
    # Common Sources
    mbed_resources = toolchain.scan_resources(MBED_COMMON)
    objects += toolchain.compile_sources(mbed_resources, TMP_PATH, [MBED_LIBRARIES, BUILD_TARGET])
    
    # Keep retargeting as a standalone object to be sure the
    # C standard library symbols get overridden
    retargeting = None
    for o in objects:
        if o.endswith('retarget.o'):
            retargeting = o
    objects.remove(retargeting)
    toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
    toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)
Exemplo n.º 12
0
def build_mbed_libs(target, toolchain_name, verbose=False):
    # Check toolchain support
    if toolchain_name not in target.supported_toolchains:
        print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
        return
    
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target)
    toolchain.VERBOSE = verbose
    
    # Source and Build Paths
    TARGET_SRC = join(VENDOR_PATH, target.vendor, target.name)
    BUILD_TARGET = join(MBED_LIBRARIES, target.name)
    BUILD_TOOLCHAIN = join(BUILD_TARGET, toolchain_name)
    mkdir(BUILD_TOOLCHAIN)
    
    TMP_PATH = join(MBED_LIBRARIES, '.temp', toolchain.obj_path)
    mkdir(TMP_PATH)
    
    # CMSIS
    toolchain.info("\n>>> BUILD LIBRARY %s (%s, %s)" % ('CMSIS', target.name, toolchain_name))
    cmsis_src = join(TARGET_SRC, "cmsis")
    resources = toolchain.scan_resources(cmsis_src)
    
    toolchain.copy_files(resources.headers + [resources.linker_script], BUILD_TARGET, rel_path=cmsis_src)
    objects = toolchain.compile_sources(resources, TMP_PATH, resources.inc_dirs)
    toolchain.copy_files(objects, BUILD_TOOLCHAIN)
    
    # mbed
    toolchain.info("\n>>> BUILD LIBRARY %s (%s, %s)" % ('MBED', target.name, toolchain_name))
    HAL_SRC = join(TARGET_SRC, "hal")
    hal_implementation = toolchain.scan_resources(HAL_SRC)
    
    mbed_resources = toolchain.scan_resources(MBED_COMMON)
    mbed_resources.add(hal_implementation)
    
    # Headers
    toolchain.copy_files(toolchain.scan_resources(MBED_API).headers, MBED_LIBRARIES)
    toolchain.copy_files(toolchain.scan_resources(MBED_HAL).headers, MBED_LIBRARIES)
    toolchain.copy_files(hal_implementation.headers, BUILD_TARGET)
    
    includes = mbed_resources.inc_dirs + [MBED_LIBRARIES, BUILD_TARGET]
    objects = toolchain.compile_sources(mbed_resources, TMP_PATH, includes)
    
    # Keep the stdio retargeting as a standalone object to be sure the
    # C standard library symbols get overridden
    stdio_retargeting = None
    for o in objects:
        if o.endswith('stdio.o'):
            stdio_retargeting = o
    objects.remove(stdio_retargeting)
    toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
    toolchain.copy_files(stdio_retargeting, BUILD_TOOLCHAIN)
Exemplo n.º 13
0
 def copy_files(self, src_path, trg_path, files_paths):
     # Handle a single file
     if type(files_paths) != ListType: files_paths = [files_paths]
     
     for source in files_paths:
         
         relative_path = relpath(source, src_path)
         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)
Exemplo n.º 14
0
    def copy_files(self, src_path, trg_path, files_paths):
        # Handle a single file
        if type(files_paths) != ListType: files_paths = [files_paths]

        for source in files_paths:

            relative_path = relpath(source, src_path)
            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)
Exemplo n.º 15
0
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):
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify,
                                                  macros)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean

    src_paths = [src_path] if type(src_path) != ListType else src_path
    if name is None:
        name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" %
                   (name.upper(), target.name, toolchain_name))

    # 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)

    # 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
    return toolchain.link_program(resources, build_path, name)
Exemplo n.º 16
0
    def compile_sources(self, resources, build_path, inc_dirs=None):
        # Web IDE progress bar for project build
        files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
        self.to_be_compiled = len(files_to_compile)
        self.compiled = 0

        #for i in self.build_params:
        #    self.debug(i)
        #    self.debug("%s" % self.build_params[i])

        inc_paths = resources.inc_dirs
        if inc_dirs is not None:
            inc_paths.extend(inc_dirs)

        objects = []
        queue = []
        prev_dir = None

        # The dependency checking for C/C++ is delegated to the compiler
        base_path = resources.base_path
        files_to_compile.sort()
        for source in files_to_compile:
            _, name, _ = split_path(source)
            object = self.relative_object_path(build_path, base_path, source)

            # Avoid multiple mkdir() calls on same work directory
            work_dir = dirname(object)
            if work_dir is not prev_dir:
                prev_dir = work_dir
                mkdir(work_dir)

            # Queue mode (multiprocessing)
            commands = self.compile_command(source, object, inc_paths)
            if commands is not None:
                queue.append({
                    'source': source,
                    'object': object,
                    'commands': commands,
                    'work_dir': work_dir,
                    'chroot': self.CHROOT
                })
            else:
                objects.append(object)

        # Use queues/multiprocessing if cpu count is higher than setting
        jobs = self.jobs if self.jobs else cpu_count()
        if jobs > CPU_COUNT_MIN and len(queue) > jobs:
            return self.compile_queue(queue, objects)
        else:
            return self.compile_seq(queue, objects)
Exemplo n.º 17
0
    def compile_sources(self, resources, build_path, inc_dirs=None):
        # Web IDE progress bar for project build
        files_to_compile = resources.s_sources + resources.c_sources + resources.cpp_sources
        self.to_be_compiled = len(files_to_compile)
        self.compiled = 0

        #for i in self.build_params:
        #    self.debug(i)
        #    self.debug("%s" % self.build_params[i])

        inc_paths = resources.inc_dirs
        if inc_dirs is not None:
            inc_paths.extend(inc_dirs)

        objects = []
        queue = []
        prev_dir = None

        # The dependency checking for C/C++ is delegated to the compiler
        base_path = resources.base_path
        files_to_compile.sort()
        for source in files_to_compile:
            _, name, _ = split_path(source)
            object = self.relative_object_path(build_path, base_path, source)

            # Avoid multiple mkdir() calls on same work directory
            work_dir = dirname(object)
            if work_dir is not prev_dir:
                prev_dir = work_dir
                mkdir(work_dir)

            # Queue mode (multiprocessing)
            commands = self.compile_command(source, object, inc_paths)
            if commands is not None:
                queue.append({
                    'source': source,
                    'object': object,
                    'commands': commands,
                    'work_dir': work_dir,
                    'chroot': self.CHROOT
                })
            else:
                objects.append(object)

        # Use queues/multiprocessing if cpu count is higher than setting
        jobs = self.jobs if self.jobs else cpu_count()
        if jobs > CPU_COUNT_MIN and len(queue) > jobs:
            return self.compile_queue(queue, objects)
        else:
            return self.compile_seq(queue, objects)
Exemplo n.º 18
0
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):
    """ This function builds project. Project can be for example one test / UT """
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean
    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:]))

    if name is None:
        name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target.name, toolchain_name))

    # 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:
        clean_dir(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)

    # 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
    return toolchain.link_program(resources, build_path, name)
Exemplo n.º 19
0
def setup_test_user_prj():
    if exists(USER_PRJ):
        print 'Test user project already generated...'
        return
    
    # Build project directory structure
    for d in [USER_LIB, USER_SRC]:
        mkdir(d)
    
    # Sources
    print 'Coping sources...'
    copy_file(join(TEST_DIR, "mbed", "hello", "main.cpp"), join(USER_SRC, "main.cpp"))
    
    # FAKE BUILD URL
    open(join(USER_SRC, "mbed.bld"), 'w').write("http://mbed.org/users/mbed_official/code/mbed/builds/976df7c37ad5\n")
Exemplo n.º 20
0
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)))
Exemplo n.º 21
0
    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 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)
Exemplo n.º 22
0
 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 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)
Exemplo n.º 23
0
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)))
Exemplo n.º 24
0
def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None):
    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, notify, macros)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean
    
    # The first path will give the name to the library
    name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD 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)
    
    # Copy Headers
    for resource in resources:
        toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
    dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
    
    # Compile Sources
    objects = []
    for resource in resources:
        objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))
    
    toolchain.build_library(objects, bin_path, name)
Exemplo n.º 25
0
def setup_test_user_prj():
    if exists(USER_PRJ):
        print 'Test user project already generated...'
        return

    # Build project directory structure
    for d in [USER_LIB, USER_SRC]:
        mkdir(d)

    # Sources
    print 'Coping sources...'
    copy_file(join(TEST_DIR, "mbed", "hello", "main.cpp"),
              join(USER_SRC, "main.cpp"))

    # FAKE BUILD URL
    open(join(USER_SRC, "mbed.bld"), 'w').write(
        "http://mbed.org/users/mbed_official/code/mbed/builds/976df7c37ad5\n")
Exemplo n.º 26
0
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):
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros)
    toolchain.VERBOSE = verbose
    toolchain.build_all = clean

    src_paths = [src_path] if type(src_path) != ListType else src_path
    if name is None:
        name = basename(src_paths[0])
    toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
    
    # 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)
    
    # 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
    return toolchain.link_program(resources, build_path, name)
Exemplo n.º 27
0
def test_export(toolchain, target, expected_error=None):
    if toolchain is None and target is None:
        base_dir = join(TEMP, "zip")
    else:
        base_dir = join(TEMP, toolchain, target)
    temp_dir = join(base_dir, "temp")
    mkdir(temp_dir)
    
    zip_path, report = export(USER_PRJ, USR_PRJ_NAME, toolchain, target, base_dir, temp_dir, False, fake_build_url_resolver)
    
    if report['success']:
        export_name = join(EXPORT_DIR, "export_%s_%s.zip" % (toolchain, target))
        cmd(["mv", zip_path, export_name])
        print "[OK]"
    else:
        if expected_error is None:
            print '[ERRROR] %s' % report['errormsg']
        else:
            if (zip_path is None) and (expected_error in report['errormsg']):
                print '[OK]'
            else:
                print '[ERROR]'
                print '    zip:', zip_path
                print '    msg:', report['errormsg']
Exemplo n.º 28
0
def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None,
         jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
    """ src_path: the path of the source directory
    build_path: the path of the build directory
    target: ['LPC1768', 'LPC11U24', 'LPC2368']
    toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CS', 'GCC_CR']
    library_paths: List of paths to additional libraries
    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
    inc_dirs_ext: additional include directories which should be copied to library directory
    """
    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
        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, id_name)

    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
        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.upper(), target.name, toolchain_name))

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

        # Add extra include directories / files which are required by library
        # This files usually are not in the same directory as source files so
        # previous scan will not include them
        if inc_dirs_ext is not None:
            for inc_ext in inc_dirs_ext:
                resources.append(toolchain.scan_resources(inc_ext))

        # 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)

        if inc_dirs:
            dependencies_include_dir.extend(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)

        # Copy Headers
        for resource in resources:
            toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
        dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)

        # Compile Sources
        objects = []
        for resource in resources:
            objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))

        needed_update = toolchain.build_library(objects, bin_path, name)

        if report != None and needed_update:
            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)

    except Exception, e:
        if report != None:
            end = time()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 29
0
 def relative_object_path(self, build_path, base_dir, source):
     source_dir, name, _ = split_path(source)
     obj_dir = join(build_path, relpath(source_dir, base_dir))
     mkdir(obj_dir)
     return join(obj_dir, name + '.o')
Exemplo n.º 30
0
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):
    """ This function builds project. Project can be for example one test / UT
    """
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean
    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:]))
    PROJECT_BASENAME = basename(src_paths[0])

    if name is None:
        # We will use default project name based on project folder name
        name = PROJECT_BASENAME
        toolchain.info("Building project %s (%s, %s)" % (PROJECT_BASENAME.upper(), 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_BASENAME.upper(), name, target.name, toolchain_name))


    if report != None:
        start = time()
        id_name = project_id.upper()
        description = project_description
        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)

        # 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, needed_update = toolchain.link_program(resources, build_path, name)

        if report != None and needed_update:
            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 res

    except Exception, e:
        if report != None:
            end = time()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 31
0
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):
    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)
    toolchain.VERBOSE = verbose

    # 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 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 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_ext(check_cmd)
    if verbose:
        print _stdout
    print _stderr
Exemplo n.º 32
0
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):
    """ 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)
    toolchain.VERBOSE = verbose

    # 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
Exemplo n.º 33
0
def build_mbed_libs(target,
                    toolchain_name,
                    options=None,
                    verbose=False,
                    clean=False,
                    macros=None):
    # Check toolchain support
    if toolchain_name not in target.supported_toolchains:
        print '\n%s target is not yet supported by toolchain %s' % (
            target.name, toolchain_name)
        return

    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target,
                                                  options,
                                                  macros=macros)
    toolchain.VERBOSE = verbose
    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("\n>>> BUILD 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)

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

    # mbed
    toolchain.info("\n>>> BUILD 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, BUILD_TARGET)
    objects = toolchain.compile_sources(hal_implementation, TMP_PATH,
                                        [MBED_LIBRARIES, BUILD_TARGET])

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

    # Keep retargeting as a standalone object to be sure the
    # C standard library symbols get overridden
    retargeting = None
    for o in objects:
        if o.endswith('retarget.o'):
            retargeting = o
    objects.remove(retargeting)
    toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed")
    toolchain.copy_files(retargeting, BUILD_TOOLCHAIN)
Exemplo n.º 34
0
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1):
    """ Function returns True is library was built and false if building was skipped """
    # 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 '')
        return False

    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify)
    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)

    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, 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)
    return True
Exemplo n.º 35
0
def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None, inc_dirs=None, inc_dirs_ext=None,
         jobs=1, silent=False, report=None, properties=None, extra_verbose=False):
    """ src_path: the path of the source directory
    build_path: the path of the build directory
    target: ['LPC1768', 'LPC11U24', 'LPC2368']
    toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CR']
    library_paths: List of paths to additional libraries
    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
    inc_dirs_ext: additional include directories which should be copied to library directory
    """
    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
        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.upper(), target.name, toolchain_name))

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

        # Add extra include directories / files which are required by library
        # This files usually are not in the same directory as source files so
        # previous scan will not include them
        if inc_dirs_ext is not None:
            for inc_ext in inc_dirs_ext:
                resources.append(toolchain.scan_resources(inc_ext))

        # 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)

        if inc_dirs:
            dependencies_include_dir.extend(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)

        # Copy Headers
        for resource in resources:
            toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
        dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)

        # Compile Sources
        objects = []
        for resource in resources:
            objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))

        needed_update = toolchain.build_library(objects, bin_path, name)

        if report != None and needed_update:
            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)

    except Exception, e:
        if report != None:
            end = time()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 36
0
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"
        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, id_name)

    # 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)

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

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

        if report != None and needed_update:
            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()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 37
0
 def __gen_dir(self, dirname):
     settings = join(self.inputDir, dirname)
     mkdir(settings)
Exemplo n.º 38
0
def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, options=None, verbose=False, clean=False, macros=None, notify=None, jobs=1):
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify)
    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())
    tmp_file.writelines(line + '\n' for line in target_cpp_sources.split())
    tmp_file.writelines(line + '\n' for line in mbed_c_sources.split())
    tmp_file.writelines(line + '\n' for line in mbed_cpp_sources.split())
    tmp_file.close()
    check_cmd += ["--file-list=%s"% tmp_file.name]

    _stdout, _stderr, _rc = run_cmd_ext(check_cmd)
    if verbose:
        print _stdout
    print _stderr
Exemplo n.º 39
0
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)

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

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

        if report != None and needed_update:
            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()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 40
0
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):
    """ This function builds project. Project can be for example one test / UT
    """
    # Toolchain instance
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros, silent, extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean
    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:]))
    PROJECT_BASENAME = basename(src_paths[0])

    if name is None:
        # We will use default project name based on project folder name
        name = PROJECT_BASENAME
        toolchain.info("Building project %s (%s, %s)" % (PROJECT_BASENAME.upper(), 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_BASENAME.upper(), name, target.name, toolchain_name))


    if report != None:
        start = time()
        id_name = project_id.upper()
        description = project_description
        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, id_name)

    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)

        # 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, needed_update = toolchain.link_program(resources, build_path, name)

        if report != None and needed_update:
            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 res

    except Exception, e:
        if report != None:
            end = time()
            cur_result["result"] = "FAIL"
            cur_result["elapsed_time"] = end - start

            toolchain_output = toolchain.get_output()
            if toolchain_output:
                cur_result["output"] += toolchain_output

            cur_result["output"] += str(e)

            add_result_to_report(report, cur_result)

        # Let Exception propagate
        raise e
Exemplo n.º 41
0
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):
    """ 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)
    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
Exemplo n.º 42
0
def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, options=None, verbose=False, clean=False, macros=None, notify=None):
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify)
    toolchain.VERBOSE = verbose
    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())
    tmp_file.writelines(line + '\n' for line in target_cpp_sources.split())
    tmp_file.writelines(line + '\n' for line in mbed_c_sources.split())
    tmp_file.writelines(line + '\n' for line in mbed_cpp_sources.split())
    tmp_file.close()
    check_cmd += ["--file-list=%s"% tmp_file.name]

    _stdout, _stderr, _rc = run_cmd_ext(check_cmd)
    if verbose:
        print _stdout
    print _stderr
Exemplo n.º 43
0
 def relative_object_path(self, build_path, base_dir, source):
     source_dir, name, _ = split_path(source)
     obj_dir = join(build_path, relpath(source_dir, base_dir))
     mkdir(obj_dir)
     return join(obj_dir, name + '.o')
Exemplo n.º 44
0
def build_library(src_paths, build_path, target, toolchain_name,
         dependencies_paths=None, options=None, name=None, clean=False,
         notify=None, verbose=False, macros=None, inc_dirs=None, jobs=1):
    """ src_path: the path of the source directory
    build_path: the path of the build directory
    target: ['LPC1768', 'LPC11U24', 'LPC2368']
    toolchain: ['ARM', 'uARM', 'GCC_ARM', 'GCC_CS', 'GCC_CR']
    library_paths: List of paths to additional libraries
    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"""
    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)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean

    # The first path will give the name to the library
    name = basename(src_paths[0])
    toolchain.info("Building 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)

    if inc_dirs:
        dependencies_include_dir.extend(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)

    # Copy Headers
    for resource in resources:
        toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
    dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)

    # Compile Sources
    objects = []
    for resource in resources:
        objects.extend(toolchain.compile_sources(resource, tmp_path, dependencies_include_dir))

    toolchain.build_library(objects, bin_path, name)
Exemplo n.º 45
0
 toolchain.info("\n>>> BUILD LIBRARY %s (%s, %s)" % (name.upper(), target, toolchain_name))
 
 # Scan Resources
 resources = []
 for src_path in src_paths:
     resources.append(toolchain.scan_resources(src_path))
 
 # Just for the include paths
 lib_resources = Resources()
 if libraries_paths is not None:
     for path in libraries_paths:
         lib_resources.add(toolchain.scan_resources(path))
 
 # 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)
 
 # Copy Files
 for resource in resources:
     files_to_be_copied = resource.headers
     if resource.linker_script is not None:
         # Linker script
         files_to_be_copied.append(resource.linker_script)
     toolchain.copy_files(resource.base_path, build_path, files_to_be_copied)
 
 # Compile sources
 objects = []
 for resource in resources:
Exemplo n.º 46
0
def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None, notify=None):
    """ Function returns True is library was built and false if building was skipped """
    # Check toolchain support
    if toolchain_name not in target.supported_toolchains:
        print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name)
        return False

    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify)
    toolchain.VERBOSE = verbose
    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("\n>>> BUILD 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)

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

    # mbed
    toolchain.info("\n>>> BUILD 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, 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)
    return True
Exemplo n.º 47
0
                   (name.upper(), target.name, toolchain_name))

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

    # Just for the include paths
    lib_resources = Resources()
    if libraries_paths is not None:
        for path in libraries_paths:
            lib_resources.add(toolchain.scan_resources(path))

    # 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)

    # Copy Files
    for resource in resources:
        files_to_be_copied = resource.headers
        if resource.linker_script is not None:
            # Linker script
            files_to_be_copied.append(resource.linker_script)
        toolchain.copy_files(resource.base_path, build_path,
                             files_to_be_copied)

    # Compile sources
    objects = []
Exemplo n.º 48
0
 def __gen_dir(self, dirname):
     settings = join(self.inputDir, dirname)
     mkdir(settings)