示例#1
0
    def report_errors(self):
        """Report statistics about the computation and create a CSV file
        containing the list or errors found during the analysis"""

        csv_report = os.path.join(self.args.infer_out,
                                  utils.CSV_REPORT_FILENAME)
        bugs_out = os.path.join(self.args.infer_out, utils.BUGS_FILENAME)
        procs_report = os.path.join(self.args.infer_out, 'procs.csv')

        infer_print_cmd = [utils.get_cmd_in_bin_dir('InferPrint')]
        infer_print_options = [
            '-q', '-results_dir', self.args.infer_out, '-bugs', csv_report,
            '-procs', procs_report, '-analyzer', self.args.analyzer
        ]
        if self.javac.annotations_out is not None:
            infer_print_options += [
                '-local_config', self.javac.annotations_out
            ]
        exit_status = subprocess.check_call(infer_print_cmd +
                                            infer_print_options)
        if exit_status != os.EX_OK:
            logging.error('Error with InferPrint with the command: ' +
                          infer_print_cmd)
        else:
            clean_csv(self.args, csv_report)
            self.update_stats_with_warnings(csv_report)
            utils.create_json_report(self.args.infer_out)

            print('\n')
            if not self.args.buck:
                print_errors(csv_report, bugs_out)

        return exit_status
示例#2
0
    def report_errors(self):
        """Report statistics about the computation and create a CSV file
        containing the list or errors found during the analysis"""

        csv_report = os.path.join(self.args.infer_out, utils.CSV_REPORT_FILENAME)
        bugs_out = os.path.join(self.args.infer_out, utils.BUGS_FILENAME)
        procs_report = os.path.join(self.args.infer_out, "procs.csv")

        infer_print_cmd = [utils.get_cmd_in_bin_dir("InferPrint")]
        infer_print_options = [
            "-q",
            "-results_dir",
            self.args.infer_out,
            "-bugs",
            csv_report,
            "-procs",
            procs_report,
            "-analyzer",
            self.args.analyzer,
        ]

        exit_status = subprocess.check_call(infer_print_cmd + infer_print_options)
        if exit_status != os.EX_OK:
            logging.error("Error with InferPrint with the command: " + infer_print_cmd)
        else:
            clean_csv(self.args, csv_report)
            self.update_stats(csv_report)
            utils.create_json_report(self.args.infer_out)

            print("\n")
            if not self.args.buck:
                print_errors(csv_report, bugs_out)

        return exit_status
示例#3
0
def get_infer_version():
    try:
        return subprocess.check_output(
            [utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), '-version'])
    except:
        print("Failed to run {0} binary, exiting".format(INFER_ANALYZE_BINARY))
        sys.exit(os.EX_UNAVAILABLE)
示例#4
0
    def run_infer_frontend(self):

        infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')]

        if not self.args.absolute_paths:
            infer_cmd += ['-project_root', self.args.project_root]

        infer_cmd += [
            '-results_dir',
            self.args.infer_out,
            '-verbose_out',
            self.javac.verbose_out,
        ]

        if os.path.isfile(utils.MODELS_JAR):
            infer_cmd += ['-models', utils.MODELS_JAR]

        infer_cmd.append('-no-static_final')

        if self.args.debug:
            infer_cmd.append('-debug')
        if self.args.analyzer == TRACING:
            infer_cmd.append('-tracing')

        return run_command(infer_cmd, self.args.debug,
                           self.javac.original_arguments, 'frontend',
                           self.args.analyzer)
示例#5
0
文件: inferlib.py 项目: hckhanh/infer
    def run_infer_frontend(self):

        infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')]

        if not self.args.absolute_paths:
            infer_cmd += ['-project_root', self.args.project_root]

        infer_cmd += [
            '-results_dir', self.args.infer_out,
            '-verbose_out', self.javac.verbose_out,
        ]

        if os.path.isfile(utils.MODELS_JAR):
            infer_cmd += ['-models', utils.MODELS_JAR]

        infer_cmd.append('-no-static_final')

        if self.args.debug:
            infer_cmd.append('-debug')
        if self.args.analyzer == TRACING:
            infer_cmd.append('-tracing')

        return run_command(
            infer_cmd,
            self.args.debug,
            self.javac.original_arguments,
            'frontend',
            self.args.analyzer
        )
