Adding inferconfig support to skip the translation of generated source code

Summary: public
This allow to tell Infer to skip the translation of some files. This is especially useful to skip the translation of some generated files following the syntax:

  > cat .inferconfig
  {
    "skip_translation": [
      {
        "language": "Java",
        "source_contains": "_SHOULD_BE_SKIPPED_"
      }
    ]
  }

Reviewed By: cristianoc

Differential Revision: D2588095

fb-gh-sync-id: 3fda816
master
jrm 9 years ago committed by facebook-github-bot-7
parent abc0e8315e
commit 6f3873aa99

@ -0,0 +1 @@
/Users/jrm/infer/.inferconfig

@ -0,0 +1,20 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// _SHOULD_BE_SKIPPED_
package infer.inferandroidexample;
public class Generated {
static Object returnsNull() {
return null;
}
}

@ -1,3 +1,12 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package infer.inferandroidexample; package infer.inferandroidexample;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
@ -60,4 +69,10 @@ public class MainActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
private void inferShouldNotReport() {
Object o = Generated.returnsNull();
o.toString();
}
} }

@ -1,13 +1,13 @@
[ [
{ {
"file": "app/src/main/java/infer/inferandroidexample/MainActivity.java", "file": "app/src/main/java/infer/inferandroidexample/MainActivity.java",
"line": "20", "line": "29",
"type": "NULL_DEREFERENCE", "type": "NULL_DEREFERENCE",
"procedure": "void MainActivity.onCreate(Bundle)" "procedure": "void MainActivity.onCreate(Bundle)"
}, },
{ {
"file": "app/src/main/java/infer/inferandroidexample/MainActivity.java", "file": "app/src/main/java/infer/inferandroidexample/MainActivity.java",
"line": "37", "line": "46",
"type": "RESOURCE_LEAK", "type": "RESOURCE_LEAK",
"procedure": "void MainActivity.writeToFile()" "procedure": "void MainActivity.writeToFile()"
} }

@ -271,6 +271,7 @@ struct
end (* of module FileOrProcMatcher *) end (* of module FileOrProcMatcher *)
module NeverReturnNull = FileOrProcMatcher(struct module NeverReturnNull = FileOrProcMatcher(struct
let json_key = "never_returning_null" let json_key = "never_returning_null"
end) end)
@ -279,6 +280,11 @@ module ProcMatcher = FileOrProcMatcher(struct
let json_key = "suppress_procedures" let json_key = "suppress_procedures"
end) end)
module SkipTranslationMatcher = FileOrProcMatcher(struct
let json_key = "skip_translation"
end)
let inferconfig () = match !inferconfig_home with let inferconfig () = match !inferconfig_home with
| Some dir -> Filename.concat dir inferconfig_file | Some dir -> Filename.concat dir inferconfig_file
| None -> inferconfig_file | None -> inferconfig_file
@ -311,6 +317,7 @@ let make_proc_filter_from_local_config () =
| None -> ProcMatcher.default_matcher in | None -> ProcMatcher.default_matcher in
fun pname -> not (filter DB.source_file_empty pname) fun pname -> not (filter DB.source_file_empty pname)
let filters_from_inferconfig inferconfig : filters = let filters_from_inferconfig inferconfig : filters =
let path_filter = let path_filter =
let whitelist_filter : path_filter = let whitelist_filter : path_filter =

@ -41,5 +41,10 @@ module NeverReturnNull : sig
val load_matcher : string -> matcher val load_matcher : string -> matcher
end end
module SkipTranslationMatcher : sig
type matcher = DB.source_file -> Procname.t -> bool
val load_matcher : string -> matcher
end
(** Load the config file and list the files to report on *) (** Load the config file and list the files to report on *)
val test: unit -> unit val test: unit -> unit

@ -63,6 +63,10 @@ type detail_level =
| NON_VERBOSE | NON_VERBOSE
| SIMPLE | SIMPLE
let empty = OBJC_BLOCK ""
let is_verbose v = let is_verbose v =
match v with match v with
| VERBOSE -> true | VERBOSE -> true

@ -25,6 +25,8 @@ type objc_method_kind =
| Instance_objc_method (* for instance methods in ObjC *) | Instance_objc_method (* for instance methods in ObjC *)
| Class_objc_method (* for class methods in ObjC *) | Class_objc_method (* for class methods in ObjC *)
val empty : t
(** Mangled string for method types *) (** Mangled string for method types *)
val mangled_of_objc_method_kind : objc_method_kind -> string option val mangled_of_objc_method_kind : objc_method_kind -> string option

@ -81,7 +81,6 @@ let do_source_file
never_null_matcher linereader classes program tenv source_basename source_file proc_file_map = never_null_matcher linereader classes program tenv source_basename source_file proc_file_map =
JUtils.log "\nfilename: %s (%s)@." JUtils.log "\nfilename: %s (%s)@."
(DB.source_file_to_string source_file) source_basename; (DB.source_file_to_string source_file) source_basename;
init_global_state source_file;
let call_graph, cfg = let call_graph, cfg =
JFrontend.compute_source_icfg JFrontend.compute_source_icfg
never_null_matcher linereader classes program tenv source_basename source_file in never_null_matcher linereader classes program tenv source_basename source_file in
@ -145,10 +144,19 @@ let do_all_files classpath sources classes =
let program = JClasspath.load_program classpath classes sources in let program = JClasspath.load_program classpath classes sources in
let tenv = load_tenv program in let tenv = load_tenv program in
let linereader = Printer.LineReader.create () in let linereader = Printer.LineReader.create () in
let never_null_matcher = Inferconfig.NeverReturnNull.load_matcher (Inferconfig.inferconfig ()) in let skip_translation_matcher =
Inferconfig.SkipTranslationMatcher.load_matcher (Inferconfig.inferconfig ()) in
let never_null_matcher =
Inferconfig.NeverReturnNull.load_matcher (Inferconfig.inferconfig ()) in
let proc_file_map = let proc_file_map =
let skip filename =
skip_translation_matcher filename Procname.empty in
StringMap.fold StringMap.fold
(do_source_file never_null_matcher linereader classes program tenv) (fun basename source_file map ->
init_global_state source_file;
if skip source_file then map
else do_source_file
never_null_matcher linereader classes program tenv basename source_file map)
sources sources
Procname.Map.empty in Procname.Map.empty in
if !JConfig.dependency_mode then if !JConfig.dependency_mode then

@ -0,0 +1 @@
../../.inferconfig

@ -12,5 +12,11 @@
], ],
"infer_blacklist_files_containing": [ "infer_blacklist_files_containing": [
"@generated" "@generated"
],
"skip_translation": [
{
"language": "Java",
"source_contains": "_SHOULD_BE_SKIPPED_"
}
] ]
} }

@ -425,4 +425,9 @@ public class NullPointerExceptions {
o.toString(); o.toString();
} }
void shouldNotReportOnSkippedSource() {
Object o = SkippedSourceFile.createdBySkippedFile();
o.toString();
}
} }

@ -0,0 +1,21 @@
/*
* Copyright (c) 2015 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// _SHOULD_BE_SKIPPED_
package codetoanalyze.java.infer;
public class SkippedSourceFile {
static Object createdBySkippedFile() {
return null;
}
}
Loading…
Cancel
Save