Skip to content

Commit

Permalink
Minor refactors and doc in config loading code
Browse files Browse the repository at this point in the history
Summary: I never remember what flows where, so this is an attempt at making that flow clearer upon reading the code.

Differential Revision: D68019600

fbshipit-source-id: b3175170ba9941e3e42978b4c7663d9372d3b680
  • Loading branch information
Catherine Gasnier authored and facebook-github-bot committed Jan 16, 2025
1 parent 7340b07 commit 9a1bf15
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 72 deletions.
155 changes: 83 additions & 72 deletions hphp/hack/src/client_and_server/serverConfig.ml
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ let reasons_config_opt config =
Option.map ~f:(fun n -> GlobalOptions.Extended n)
@@ int_of_string_opt data_str)

let load_config config options =
let load_config (config : Config_file_common.t) (options : GlobalOptions.t) :
GlobalOptions.t =
let ( >?? ) x y = Option.value x ~default:y in
let po_opt = options.GlobalOptions.po in
let experimental_features = config_experimental_stx_features config in
Expand Down Expand Up @@ -507,17 +508,64 @@ let load_config config options =
?class_class_type:(bool_opt "class_class_type" config)
options

(** Load local config from the following sources:
* /etc/hh.conf
* overridden by Knobs
* overridden by ExperimentsConfig
* overridden by command line overrides
If not silent, then prints what it's doing to stderr. *)
let load_local_config
(config : Config_file_common.t)
(version : Config_file_version.version)
~(command_line_overrides : Config_file_common.t)
~is_ai
~silent
~from : ServerLocalConfig.t =
let current_rolled_out_flag_idx =
int_ "current_saved_state_rollout_flag_index" ~default:0 config
in
let deactivate_saved_state_rollout =
bool_ "deactivate_saved_state_rollout" ~default:false config
in
let local_config =
ServerLocalConfigLoad.load
~silent
~current_version:version
~current_rolled_out_flag_idx
~deactivate_saved_state_rollout
~from
~overrides:command_line_overrides
in
if is_ai then
let open ServerLocalConfig in
{
local_config with
watchman =
{
local_config.watchman with
Watchman.enabled = false;
subscribe = false;
};
interrupt_on_watchman = false;
interrupt_on_client = false;
trace_parsing = false;
}
else
local_config

let load
~silent
~from
~(cli_config_overrides : (string * string) list)
~(ai_options : Ai_options.t option) : t * ServerLocalConfig.t =
let command_line_overrides = Config_file.of_list cli_config_overrides in
let hhconfig_abs_path = Relative_path.to_absolute repo_config_path in
let original_config = Config_file.parse_hhconfig hhconfig_abs_path in
let hhconfig = Config_file.parse_hhconfig hhconfig_abs_path in
let config =
Config_file.apply_overrides
~config:original_config
~config:hhconfig
~overrides:command_line_overrides
~log_reason:None
in
Expand All @@ -526,80 +574,31 @@ let load
Config_file.parse_version (Config_file.Getters.string_opt "version" config)
in
let local_config =
let current_rolled_out_flag_idx =
int_ "current_saved_state_rollout_flag_index" ~default:0 config
in
let deactivate_saved_state_rollout =
bool_ "deactivate_saved_state_rollout" ~default:false config
in
ServerLocalConfigLoad.load
load_local_config
config
version
~command_line_overrides
~is_ai:(Option.is_some ai_options)
~silent
~current_version:version
~current_rolled_out_flag_idx
~deactivate_saved_state_rollout
~from
~overrides:command_line_overrides
in
let local_config =
if Option.is_some ai_options then
let open ServerLocalConfig in
{
local_config with
watchman =
{
local_config.watchman with
Watchman.enabled = false;
subscribe = false;
};
interrupt_on_watchman = false;
interrupt_on_client = false;
trace_parsing = false;
}
else
local_config
in
let ignored_paths = process_ignored_paths config in
let extra_paths = process_extra_paths config in
(* Since we use the unix alarm() for our timeouts, a timeout value of 0 means
* to wait indefinitely *)
let load_script_timeout = int_ "load_script_timeout" ~default:0 config in
let warn_on_non_opt_build =
bool_ "warn_on_non_opt_build" ~default:false config
in
let ide_fall_back_to_full_index =
bool_ "ide_fall_back_to_full_index" ~default:true config
in
let naming_table_compression_level =
int_ "naming_table_compression_level" ~default:6 config
in
let naming_table_compression_threads =
int_ "naming_table_compression_threads" ~default:1 config
in
let warnings_generated_files =
string_list "warnings_generated_files" ~default:[] config
|> List.map ~f:Str.regexp
in
let package_v2 = bool_ "package_v2" ~default:false config in
let formatter_override =
Option.map
(Config_file.Getters.string_opt "formatter_override" config)
~f:maybe_relative_path
in
string_opt "packages_config_path" config
|> Option.iter ~f:Config_file_common.set_pkgconfig_path;
Option.iter
~f:Config_file_common.set_pkgconfig_path
(string_opt "packages_config_path" config);
let pkgs_config_abs_path =
Relative_path.(
to_absolute
@@ from_root ~suffix:(Config_file_common.get_pkgconfig_path ()))
in
let config_hash =
Config_file_common.hash
original_config
hhconfig
~hhconfig_contents:(Config_file.cat_hhconfig_file hhconfig_abs_path)
~pkgconfig_contents:(Config_file.cat_packages_file pkgs_config_abs_path)
in
Hh_logger.log "Parsing and loading packages config at %s" pkgs_config_abs_path;
let package_info =
let package_v2 = bool_ "package_v2" ~default:false config in
PackageConfig.load_and_parse ~strict:true ~package_v2 ~pkgs_config_abs_path
in
let global_opts =
Expand All @@ -612,7 +611,7 @@ let load
default.po with
ParserOptions.allow_unstable_features =
local_config.ServerLocalConfig.allow_unstable_features;
ParserOptions.package_info;
package_info;
}
?so_naming_sqlite_path:local_config.naming_sqlite_path
?tco_log_large_fanouts_threshold:
Expand Down Expand Up @@ -658,22 +657,34 @@ let load
Errors.code_agnostic_fixme := GlobalOptions.code_agnostic_fixme global_opts;
( {
version;
load_script_timeout;
load_script_timeout =
(* Since we use the unix alarm() for our timeouts, a timeout value of 0 means
* to wait indefinitely *)
int_ "load_script_timeout" ~default:0 config;
gc_control = make_gc_control config;
sharedmem_config = make_sharedmem_config config local_config ?ai_options;
tc_options = global_opts;
parser_options = global_opts.GlobalOptions.po;
glean_options = global_opts;
symbol_write_options = global_opts;
formatter_override;
formatter_override =
Option.map
(Config_file.Getters.string_opt "formatter_override" config)
~f:maybe_relative_path;
config_hash = Some config_hash;
ignored_paths;
extra_paths;
warn_on_non_opt_build;
ide_fall_back_to_full_index;
naming_table_compression_level;
naming_table_compression_threads;
warnings_generated_files;
ignored_paths = process_ignored_paths config;
extra_paths = process_extra_paths config;
warn_on_non_opt_build =
bool_ "warn_on_non_opt_build" ~default:false config;
ide_fall_back_to_full_index =
bool_ "ide_fall_back_to_full_index" ~default:true config;
naming_table_compression_level =
int_ "naming_table_compression_level" ~default:6 config;
naming_table_compression_threads =
int_ "naming_table_compression_threads" ~default:1 config;
warnings_generated_files =
string_list "warnings_generated_files" ~default:[] config
|> List.map ~f:Str.regexp;
},
local_config )

Expand Down
5 changes: 5 additions & 0 deletions hphp/hack/src/client_and_server/serverLocalConfigLoad.ml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ let system_config_path =
in
Filename.concat dir "hh.conf"

(** Apply the following overrides in order:
* JuskKnobs
* Experiments
* `overrides`
*)
let apply_overrides ~silent ~current_version ~config ~from ~overrides =
(* We'll apply CLI overrides now at the start so that JustKnobs and experiments_config
can be informed about them, e.g. "--config rollout_group=foo" will be able
Expand Down

0 comments on commit 9a1bf15

Please sign in to comment.