[linters] Use the sdk version by path in the error message of unavailable api check

Reviewed By: jvillard

Differential Revision: D5738395

fbshipit-source-id: 4f740a1
master
Dulma Churchill 7 years ago committed by Facebook Github Bot
parent 32d462b778
commit 47088e078e

@ -217,8 +217,7 @@ DEFINE-CHECKER CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK = {
HOLDS-IN-NODE DeclRefExpr, ObjCMessageExpr;
SET message =
"%decl_ref_or_selector_name% is not available in the required iOS SDK version
%iphoneos_target_sdk_version% (only available from version %available_ios_sdk%)";
"%decl_ref_or_selector_name% is not available in the required iOS SDK version %iphoneos_target_sdk_version% (only available from version %available_ios_sdk%)";
SET name = "Unavailable API In Supported iOS SDK";
SET suggestion = "This could cause a crash.";
SET severity = "ERROR";
@ -233,8 +232,7 @@ DEFINE-CHECKER CXX_REFERENCE_CAPTURED_IN_OBJC_BLOCK = {
HOLDS-IN-NODE ObjCMessageExpr;
SET message =
"The receiver %receiver_method_call% of %name% is not available in the required iOS SDK version
%iphoneos_target_sdk_version% (only available from version %class_available_ios_sdk%)";
"The receiver %receiver_method_call% of %name% is not available in the required iOS SDK version %iphoneos_target_sdk_version% (only available from version %class_available_ios_sdk%)";
SET name = "Unavailable API In Supported iOS SDK";
SET severity = "ERROR";
SET mode = "ON";

@ -50,8 +50,8 @@ let decl_ref_or_selector_name an =
"decl_ref_or_selector_name must be called with a DeclRefExpr or an ObjCMessageExpr, but got %s"
(tag_name_of_node an)
let iphoneos_target_sdk_version _ =
match Config.iphoneos_target_sdk_version with Some f -> f | None -> "0"
let iphoneos_target_sdk_version context _ =
match CPredicates.iphoneos_target_sdk_version_by_path context with Some f -> f | None -> "0"
let available_ios_sdk an =
let open Ctl_parser_types in

@ -23,7 +23,7 @@ val cxx_ref_captured_in_block : Ctl_parser_types.ast_node -> string
val decl_ref_or_selector_name : Ctl_parser_types.ast_node -> string
val iphoneos_target_sdk_version : Ctl_parser_types.ast_node -> string
val iphoneos_target_sdk_version : CLintersContext.context -> Ctl_parser_types.ast_node -> string
val available_ios_sdk : Ctl_parser_types.ast_node -> string

@ -93,7 +93,7 @@ let stmt_checkers_list = List.map ~f:single_to_multi stmt_single_checkers_list
input the linter def files *)
let parsed_linters = ref []
let evaluate_place_holder ph an =
let evaluate_place_holder context ph an =
match ph with
| "%ivar_name%"
-> MF.monospaced_to_string (CFrontend_checkers.ivar_name an)
@ -106,7 +106,7 @@ let evaluate_place_holder ph an =
| "%receiver_method_call%"
-> MF.monospaced_to_string (CFrontend_checkers.receiver_method_call an)
| "%iphoneos_target_sdk_version%"
-> MF.monospaced_to_string (CFrontend_checkers.iphoneos_target_sdk_version an)
-> MF.monospaced_to_string (CFrontend_checkers.iphoneos_target_sdk_version context an)
| "%available_ios_sdk%"
-> MF.monospaced_to_string (CFrontend_checkers.available_ios_sdk an)
| "%class_available_ios_sdk%"
@ -127,19 +127,19 @@ let evaluate_place_holder ph an =
other place-holders exist and repeats the process until there are
no place-holder left.
*)
let rec expand_message_string message an =
let rec expand_message_string context message an =
(* reg exp should match alphanumeric id with possibly somee _ *)
let re = Str.regexp "%[a-zA-Z0-9_]+%" in
try
let _ = Str.search_forward re message 0 in
let ms = Str.matched_string message in
let res = evaluate_place_holder ms an in
let res = evaluate_place_holder context ms an in
L.(debug Linters Medium) "@\nMatched string '%s'@\n" ms ;
let re_ms = Str.regexp_string ms in
let message' = Str.replace_first re_ms res message in
L.(debug Linters Medium) "Replacing %s in message: @\n %s @\n" ms message ;
L.(debug Linters Medium) "Resulting message: @\n %s @\n" message' ;
expand_message_string message' an
expand_message_string context message' an
with Not_found -> message
let remove_new_lines message = String.substr_replace_all ~pattern:"\n" ~with_:" " message
@ -441,7 +441,7 @@ let get_current_method context (an: Ctl_parser_types.ast_node) =
-> context.CLintersContext.current_method
let fill_issue_desc_info_and_log context an key issue_desc linters_def_file loc =
let desc = remove_new_lines (expand_message_string issue_desc.CIssue.description an) in
let desc = remove_new_lines (expand_message_string context issue_desc.CIssue.description an) in
let issue_desc' = {issue_desc with CIssue.description= desc; CIssue.loc= loc} in
log_frontend_issue context.CLintersContext.translation_unit_context
(get_current_method context an) key issue_desc' linters_def_file

@ -124,6 +124,8 @@ val has_visibility_attribute : Ctl_parser_types.ast_node -> ALVar.alexp -> bool
val has_used_attribute : Ctl_parser_types.ast_node -> bool
val iphoneos_target_sdk_version_by_path : CLintersContext.context -> string option
val iphoneos_target_sdk_version_greater_or_equal : CLintersContext.context -> string -> bool
val within_available_class_block : CLintersContext.context -> Ctl_parser_types.ast_node -> bool

Loading…
Cancel
Save