Ejemplo n.º 1
0
 def version_check(self):
     stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
     msg = None
     match = self.GCC_VERSION_RE.search(stdout.encode("utf-8"))
     if match:
         found_version = LooseVersion(match.group(0).decode('utf-8'))
     else:
         found_version = None
     min_ver, max_ver = self.GCC_RANGE
     if found_version and (found_version < min_ver
                           or found_version >= max_ver):
         msg = ("Compiler version mismatch: Have {}; "
                "expected version >= {} and < {}".format(
                    found_version, min_ver, max_ver))
     elif not match:
         msg = ("Compiler version mismatch: Could not detect version; "
                "expected version >= {} and < {}".format(min_ver, max_ver))
     if msg:
         self.notify.cc_info({
             "message": msg,
             "file": "",
             "line": "",
             "col": "",
             "severity": "Warning",
         })
Ejemplo n.º 2
0
def compile_worker(job):
    results = []
    for command in job["commands"]:
        try:
            _, _stderr, _rc = run_cmd(command, job["work_dir"])
        except KeyboardInterrupt as e:
            raise ToolException

        results.append({"code": _rc, "output": _stderr, "command": command})

    return {"source": job["source"], "object": job["object"], "commands": job["commands"], "results": results}
Ejemplo n.º 3
0
 def check_if_obj_from_asm(self, obj_file):
     """Check if obj_file was build by the GNU Assembler."""
     dw_producer = ''
     cmd = [self.objdump, '--dwarf=info', obj_file]
     stdout, stderr, rc = run_cmd(cmd, work_dir=getcwd(), chroot=self.CHROOT)
     if rc != 0:
         return False
     match = self.DWARF_PRODUCER_RE.search(stdout)
     if match:
         dw_producer = match.group('producer')
     return 'GNU AS' in dw_producer
Ejemplo n.º 4
0
def icetea_tests(target, tcdir, verbose):
    command = ['icetea', '--tcdir', tcdir, '--list', '--json', '--platform_filter', target] \
              + (['-v'] if verbose else [])

    stdout, stderr, returncode = run_cmd(command)

    if returncode != 0:
        raise Exception(
            "Error when running icetea. \ncwd:{} \nCommand:'{}' \noutput:{}".
            format(os.getcwd(), ' '.join(command), stderr.decode()))

    return json.loads(stdout)
Ejemplo n.º 5
0
def compile_worker(job):
    results = []
    for command in job['commands']:
        _, _stderr, _rc = run_cmd(command, job['work_dir'])
        results.append({'code': _rc, 'output': _stderr, 'command': command})

    return {
        'source': job['source'],
        'object': job['object'],
        'commands': job['commands'],
        'results': results
    }
