Skip to content

Commit

Permalink
fix: get rid of project check for dune init
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Feb 8, 2022
1 parent 34ce66d commit 9ea4f73
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 20 deletions.
6 changes: 5 additions & 1 deletion bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions bin/init.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/dune_engine/clflags.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions src/dune_engine/clflags.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 29 additions & 16 deletions src/dune_engine/source_tree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9ea4f73

Please sign in to comment.