示例#6
0
文件: buck.py 项目: didiao11300/infer
    def capture(self):
        # BuckAnalyze is a special case, and we run the analysis from here
        capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
        if self.args.infer_out is not None:
            capture_cmd += ['--out', self.args.infer_out]
        if self.args.debug:
            capture_cmd.append('-g')
        if self.args.no_filtering:
            capture_cmd.append('--no-filtering')
        if self.args.verbose:
            capture_cmd.append('--verbose')
        if self.args.no_cache:
            capture_cmd.append('--no-cache')
        if self.args.print_harness:
            capture_cmd.append('--print-harness')

        capture_cmd += self.cmd
        capture_cmd += ['--analyzer', self.args.analyzer]
        try:
            subprocess.check_call(capture_cmd)
            return os.EX_OK
        except subprocess.CalledProcessError as exc:
            if self.args.debug:
                traceback.print_exc()
            return exc.returncode
示例#7
0
文件: buck.py 项目: nbstar/infer
    def capture(self):
        # BuckAnalyze is a special case, and we run the analysis from here
        capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
        if self.args.infer_out is not None:
            capture_cmd += ['--out', self.args.infer_out]
        if self.args.debug:
            capture_cmd.append('-g')
        if self.args.no_filtering:
            capture_cmd.append('--no-filtering')
        if self.args.verbose:
            capture_cmd.append('--verbose')
        if self.args.no_cache:
            capture_cmd.append('--no-cache')
        if self.args.print_harness:
            capture_cmd.append('--print-harness')

        capture_cmd += self.cmd
        capture_cmd += ['--analyzer', self.args.analyzer]
        try:
            subprocess.check_call(capture_cmd)
            return os.EX_OK
        except subprocess.CalledProcessError as exc:
            if self.args.debug:
                traceback.print_exc()
            return exc.returncode
示例#8
0
文件: inferlib.py 项目: hckhanh/infer
def get_infer_version():
    try:
        return subprocess.check_output([
            utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), '-version'])
    except:
        print("Failed to run {0} binary, exiting".
              format(INFER_ANALYZE_BINARY))
        sys.exit(os.EX_UNAVAILABLE)
示例#9
0
文件: buck.py 项目: pauljriley/infer
 def capture_without_flavors(self):
     # BuckAnalyze is a special case, and we run the analysis from here
     capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
     if self.args.infer_out is not None:
         capture_cmd += ['--out', self.args.infer_out]
     if self.args.debug:
         capture_cmd.append('-g')
     if self.args.no_filtering:
         capture_cmd.append('--no-filtering')
     if self.args.verbose:
         capture_cmd.append('--verbose')
     if self.args.no_cache:
         capture_cmd.append('--no-cache')
     if self.args.print_harness:
         capture_cmd.append('--print-harness')
     capture_cmd += self.cmd[2:]  # TODO: make extraction of targets smarter
     capture_cmd += ['--analyzer', self.args.analyzer]
     subprocess.check_call(capture_cmd)
     return os.EX_OK
示例#10
0
文件: javac.py 项目: 0x73/infer
    def capture(self):
        # run inferJ only in capture mode
        # pass all the frontend args (if any)
        capture_cmd = [utils.get_cmd_in_bin_dir('inferJ')]
        capture_cmd += ['--out', self.args.infer_out]
        capture_cmd += ['--analyzer', self.args.analyzer]
        if self.args.no_filtering:
            capture_cmd.append('--no-filtering')
        if self.args.debug:
            capture_cmd.append('-g')
        capture_cmd += self.cmd

        try:
            subprocess.check_call(capture_cmd)
            return os.EX_OK
        except subprocess.CalledProcessError as exc:
            if self.args.debug:
                traceback.print_exc()
            return exc.returncode
示例#11
0
文件: buck.py 项目: ryoon/infer
 def capture_without_flavors(self):
     # BuckAnalyze is a special case, and we run the analysis from here
     capture_cmd = [utils.get_cmd_in_bin_dir('BuckAnalyze')]
     if self.args.infer_out is not None:
         capture_cmd += ['--out', self.args.infer_out]
     if self.args.debug:
         capture_cmd.append('-g')
     if self.args.no_filtering:
         capture_cmd.append('--no-filtering')
     if self.args.verbose:
         capture_cmd.append('--verbose')
     if self.args.no_cache:
         capture_cmd.append('--no-cache')
     if self.args.print_harness:
         capture_cmd.append('--print-harness')
     capture_cmd += self.cmd[2:]  # TODO: make extraction of targets smarter
     capture_cmd += ['--analyzer', self.args.analyzer]
     subprocess.check_call(capture_cmd)
     return os.EX_OK
示例#12
0
    def run_infer_frontend(self):

        infer_cmd = [utils.get_cmd_in_bin_dir("InferJava")]

        if self.args.buck:
            infer_cmd += ["-project_root", os.getcwd()]

        infer_cmd += ["-results_dir", self.args.infer_out, "-verbose_out", self.javac.verbose_out]

        if os.path.isfile(utils.MODELS_JAR):
            infer_cmd += ["-models", utils.MODELS_JAR]

        infer_cmd.append("-no-static_final")

        if self.args.debug:
            infer_cmd.append("-debug")
        if self.args.analyzer == TRACING:
            infer_cmd.append("-tracing")

        return run_command(infer_cmd, self.args.debug, self.javac.original_arguments, "frontend", self.args.analyzer)
示例#13
0
文件: inferlib.py 项目: hckhanh/infer
    def report_errors(self):
        """Report statistics about the computation and create a CSV file
        containing the list or errors found during the analysis"""

        csv_report = os.path.join(self.args.infer_out,
                                  utils.CSV_REPORT_FILENAME)
        bugs_out = os.path.join(self.args.infer_out,
                                utils.BUGS_FILENAME)
        procs_report = os.path.join(self.args.infer_out, 'procs.csv')

        infer_print_cmd = [utils.get_cmd_in_bin_dir('InferPrint')]
        infer_print_options = [
            '-q',
            '-results_dir', self.args.infer_out,
            '-bugs', csv_report,
            '-procs', procs_report,
            '-analyzer', self.args.analyzer
        ]
        if self.javac.annotations_out is not None:
            infer_print_options += [
                '-local_config', self.javac.annotations_out]

        exit_status = subprocess.check_call(
            infer_print_cmd + infer_print_options
        )
        if exit_status != os.EX_OK:
            logging.error('Error with InferPrint with the command: '
                          + infer_print_cmd)
        else:
            clean_csv(self.args, csv_report)
            self.update_stats_with_warnings(csv_report)
            utils.create_json_report(self.args.infer_out)

            print('\n')
            if not self.args.buck:
                print_errors(csv_report, bugs_out)

        return exit_status
示例#14
0
    def analyze(self):
        logging.info('Starting analysis')
        infer_analyze = [
            utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), '-results_dir',
            self.args.infer_out
        ]
        infer_options = []

        # remove specs if possible so that old issues are less likely
        # to be reported
        infer_options += ['-allow_specs_cleanup']

        if self.args.analyzer == ERADICATE:
            infer_options += ['-checkers', '-eradicate']
        elif self.args.analyzer == CHECKERS:
            infer_options += ['-checkers']
        else:
            if self.args.analyzer == TRACING:
                infer_options.append('-tracing')
            if os.path.isfile(utils.MODELS_JAR):
                infer_options += ['-models', utils.MODELS_JAR]

        if self.args.infer_cache:
            infer_options += ['-infer_cache', self.args.infer_cache]

        if self.args.objc_ml_buckets:
            infer_options += ['-objc_ml_buckets', self.args.objc_ml_buckets]

        if self.args.notest:
            infer_options += ['-notest']

        if self.args.debug:
            infer_options += [
                '-developer_mode',
                '-html',
                '-dotty',
                '-print_types',
                '-trace_error',
                '-print_buckets',
                # '-notest',
            ]

        if self.args.incremental:
            if self.args.changed_only:
                infer_options.append('-incremental_changed_only')
            else:
                infer_options.append('-incremental')

        if self.args.specs_dirs:
            infer_options += self.args.specs_dirs

        exit_status = os.EX_OK

        if self.args.buck:
            infer_options += ['-project_root', os.getcwd(), '-java']
            if self.javac.args.classpath is not None:
                for path in self.javac.args.classpath.split(os.pathsep):
                    if os.path.isfile(path):
                        infer_options += ['-ziplib', os.path.abspath(path)]
        elif self.args.project_root:
            infer_options += ['-project_root', self.args.project_root]

        if self.args.multicore == 1:
            analyze_cmd = infer_analyze + infer_options
            exit_status = run_command(analyze_cmd, self.args.debug,
                                      self.javac.original_arguments,
                                      'analysis', self.args.analyzer)

        else:
            if self.args.analyzer in [ERADICATE, CHECKERS]:
                infer_analyze.append('-intraprocedural')

            os.environ['INFER_OPTIONS'] = ' '.join(infer_options)

            multicore_dir = os.path.join(self.args.infer_out, 'multicore')
            pwd = os.getcwd()
            if os.path.isdir(multicore_dir):
                shutil.rmtree(multicore_dir)
            os.mkdir(multicore_dir)
            os.chdir(multicore_dir)
            analyze_cmd = infer_analyze + ['-makefile', 'Makefile']
            analyze_cmd += infer_options
            makefile_status = run_command(analyze_cmd, self.args.debug,
                                          self.javac.original_arguments,
                                          'create_makefile',
                                          self.args.analyzer)
            exit_status += makefile_status
            if makefile_status == os.EX_OK:
                make_cmd = ['make', '-k', '-j', str(self.args.multicore)]
                if not self.args.debug:
                    make_cmd += ['-s']
                make_status = run_command(make_cmd, self.args.debug,
                                          self.javac.original_arguments,
                                          'run_makefile', self.args.analyzer)
                os.chdir(pwd)
                exit_status += make_status

        if self.args.buck and exit_status == os.EX_OK:
            clean(self.args.infer_out, self.javac.annotations_out)

        return exit_status
