From e27228737749e6f4b15a9131d60f7ac01e7f1df8 Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Mon, 12 Aug 2019 05:09:01 -0700 Subject: [PATCH] [version check] add a check for the environment variable INFERVERSION Summary: Add a sanity check that looks up the `INFERVERSION` environment variable and, if set, checks that the current binary matches that version. Reviewed By: skcho Differential Revision: D16761575 fbshipit-source-id: 9d5c32220 --- infer/src/base/Config.ml | 2 ++ infer/src/base/Config.mli | 2 ++ infer/src/infer.ml | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/infer/src/base/Config.ml b/infer/src/base/Config.ml index e0f8405f2..b2c62cb96 100644 --- a/infer/src/base/Config.ml +++ b/infer/src/base/Config.ml @@ -438,6 +438,8 @@ let infer_top_results_dir_env_var = "INFER_TOP_RESULTS_DIR" let infer_inside_maven_env_var = "INFER_INSIDE_MAVEN" +let infer_version_env_var = "INFERVERSION" + let maven = CLOpt.is_env_var_set infer_inside_maven_env_var let env_inside_maven = `Extend [(infer_inside_maven_env_var, "1")] diff --git a/infer/src/base/Config.mli b/infer/src/base/Config.mli index 671ee87f0..21933d1f9 100644 --- a/infer/src/base/Config.mli +++ b/infer/src/base/Config.mli @@ -103,6 +103,8 @@ val idempotent_getters : bool val infer_py_argparse_error_exit_code : int +val infer_version_env_var : string + val initial_analysis_time : float val ivar_attributes : string diff --git a/infer/src/infer.ml b/infer/src/infer.ml index 087829bd4..f091b96c4 100644 --- a/infer/src/infer.ml +++ b/infer/src/infer.ml @@ -120,6 +120,12 @@ let () = Version.versionString | None -> () ) ; + Sys.getenv Config.infer_version_env_var + |> Option.iter ~f:(fun version -> + if not (String.is_prefix version ~prefix:Version.commit) then + L.(die UserError) + "Version '%s' (in environment variable %s) does not match commit hash '%s'" version + Config.infer_version_env_var Version.commit ) ; if Config.print_builtins then Builtin.print_and_exit () ; setup () ; log_environment_info () ;