From 73ad59ca7c7a7da174891529d9dbe7d7b9f5bdc9 Mon Sep 17 00:00:00 2001 From: Ambre Austen Suhamy Date: Thu, 11 Jul 2024 18:38:59 +0200 Subject: [PATCH] Added feature flag to enable dune cache by default Signed-off-by: Ambre Austen Suhamy --- src/dune_config_file/dune_config_file.ml | 12 +++++-- src/dune_config_file/feature_flags.ml | 1 + src/dune_rules/format_rules.mli | 2 +- .../blackbox-tests/test-cases/default-cache.t | 34 +++++++++++++++++++ 4 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src/dune_config_file/feature_flags.ml create mode 100644 test/blackbox-tests/test-cases/default-cache.t diff --git a/src/dune_config_file/dune_config_file.ml b/src/dune_config_file/dune_config_file.ml index 0b31881b5475..3220aa598d4e 100644 --- a/src/dune_config_file/dune_config_file.ml +++ b/src/dune_config_file/dune_config_file.ml @@ -11,6 +11,7 @@ module Dune_config = struct module Log = Dune_util.Log module Config = Dune_config.Config module Execution_env = Dune_util.Execution_env + module Feature_flags = Feature_flags (* the configuration file use the same version numbers as dune-project files for simplicity *) @@ -279,9 +280,14 @@ module Dune_config = struct ; concurrency = (if Execution_env.inside_dune then Fixed 1 else Auto) ; terminal_persistence = Clear_on_rebuild ; sandboxing_preference = [] - ; cache_enabled = `Disabled - ; cache_reproducibility_check = Skip - ; cache_storage_mode = None + ; cache_enabled = + (if Feature_flags.cache_enabled_by_default then `Enabled else `Disabled) + ; cache_reproducibility_check = + (if Feature_flags.cache_enabled_by_default then Check else Skip) + ; cache_storage_mode = + (if Feature_flags.cache_enabled_by_default + then Some (Dune_cache_storage.Mode.default ()) + else None) ; action_stdout_on_success = Print ; action_stderr_on_success = Print ; experimental = [] diff --git a/src/dune_config_file/feature_flags.ml b/src/dune_config_file/feature_flags.ml new file mode 100644 index 000000000000..f9521684aa35 --- /dev/null +++ b/src/dune_config_file/feature_flags.ml @@ -0,0 +1 @@ +let cache_enabled_by_default = false diff --git a/src/dune_rules/format_rules.mli b/src/dune_rules/format_rules.mli index 84508393b2b3..4f4a11cb3150 100644 --- a/src/dune_rules/format_rules.mli +++ b/src/dune_rules/format_rules.mli @@ -8,7 +8,7 @@ open Import val gen_rules : Super_context.t -> output_dir:Path.Build.t -> unit Memo.t (** This must be called from the main directory, i.e. the ones containing the - source files and the the [formatted_dir_basename] sub-directory. *) + source files and the [formatted_dir_basename] sub-directory. *) val setup_alias : dir:Path.Build.t -> unit Memo.t val formatted_dir_basename : Filename.t diff --git a/test/blackbox-tests/test-cases/default-cache.t b/test/blackbox-tests/test-cases/default-cache.t new file mode 100644 index 000000000000..03c9c8494255 --- /dev/null +++ b/test/blackbox-tests/test-cases/default-cache.t @@ -0,0 +1,34 @@ +The dune cache should be enabled by 'default' +(not by default on main branch since it's a feature flag) + $ export DUNE_CACHE=enabled + $ echo "(lang dune 3.16)" > dune-project + + $ cat > dune << EOF + > (library + > (name foo)) + > EOF + + $ cat > foo.ml << EOF + > let f x y = x + y + > EOF + +Set up cache directory + $ export DUNE_CACHE_ROOT=$(pwd)/dune_test_cache + $ mkdir $DUNE_CACHE_ROOT + + $ DUNE_CACHE=disabled dune build + $ ls $DUNE_CACHE_ROOT +We have not written anything to the cache yet. + +Change source files to force a recompilation + $ cat > foo.ml << EOF + > let f x y = x - y + > EOF + + $ dune build + $ ls $DUNE_CACHE_ROOT + files + meta + temp + values +Cache has been written to!