示例#15
0
    def analyze(self):
        logging.info("Starting analysis")
        infer_analyze = [utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY), "-results_dir", self.args.infer_out]
        infer_options = []

        # remove specs if possible so that old issues are less likely
        # to be reported
        infer_options += ["-allow_specs_cleanup"]

        if self.args.analyzer == ERADICATE:
            infer_options += ["-checkers", "-eradicate"]
        elif self.args.analyzer == CHECKERS:
            infer_options += ["-checkers"]
        else:
            if self.args.analyzer == TRACING:
                infer_options.append("-tracing")
            if os.path.isfile(utils.MODELS_JAR):
                infer_options += ["-models", utils.MODELS_JAR]

        if self.args.infer_cache:
            infer_options += ["-infer_cache", self.args.infer_cache]

        if self.args.objc_ml_buckets:
            infer_options += ["-objc_ml_buckets", self.args.objc_ml_buckets]

        if self.args.notest:
            infer_options += ["-notest"]

        if self.args.debug:
            infer_options += [
                "-developer_mode",
                "-html",
                "-dotty",
                "-print_types",
                "-trace_error",
                "-print_buckets",
                # '-notest',
            ]

        if self.args.specs_dirs:
            infer_options += self.args.specs_dirs

        exit_status = os.EX_OK

        if self.args.buck:
            infer_options += ["-project_root", os.getcwd(), "-java"]
            if self.javac.args.classpath is not None:
                for path in self.javac.args.classpath.split(os.pathsep):
                    if os.path.isfile(path):
                        infer_options += ["-ziplib", os.path.abspath(path)]
        elif self.args.project_root:
            infer_options += ["-project_root", self.args.project_root]

        if self.args.multicore == 1:
            analyze_cmd = infer_analyze + infer_options
            exit_status = run_command(
                analyze_cmd, self.args.debug, self.javac.original_arguments, "analysis", self.args.analyzer
            )

        else:
            if self.args.analyzer in [ERADICATE, CHECKERS]:
                infer_analyze.append("-intraprocedural")

            os.environ["INFER_OPTIONS"] = " ".join(infer_options)

            multicore_dir = os.path.join(self.args.infer_out, "multicore")
            pwd = os.getcwd()
            if os.path.isdir(multicore_dir):
                shutil.rmtree(multicore_dir)
            os.mkdir(multicore_dir)
            os.chdir(multicore_dir)
            analyze_cmd = infer_analyze + ["-makefile", "Makefile"]
            analyze_cmd += infer_options
            makefile_status = run_command(
                analyze_cmd, self.args.debug, self.javac.original_arguments, "create_makefile", self.args.analyzer
            )
            exit_status += makefile_status
            if makefile_status == os.EX_OK:
                make_cmd = ["make", "-k", "-j", str(self.args.multicore)]
                if not self.args.debug:
                    make_cmd += ["-s"]
                make_status = run_command(
                    make_cmd, self.args.debug, self.javac.original_arguments, "run_makefile", self.args.analyzer
                )
                os.chdir(pwd)
                exit_status += make_status

        if self.args.buck and exit_status == os.EX_OK:
            clean_infer_out(self.args.infer_out)

        cfgs = os.path.join(self.args.infer_out, "captured", "*", "")
        captured_total = len(glob.glob(cfgs))
        captured_plural = "" if captured_total <= 1 else "s"
        print("\n%d file%s analyzed" % (captured_total, captured_plural))

        logging.info("Analyzed file count: %d", captured_total)
        logging.info("Analysis status: %d", exit_status)

        return exit_status
