[java] support Java9

Summary:
Support `javac` invocations from Java9.

closes #774

Reviewed By: jeremydubreil

Differential Revision: D6135103

fbshipit-source-id: a57ea5c
master
Jules Villard 7 years ago committed by Facebook Github Bot
parent 535ba01a25
commit 185e7f7131

@ -34,7 +34,7 @@ $(INFER_REPORT): $(JAVA_DEPS_NO_MODELS) $(JAVA_SOURCES) $(MAKEFILE_LIST)
$(QUIET)$(call silent_on_success,Building Java models,\ $(QUIET)$(call silent_on_success,Building Java models,\
$(INFER_BIN) -a checkers --biabduction-only --results-dir $(INFER_RESULTS_DIR) --models-mode -- \ $(INFER_BIN) -a checkers --biabduction-only --results-dir $(INFER_RESULTS_DIR) --models-mode -- \
$(JAVAC) -bootclasspath $(ANDROID_JAR) -d $(MODELS_OUT) -classpath $(MODELS_CLASSPATH) \ $(JAVAC) -bootclasspath $(ANDROID_JAR) -d $(MODELS_OUT) -classpath $(MODELS_CLASSPATH) \
$(JAVA_SOURCES)) $(JAVA_SOURCES) -source 7 -target 7)
$(MODELS_JAR): $(INFER_REPORT) $(MODELS_JAR): $(INFER_REPORT)
cd $(MODELS_OUT); jar cf ../$(MODELS_JAR) * cd $(MODELS_OUT); jar cf ../$(MODELS_JAR) *

@ -2005,7 +2005,12 @@ and xml_specs =
are allowed to refer to the other arg variables. *) are allowed to refer to the other arg variables. *)
let javac_classes_out = let javac_classes_out =
CLOpt.mk_string_opt ~parse_mode:CLOpt.Javac ~deprecated:["classes_out"] ~long:"" ~short:'d' CLOpt.mk_string ~parse_mode:CLOpt.Javac ~deprecated:["classes_out"] ~long:""
~short:
'd'
(* Ensure that some form of "-d ..." is passed to javac. It's unclear whether this is strictly
needed but the tests break without this for now. See discussion in D4397716. *)
~default:CLOpt.init_work_dir
~f:(fun classes_out -> ~f:(fun classes_out ->
( if !buck then ( if !buck then
let classes_out_infer = resolve classes_out ^/ buck_results_dir_name in let classes_out_infer = resolve classes_out ^/ buck_results_dir_name in

@ -490,7 +490,7 @@ val iterations : int
val java_jar_compiler : string option val java_jar_compiler : string option
val javac_classes_out : string option val javac_classes_out : string
val javac_verbose_out : string val javac_verbose_out : string

@ -26,18 +26,7 @@ let compile compiler build_prog build_args =
("java", ["-jar"; jar]) ("java", ["-jar"; jar])
in in
let cli_args, file_args = let cli_args, file_args =
let args = let args = "-verbose" :: "-g" :: "-d" :: Config.javac_classes_out :: build_args in
"-verbose"
:: "-g"
::
(* Ensure that some form of "-d ..." is passed to javac. It's unclear whether this is strictly
needed but the tests break without this for now. See discussion in D4397716. *)
( match Config.javac_classes_out with
| Some _ ->
build_args
| None ->
"-d" :: CLOpt.init_work_dir :: build_args )
in
List.partition_tf args ~f:(fun arg -> List.partition_tf args ~f:(fun arg ->
(* As mandated by javac, argument files must not contain certain arguments. *) (* As mandated by javac, argument files must not contain certain arguments. *)
String.is_prefix ~prefix:"-J" arg || String.is_prefix ~prefix:"@" arg ) String.is_prefix ~prefix:"-J" arg || String.is_prefix ~prefix:"@" arg )

@ -142,25 +142,41 @@ let add_root_path path roots = String.Set.add roots path
let load_from_verbose_output javac_verbose_out = let load_from_verbose_output javac_verbose_out =
let file_in = In_channel.create javac_verbose_out in let file_in = In_channel.create javac_verbose_out in
let class_filename_re = Str.regexp "\\[wrote RegularFileObject\\[\\(.*\\)\\]\\]" in let class_filename_re =
let source_filename_re = Str.regexp "\\[parsing started RegularFileObject\\[\\(.*\\)\\]\\]" in Str.regexp
(Printf.sprintf
(* the unreadable regexp below captures 3 possible forms:
1. [wrote DirectoryFileObject[/path/to/classes_out:path/to/File.java]], leaves `path/to/File.java` in match group 2
2. [wrote RegularFileObject[path/to/File.java]], leaves `path/to/File.java` in match group 5
3. [wrote SimpleFileObject[path/to/File.java]], also leaves `path/to/File.java` in match group 5 *)
"\\[wrote \\(DirectoryFileObject\\[%s:\\(.*\\)\\|\\(\\(Regular\\|Simple\\)FileObject\\[\\(.*\\)\\)\\)\\]\\]"
Config.javac_classes_out)
in
let source_filename_re =
Str.regexp "\\[parsing started \\(Regular\\|Simple\\)FileObject\\[\\(.*\\)\\]\\]"
in
let classpath_re = Str.regexp "\\[search path for class files: \\(.*\\)\\]" in let classpath_re = Str.regexp "\\[search path for class files: \\(.*\\)\\]" in
let rec loop paths roots sources classes = let rec loop paths roots sources classes =
try try
let line = In_channel.input_line_exn file_in in let line = In_channel.input_line_exn file_in in
if Str.string_match class_filename_re line 0 then if Str.string_match class_filename_re line 0 then
let path = Str.matched_group 1 line in let path =
try Str.matched_group 5 line
with Not_found ->
(* either matched group 5 is found, or matched group 2 is found, see doc for [class_filename_re] above *)
Config.javac_classes_out ^/ Str.matched_group 2 line
in
let cn, root_info = Javalib.extract_class_name_from_file path in let cn, root_info = Javalib.extract_class_name_from_file path in
let root_dir = let root_dir =
if String.equal root_info "" then Filename.current_dir_name else root_info if String.equal root_info "" then Filename.current_dir_name else root_info
in in
loop paths (add_root_path root_dir roots) sources (JBasics.ClassSet.add cn classes) loop paths (add_root_path root_dir roots) sources (JBasics.ClassSet.add cn classes)
else if Str.string_match source_filename_re line 0 then else if Str.string_match source_filename_re line 0 then
let path = Str.matched_group 1 line in let path = Str.matched_group 2 line in
loop paths roots (add_source_file path sources) classes loop paths roots (add_source_file path sources) classes
else if Str.string_match classpath_re line 0 then else if Str.string_match classpath_re line 0 then
let classpath = Str.matched_group 1 line in let classpath = Str.matched_group 1 line in
let parsed_paths = Str.split (Str.regexp_string ",") classpath in let parsed_paths = String.split ~on:',' classpath in
loop parsed_paths roots sources classes loop parsed_paths roots sources classes
else (* skip this line *) else (* skip this line *)
loop paths roots sources classes loop paths roots sources classes

Loading…
Cancel
Save