Skip to content

Commit

Permalink
[maven] disable JAVA_HOME during capture
Browse files Browse the repository at this point in the history
Summary:
The maven script now checks for a java command in `JAVA_HOME`

```
if [ -z "$JAVA_HOME" ] ; then
  JAVACMD=`which java`
else
  JAVACMD="$JAVA_HOME/bin/java"
fi
```
when running under infer (where we specify infer as a compiler) and a valid `JAVA_HOME`, this check fails with
```
The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE
```
We unset `JAVA_HOME` when running under infer, bypassing this check (it still requires a java executable in the path).

Reviewed By: geralt-encore

Differential Revision:
D68148333

Privacy Context Container: L1208441

fbshipit-source-id: 1d6bf0994f58f9c225f2a889c8145754eb6f6ea8
  • Loading branch information
ngorogiannis authored and facebook-github-bot committed Jan 14, 2025
1 parent ef7d4b3 commit 370f5fc
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion infer/src/base/Config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ let infer_inside_maven_env_var = "INFER_INSIDE_MAVEN"

let maven = CLOpt.is_env_var_set infer_inside_maven_env_var

let env_inside_maven = `Extend [(infer_inside_maven_env_var, "1")]
let maven_env = `Extend [(infer_inside_maven_env_var, "1"); ("JAVA_HOME", "")]

let infer_is_javac = maven

Expand Down
3 changes: 2 additions & 1 deletion infer/src/base/Config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ val build_system_of_exe_name : string -> build_system

val string_of_build_system : build_system -> string

val env_inside_maven : Unix.env
val maven_env : Unix.env
(** tell Infer it's running inside maven and disable JAVA_HOME *)

(** {2 Constant configuration values} *)

Expand Down
2 changes: 1 addition & 1 deletion infer/src/integration/Maven.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ let capture ~prog ~args =
"Running maven capture:@\n%s %s@." prog
(String.concat ~sep:" " (List.map ~f:(Printf.sprintf "'%s'") capture_args)) ;
(* let children infer processes know that they are spawned by Maven *)
Process.create_process_and_wait ~prog ~args:capture_args ~env:Config.env_inside_maven ()
Process.create_process_and_wait ~prog ~args:capture_args ~env:Config.maven_env ()

0 comments on commit 370f5fc

Please sign in to comment.