示例#16
0
文件: inferlib.py 项目: hckhanh/infer
    def analyze(self):
        logging.info('Starting analysis')
        infer_analyze = [
            utils.get_cmd_in_bin_dir(INFER_ANALYZE_BINARY),
            '-results_dir',
            self.args.infer_out
        ]
        infer_options = []

        # remove specs if possible so that old issues are less likely
        # to be reported
        infer_options += ['-allow_specs_cleanup']

        if self.args.analyzer == ERADICATE:
            infer_options += ['-checkers', '-eradicate']
        elif self.args.analyzer == CHECKERS:
            infer_options += ['-checkers']
        else:
            if self.args.analyzer == TRACING:
                infer_options.append('-tracing')
            if os.path.isfile(utils.MODELS_JAR):
                infer_options += ['-models', utils.MODELS_JAR]

        if self.args.infer_cache:
            infer_options += ['-infer_cache', self.args.infer_cache]

        if self.args.objc_ml_buckets:
            infer_options += ['-objc_ml_buckets', self.args.objc_ml_buckets]

        if self.args.notest:
            infer_options += ['-notest']

        if self.args.debug:
            infer_options += [
                '-developer_mode',
                '-html',
                '-dotty',
                '-print_types',
                '-trace_error',
                '-print_buckets',
                # '-notest',
            ]

        if self.args.incremental:
            if self.args.changed_only:
                infer_options.append('-incremental_changed_only')
            else:
                infer_options.append('-incremental')

        if self.args.specs_dirs:
            infer_options += self.args.specs_dirs

        exit_status = os.EX_OK

        if self.args.buck:
            infer_options += ['-project_root', os.getcwd(), '-java']
            if self.javac.args.classpath is not None:
                for path in self.javac.args.classpath.split(os.pathsep):
                    if os.path.isfile(path):
                        infer_options += ['-ziplib', os.path.abspath(path)]
        elif self.args.project_root:
            infer_options += ['-project_root', self.args.project_root]

        if self.args.multicore == 1:
            analyze_cmd = infer_analyze + infer_options
            exit_status = run_command(
                analyze_cmd,
                self.args.debug,
                self.javac.original_arguments,
                'analysis',
                self.args.analyzer
            )

        else:
            if self.args.analyzer in [ERADICATE, CHECKERS]:
                infer_analyze.append('-intraprocedural')

            os.environ['INFER_OPTIONS'] = ' '.join(infer_options)

            multicore_dir = os.path.join(self.args.infer_out, 'multicore')
            pwd = os.getcwd()
            if os.path.isdir(multicore_dir):
                shutil.rmtree(multicore_dir)
            os.mkdir(multicore_dir)
            os.chdir(multicore_dir)
            analyze_cmd = infer_analyze + ['-makefile', 'Makefile']
            analyze_cmd += infer_options
            makefile_status = run_command(
                analyze_cmd,
                self.args.debug,
                self.javac.original_arguments,
                'create_makefile',
                self.args.analyzer
            )
            exit_status += makefile_status
            if makefile_status == os.EX_OK:
                make_cmd = ['make', '-k', '-j', str(self.args.multicore)]
                if not self.args.debug:
                    make_cmd += ['-s']
                make_status = run_command(
                    make_cmd,
                    self.args.debug,
                    self.javac.original_arguments,
                    'run_makefile',
                    self.args.analyzer
                )
                os.chdir(pwd)
                exit_status += make_status

        if self.args.buck and exit_status == os.EX_OK:
            clean_infer_out(self.args.infer_out)

        return exit_status