Directly handle javac -classes_out option in build command

Summary:
The javac -classes_out option is used to set the results directory for
the buck build system integration.

Reviewed By: jeremydubreil

Differential Revision: D4162907

fbshipit-source-id: 75d0a6d
master
Josh Berdine 8 years ago committed by Facebook Github Bot
parent 95ad5b6387
commit a9253d8996

@ -246,12 +246,6 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper):
if self.javac.original_arguments is None: if self.javac.original_arguments is None:
raise Exception('No javac command detected') raise Exception('No javac command detected')
if self.args.buck:
self.args.infer_out = os.path.join(
self.javac.args.classes_out,
config.BUCK_INFER_OUT)
self.args.infer_out = os.path.abspath(self.args.infer_out)
def compute_buck_key(self): def compute_buck_key(self):
javac_version = self.javac.get_version() javac_version = self.javac.get_version()
infer_version = utils.infer_key(self.args.analyzer) infer_version = utils.infer_key(self.args.analyzer)
@ -296,7 +290,6 @@ class AnalyzerWithFrontendWrapper(analyze.AnalyzerWrapper):
infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')] infer_cmd = [utils.get_cmd_in_bin_dir('InferJava')]
infer_cmd += [ infer_cmd += [
'-results_dir', self.args.infer_out,
'-verbose_out', self.javac.verbose_out, '-verbose_out', self.javac.verbose_out,
'-suppress_warnings_out', self.javac.suppress_warnings_out, '-suppress_warnings_out', self.javac.suppress_warnings_out,
] ]

@ -526,16 +526,21 @@ let prepend_to_argv args =
args @ cl_args args @ cl_args
(** [prefix_before_rest (prefix @ ["--" :: rest])] is [prefix] where "--" is not in [prefix]. *) (** [prefix_before_rest (prefix @ ["--" :: rest])] is [prefix] where "--" is not in [prefix]. *)
let prefix_before_rest args = let rev_prefix_before_rest args =
let rec prefix_before_rest_ rev_keep = function let rec rev_prefix_before_rest_ rev_keep = function
| [] | "--" :: _ -> IList.rev rev_keep | [] | "--" :: _ -> rev_keep
| keep :: args -> prefix_before_rest_ (keep :: rev_keep) args in | keep :: args -> rev_prefix_before_rest_ (keep :: rev_keep) args in
prefix_before_rest_ [] args rev_prefix_before_rest_ [] args
(** environment variable use to pass arguments from parent to child processes *) (** environment variable use to pass arguments from parent to child processes *)
let args_env_var = "INFER_ARGS" let args_env_var = "INFER_ARGS"
let extra_env_args = ref []
let extend_env_args args =
extra_env_args := List.rev_append args !extra_env_args
let parse ?(incomplete=false) ?(accept_unknown=false) ?config_file current_exe exe_usage = let parse ?(incomplete=false) ?(accept_unknown=false) ?config_file current_exe exe_usage =
let full_speclist = ref [] let full_speclist = ref []
in in
@ -669,8 +674,14 @@ let parse ?(incomplete=false) ?(accept_unknown=false) ?config_file current_exe e
| Arg.Help usage_msg -> Pervasives.print_string usage_msg; exit 0 | Arg.Help usage_msg -> Pervasives.print_string usage_msg; exit 0
in in
parse_loop (); parse_loop ();
if not incomplete then if not incomplete then (
Unix.putenv (* reread args_to_parse instead of using all_args since mk_path_helper may have modified them *)
~key:args_env_var let prog_args =
~data:(encode_argv_to_env (prefix_before_rest (IList.tl (Array.to_list !args_to_parse)))) ; List.rev_append
(rev_prefix_before_rest (Array.to_list !args_to_parse))
(List.rev !extra_env_args) in
(* do not include program path in args passed via env var *)
let args = Option.value (List.tl prog_args) ~default:[] in
Unix.putenv ~key:args_env_var ~data:(encode_argv_to_env args)
);
curr_usage curr_usage

@ -137,6 +137,9 @@ val args_env_var : string
(** separator of argv elements when encoded into environment variables *) (** separator of argv elements when encoded into environment variables *)
val env_var_sep : char val env_var_sep : char
(** [extend_env_args args] appends [args] to those passed via [args_env_var] *)
val extend_env_args : string list -> unit
(** [parse env_var exe_usage exe] parses command line arguments as specified by preceding calls to (** [parse env_var exe_usage exe] parses command line arguments as specified by preceding calls to
the [mk_*] functions, and returns a function that prints the usage message and help text then the [mk_*] functions, and returns a function that prints the usage message and help text then
exits. [exe] is used to construct the help message appropriate for that executable. The decoded exits. [exe] is used to construct the help message appropriate for that executable. The decoded

@ -78,6 +78,8 @@ let buck_generated_folder = "buck-out/gen"
let buck_infer_deps_file_name = "infer-deps.txt" let buck_infer_deps_file_name = "infer-deps.txt"
let buck_results_dir_name = "infer"
let captured_dir_name = "captured" let captured_dir_name = "captured"
let checks_disabled_by_default = [ let checks_disabled_by_default = [
@ -1229,14 +1231,29 @@ and xml_specs =
CLOpt.mk_bool ~deprecated:["xml"] ~long:"xml-specs" CLOpt.mk_bool ~deprecated:["xml"] ~long:"xml-specs"
"Export specs into XML files file1.xml ... filen.xml" "Export specs into XML files file1.xml ... filen.xml"
let javac_classes_out = ref None
(* The "rest" args must appear after "--" on the command line, and hence after other args, so they (* The "rest" args must appear after "--" on the command line, and hence after other args, so they
are allowed to refer to the other arg variables. *) are allowed to refer to the other arg variables. *)
let rest = let rest =
let classes_out_spec =
Arg.String (fun classes_out ->
javac_classes_out := Some classes_out ;
if !buck then (
let classes_out_infer = resolve classes_out ^/ buck_results_dir_name in
(* extend env var args to pass args to children that do not receive the rest args *)
CLOpt.extend_env_args ["--results-dir"; classes_out_infer] ;
results_dir := classes_out_infer
)
) in
CLOpt.mk_subcommand CLOpt.mk_subcommand
~exes:CLOpt.[Toplevel] ~exes:CLOpt.[Toplevel]
"Stop argument processing, use remaining arguments as a build command" "Stop argument processing, use remaining arguments as a build command"
(fun build_exe -> (fun build_exe ->
match Filename.basename build_exe with match Filename.basename build_exe with
| "java" | "javac" -> [
("-classes_out", classes_out_spec, ""); ("-d", classes_out_spec, "")
]
| _ -> [] | _ -> []
) )

Loading…
Cancel
Save