diff --git a/bin/common.ml b/bin/common.ml index 2c30b1e310dc..042899a95786 100644 --- a/bin/common.ml +++ b/bin/common.ml @@ -205,7 +205,11 @@ let init ?log_file c = Clflags.promote_install_files := c.promote_install_files; Clflags.always_show_command_line := c.always_show_command_line; Clflags.ignore_promoted_rules := c.ignore_promoted_rules; - Clflags.require_dune_project_file := c.require_dune_project_file; + Clflags.dune_project_file := + if c.require_dune_project_file then + Error + else + Warn; Dune_util.Log.info [ Pp.textf "Workspace root: %s" (Path.to_absolute_filename Path.root |> String.maybe_quoted) diff --git a/bin/init.ml b/bin/init.ml index 2ba95de27867..2bb323a4852d 100644 --- a/bin/init.ml +++ b/bin/init.ml @@ -210,6 +210,7 @@ let term = & info [ "pkg" ] ~docv ~doc) in let _config = Common.init common_term in + Dune_engine.Clflags.dune_project_file := Dune_engine.Clflags.Ignore; let open Component in let context = Init_context.make path in let common : Options.Common.t = { name; libraries; pps } in diff --git a/src/dune_engine/clflags.ml b/src/dune_engine/clflags.ml index 2b8ba6ebfb7c..a353897b2757 100644 --- a/src/dune_engine/clflags.ml +++ b/src/dune_engine/clflags.ml @@ -38,4 +38,9 @@ let promote_install_files = ref false let ignore_promoted_rules = ref false -let require_dune_project_file = ref false +type dune_project_file = + | Error + | Warn + | Ignore + +let dune_project_file = ref Warn diff --git a/src/dune_engine/clflags.mli b/src/dune_engine/clflags.mli index 4b64786e2ec8..8ee1ba149edf 100644 --- a/src/dune_engine/clflags.mli +++ b/src/dune_engine/clflags.mli @@ -54,5 +54,10 @@ val promote_install_files : bool ref (** Whether we are ignoring rules with [(mode promote)] *) val ignore_promoted_rules : bool ref -(** Whether the "no dune-project file in tree" warning should be fatal *) -val require_dune_project_file : bool ref +type dune_project_file = + | Error + | Warn + | Ignore + +(** Desired behavior when dune project file is absent *) +val dune_project_file : dune_project_file ref diff --git a/src/dune_engine/source_tree.ml b/src/dune_engine/source_tree.ml index bbe17018bc12..9159ed22b62f 100644 --- a/src/dune_engine/source_tree.ml +++ b/src/dune_engine/source_tree.ml @@ -477,21 +477,34 @@ end = struct end let ensure_dune_project_file_exists = - Memo.create "ensure-dune-project-file-exists" - ~input:(module Dune_project) - (fun project -> - let open Memo.Build.O in - let+ exists = - Dune_project.file project |> Path.source |> Fs_memo.file_exists - in - if not exists then - User_warning.emit - ~is_error:!Clflags.require_dune_project_file - [ Pp.text - "No dune-project file has been found. A default one is assumed \ - but the project might break when dune is upgraded. Please \ - create a dune-project file." - ]) + let memo = + Memo.create "ensure-dune-project-file-exists" + ~input:(module Dune_project) + (fun project -> + let open Memo.Build.O in + let+ exists = + Dune_project.file project |> Path.source |> Fs_memo.file_exists + in + if not exists then + let is_error = + match !Clflags.dune_project_file with + | Error -> true + | Warn -> false + | Ignore -> assert false + in + User_warning.emit ~is_error + [ Pp.text + "No dune-project file has been found. A default one is \ + assumed but the project might break when dune is upgraded. \ + Please create a dune-project file." + ]) + in + fun inp -> + match !Clflags.dune_project_file with + | Ignore -> Memo.Build.return () + | Warn + | Error -> + Memo.exec memo inp let dune_file ~(dir_status : Sub_dirs.Status.t) ~path ~files ~project = let file_exists = @@ -529,7 +542,7 @@ end = struct in Memo.Build.Option.map file ~f:(fun file -> let open Memo.Build.O in - let* () = Memo.exec ensure_dune_project_file_exists project in + let* () = ensure_dune_project_file_exists project in let file_exists = Option.is_some file_exists in let from_parent = Option.map from_parent ~f:snd in Dune_file.load file ~file_exists ~project ~from_parent)