Ejemplo n.º 6
0
    def default_cmd(self, command):
        _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
        self.debug("Return: %s"% _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s"% output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s"% error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
Ejemplo n.º 7
0
    def default_cmd(self, command):
        _stdout, _stderr, _rc = run_cmd(command, work_dir=getcwd(), chroot=self.CHROOT)
        self.debug("Return: %s"% _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s"% output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s"% error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
Ejemplo n.º 8
0
    def default_cmd(self, command):
        self.debug("Command: %s" % ' '.join(command))
        _stdout, _stderr, _rc = run_cmd(command)

        self.debug("Return: %s" % _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s" % output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s" % error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
Ejemplo n.º 9
0
    def default_cmd(self, command):
        self.debug("Command: %s" % " ".join(command))
        _stdout, _stderr, _rc = run_cmd(command)

        self.debug("Return: %s" % _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s" % output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s" % error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
Ejemplo n.º 10
0
    def version_check(self):
        # The --ide=mbed removes an instability with checking the version of
        # the ARMC6 binary that comes with Mbed Studio.
        # NOTE: the --ide=mbed argument is only for use with Mbed OS
        stdout, _, retcode = run_cmd(
            [self.cc[0], "--vsn", "--ide=mbed"],
            redirect=True
        )
        msg = None
        min_ver, max_ver = self.ARMCC_RANGE
        output = stdout.encode("utf-8")
        match = self.ARMCC_VERSION_RE.search(output)
        if match:
            found_version = LooseVersion(match.group(1).decode("utf-8"))
        else:
            found_version = None
        min_ver, max_ver = self.ARMCC_RANGE
        if found_version and (found_version < min_ver
                              or found_version >= max_ver):
            msg = ("Compiler version mismatch: Have {}; "
                   "expected version >= {} and < {}"
                   .format(found_version, min_ver, max_ver))
        elif not match or len(match.groups()) != 1:
            msg = ("Compiler version mismatch: Could not detect version; "
                   "expected version >= {} and < {}"
                   .format(min_ver, max_ver))

        if msg:
            self.notify.cc_info({
                "message": msg,
                "file": "",
                "line": "",
                "col": "",
                "severity": "WARNING",
            })

        msg = None
        match = self.ARMCC_PRODUCT_RE.search(output)
        if match:
            self.product_name = match.group(1).decode("utf-8")
        else:
            self.product_name = None

        if not match or len(match.groups()) != 1:
            msg = (
                "Could not detect product name: defaulting to professional "
                "version of ARMC6"
            )
Ejemplo n.º 11
0
def compile_worker(job):
    results = []
    for command in job['commands']:
        try:
            _, _stderr, _rc = run_cmd(command, job['work_dir'])
        except KeyboardInterrupt as e:
            raise ToolException

        results.append({'code': _rc, 'output': _stderr, 'command': command})

    return {
        'source': job['source'],
        'object': job['object'],
        'commands': job['commands'],
        'results': results
    }
Ejemplo n.º 12
0
def compile_worker(job):
    results = []
    for command in job['commands']:
        _, _stderr, _rc = run_cmd(command, job['work_dir'])
        results.append({
            'code': _rc,
            'output': _stderr,
            'command': command
        })

    return {
        'source': job['source'],
        'object': job['object'],
        'commands': job['commands'],
        'results': results
    }
def icetea_tests(target, tcdir, verbose):
    if not os.path.exists(tcdir):
        raise Exception("Icetea run error: No TEST_APPS folder in {}".format(
            os.path.curdir))

    command = ['icetea', '--tcdir', tcdir, '--list', '--json', '--platform_filter', target] \
              + (['-v'] if verbose else [])

    stdout, stderr, returncode = run_cmd(command)

    if returncode != 0:
        additional_information = "\ncwd:{} \nCommand:'{}' \noutput:{}".format(
            os.getcwd(), ' '.join(command), stderr.decode())
        raise Exception(
            "Error when running icetea. {}".format(additional_information))

    return json.loads(stdout)
Ejemplo n.º 14
0
    def default_cmd(self, command):
        self.debug("Command: %s"% ' '.join(command))
        _stdout, _stderr, _rc = run_cmd(command)
        # Print all warning / erros from stderr to console output
        for error_line in _stderr.splitlines():
            print error_line

        self.debug("Return: %s"% _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s"% output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s"% error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
Ejemplo n.º 15
0
    def default_cmd(self, command):
        self.debug("Command: %s" % ' '.join(command))
        _stdout, _stderr, _rc = run_cmd(command)
        # Print all warning / erros from stderr to console output
        for error_line in _stderr.splitlines():
            print error_line

        self.debug("Return: %s" % _rc)

        for output_line in _stdout.splitlines():
            self.debug("Output: %s" % output_line)
        for error_line in _stderr.splitlines():
            self.debug("Errors: %s" % error_line)

        if _rc != 0:
            for line in _stderr.splitlines():
                self.tool_error(line)
            raise ToolException(_stderr)
 def version_check(self):
     stdout, _, retcode = run_cmd([self.cc[0], "--version"], redirect=True)
     msg = None
     match = self.IAR_VERSION_RE.search(stdout)
     found_version = match.group(1).decode("utf-8") if match else None
     if found_version and LooseVersion(found_version) != self.IAR_VERSION:
         msg = "Compiler version mismatch: Have {}; expected {}".format(
             found_version, self.IAR_VERSION)
     elif not match or len(match.groups()) != 1:
         msg = ("Compiler version mismatch: Could Not detect compiler "
                "version; expected {}".format(self.IAR_VERSION))
     if msg:
         self.notify.cc_info({
             "message": msg,
             "file": "",
             "line": "",
             "col": "",
             "severity": "Warning",
         })
Ejemplo n.º 17
0
 def publish(self):
     # The maintainer has to evaluate the changes first and explicitly accept them
     self.run_and_print(['hg', 'addremove'], cwd=self.path)
     stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path)
     if stdout == '':
         print "No changes"
         return False
     print stdout
     if quiet:
         commit = 'Y'
     else:
         commit = raw_input(push_remote and "Do you want to commit and push? Y/N: " or "Do you want to commit? Y/N: ")
     if commit == 'Y':
         args = ['hg', 'commit', '-u', MBED_ORG_USER]
         if commit_msg:
             args = args + ['-m', commit_msg]
         self.run_and_print(args, cwd=self.path)
         if push_remote:
             self.run_and_print(['hg', 'push'], cwd=self.path)
     return True
Ejemplo n.º 18
0
 def publish(self):
     # The maintainer has to evaluate the changes first and explicitly accept them
     self.run_and_print(['hg', 'addremove'], cwd=self.path)
     stdout, _, _ = run_cmd(['hg', 'status'], wd=self.path)
     if stdout == '':
         print "No changes"
         return False
     print stdout
     if quiet:
         commit = 'Y'
     else:
         commit = raw_input(push_remote and "Do you want to commit and push? Y/N: " or "Do you want to commit? Y/N: ")
     if commit == 'Y':
         args = ['hg', 'commit', '-u', MBED_ORG_USER]
         if commit_msg:
             args = args + ['-m', commit_msg]
         self.run_and_print(args, cwd=self.path)
         if push_remote:
             self.run_and_print(['hg', 'push'], cwd=self.path)
     return True
Ejemplo n.º 19
0
def compile_worker(job):
    results = []
    for command in job['commands']:
        try:
            _, _stderr, _rc = run_cmd(command, job['work_dir'])
        except KeyboardInterrupt as e:
            raise ToolException

        results.append({
            'code': _rc,
            'output': _stderr,
            'command': command
        })

    return {
        'source': job['source'],
        'object': job['object'],
        'commands': job['commands'],
        'results': results
    }
Ejemplo n.º 20
0
 def publish(self):
     # The maintainer has to evaluate the changes first and explicitly accept them
     self.run_and_print(["hg", "addremove"], cwd=self.path)
     stdout, _, _ = run_cmd(["hg", "status"], work_dir=self.path)
     if stdout == "":
         print "No changes"
         return False
     print stdout
     if quiet:
         commit = "Y"
     else:
         commit = raw_input(
             push_remote and "Do you want to commit and push? Y/N: " or "Do you want to commit? Y/N: "
         )
     if commit == "Y":
         args = ["hg", "commit", "-u", MBED_ORG_USER]
         if commit_msg:
             args = args + ["-m", commit_msg]
         self.run_and_print(args, cwd=self.path)
         if push_remote:
             self.run_and_print(["hg", "push"], cwd=self.path)
     return True
Ejemplo n.º 21
0
Archivo: arm.py Proyecto: snej/mbed-os
    def version_check(self):
        stdout, _, retcode = run_cmd([self.cc[0], "--vsn"], redirect=True)
        msg = None
        min_ver, max_ver = self.ARMCC_RANGE
        match = self.ARMCC_VERSION_RE.search(stdout)
        found_version = LooseVersion(match.group(1)) if match else None
        min_ver, max_ver = self.ARMCC_RANGE
        if found_version and (found_version < min_ver
                              or found_version >= max_ver):
            msg = ("Compiler version mismatch: Have {}; "
                   "expected version >= {} and < {}".format(
                       found_version, min_ver, max_ver))
        elif not match or len(match.groups()) != 1:
            msg = ("Compiler version mismatch: Could not detect version; "
                   "expected version >= {} and < {}".format(min_ver, max_ver))

        if msg:
            self.notify.cc_info({
                "message": msg,
                "file": "",
                "line": "",
                "col": "",
                "severity": "ERROR",
            })
Ejemplo n.º 22
0
 def run_and_print(command, cwd):
     stdout, _, _ = run_cmd(command, work_dir=cwd, redirect=True)
     print (stdout)
Ejemplo n.º 23
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, extra_verbose=False):
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify, extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    # Common Sources
    mbed_resources = toolchain.scan_resources(MBED_COMMON)

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

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

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

    # We need to pass some parames via file to avoid "command line too long in some OSs"
    tmp_file = tempfile.NamedTemporaryFile(delete=False)
    tmp_file.writelines(line + '\n' for line in target_c_sources.split())
    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
Ejemplo n.º 24
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,
                         extra_verbose=False):
    # Toolchain
    toolchain = TOOLCHAIN_CLASSES[toolchain_name](target,
                                                  options,
                                                  macros=macros,
                                                  notify=notify,
                                                  extra_verbose=extra_verbose)
    toolchain.VERBOSE = verbose
    toolchain.jobs = jobs
    toolchain.build_all = clean

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

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

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

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

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

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

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

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

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

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

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

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

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

    # Copy files before analysis
    toolchain.copy_files(hal_implementation.headers +
                         hal_implementation.hex_files,
                         BUILD_TARGET,
                         resources=hal_implementation)
    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
Ejemplo n.º 25
0
 def run_and_print(command, cwd):
     stdout, _, _ = run_cmd(command, work_dir=cwd, redirect=True)
     print(stdout)