Skip to content

Commit

Permalink
Merge pull request #223 from lefessan/Ninjapouet-fix-dune-lang
Browse files Browse the repository at this point in the history
Ninjapouet fix dune lang
  • Loading branch information
lefessan authored Jun 5, 2024
2 parents b42a6f0 + 9fd6996 commit 87f34da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/drom_lib/project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -568,35 +568,39 @@ let project_of_toml ?file ?default table =
If no dune version is specified, drom uses the
{!Globals.current_dune_version}. *)

let after_0_9_2 = VersionCompare.compare project_drom_version "0.9.2" >= 0 in

let dune_version =
let find = List.mem_assoc "dune" in
(* No dune dependencies in packages tools or dependencies. *)
List.iter
(fun (p : package) ->
if find p.p_dependencies then
if List.mem_assoc "dune" p.p_dependencies then
(* dune is in [p] dependencies which is silly: dune is a tool, not
a library. *)
Error.raise
"Package %s has a dune dependency which has no meaning. Please \
remove it"
p.name;
if find p.p_tools then
if List.mem_assoc "dune" p.p_tools then
(* dune is in [p] tools which is bad project engineering design. *)
Error.raise
"Package %s gives dune as a tool dependency. Such dependency \
should appears at project level, please move it in drom.toml."
p.name )
packages;
(* Legacy dune lang version specification *)
let legacy_dune_lang = StringMap.find_opt "dune" p_fields in
let legacy_dune_lang = StringMap.find_opt
(if after_0_9_2 then "dune-lang" else "dune") p_fields in
(* Checking that dune is not in project's dependencies, which has no more
meaning than in packages *)
if find dependencies then
if List.mem_assoc "dune" dependencies then
Error.raise
"Project has a dune dependency which has no meaning. Please remove it \
or move it in [tools].";
(* The valid way of overriding dune version. *)
let dune_tool_spec = List.assoc_opt "dune" dependencies in
let dune_tool_spec = List.assoc_opt "dune"
(if after_0_9_2 then tools else dependencies) in
(* Normalizing *)
let versions =
match (legacy_dune_lang, dune_tool_spec) with
Expand Down
10 changes: 9 additions & 1 deletion src/drom_lib/subst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,15 @@ let project_brace ({ p; _ } as state ) v =
(* for dune *)
| "dune-version" -> p.dune_version
| "dune-lang" ->
String.sub p.dune_version 0 (String.rindex p.dune_version '.')
if VersionCompare.compare state.share.drom_version "0.9.2" >= 0 then
(* just parsing basic semver for now. *)
try
Scanf.sscanf p.dune_version "%i.%i"
(fun major minor -> Printf.sprintf "%i.%i" major minor)
with _ ->
raise (Failure ("Cannot parse dune-version: " ^ p.dune_version))
else
String.sub p.dune_version 0 (String.rindex p.dune_version '.')
| "dune-cram" ->
if VersionCompare.compare p.dune_version "2.7.0" >= 0 then
"(cram enable)"
Expand Down

0 comments on commit 87f34da

Please sign in to comment.