Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ninjapouet fix dune lang #223

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading