Skip to content

Commit

Permalink
Merge pull request #212 from lefessan/z-2023-05-10-subst-package
Browse files Browse the repository at this point in the history
Fix subst of package values description,synopsis,version,authors
  • Loading branch information
lefessan authored Jun 5, 2024
2 parents 63a5770 + 13edc91 commit 6ce330a
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 90 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
indicates, for any version of `drom`, the latest version of the
drom-share repo that should be used. It makes the `LATEST` file
obsolete (as it was incomplete in that matter)
* Package substitution: fix incorrect substitution of 'description',
'synopsis', 'version' and 'authors*' (previously interpreted as from
the project instead of from the package). {drom-version >= 0.9.2~dev4}
* Fix usage of `drom-version`: takes as `drom` version the most recent version
between `drom.toml` and skeleton `DROM_VERSION`

## v0.9.1
* Fix Sys_error docs/style.css because of missing file
Expand Down
2 changes: 1 addition & 1 deletion drom.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ min-edition = "4.07.0"
name = "drom"
skeleton = "program"
synopsis = "The drom tool is a wrapper over opam/dune in an attempt to provide a cargo-like user experience"
version = "0.9.2~dev3"
version = "0.9.2~dev4"

# keys that you could also define:
# odoc-target = "...odoc-target..."
Expand Down
1 change: 1 addition & 0 deletions src/drom_lib/globals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ let rec dummy_project =
project_share_version = None;
skeleton = None;
edition = current_ocaml_edition;
project_drom_version = min_drom_version;
min_edition = min_ocaml_edition;
github_organization = None;
homepage = None;
Expand Down
2 changes: 1 addition & 1 deletion src/drom_lib/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ let opam_of_package ?cross kind share package =
Misc.p_synopsis package );
var_string "description" (Misc.p_description package);
var_list "authors" (List.map string (Misc.p_authors package));
var_list "maintainer" (List.map string p.authors)
var_list "maintainer" (List.map string (Misc.p_authors package))
]
@ List.rev !optionals
@ build_commands
Expand Down
175 changes: 89 additions & 86 deletions src/drom_lib/project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ let find_author config =
let to_files share p =
let version =
EzToml.empty
|> EzToml.put_string [ "project"; "drom-version" ] Globals.min_drom_version
|> EzToml.put_string [ "project"; "drom-version" ] p.project_drom_version
|> EzToml.put_string_option [ "project"; "share-repo" ]
p.project_share_repo
|> EzToml.put_string_option [ "project"; "share-version" ]
Expand Down Expand Up @@ -234,15 +234,17 @@ let to_files share p =
("drom.toml", content) :: !files

let project_of_toml ?file ?default table =
( match EzToml.get_string_option table [ "project"; "drom-version" ] with
| None -> ()
| Some version -> (
match VersionCompare.compare version Version.version with
| 1 ->
Error.raise
"You must update `drom` to version %s to work with this project."
version
| _ -> () ) );
let project_drom_version =
match EzToml.get_string_option table [ "project"; "drom-version" ] with
| None -> Globals.min_drom_version
| Some version ->
match VersionCompare.compare version Version.version with
| 1 ->
Error.raise
"You must update `drom` to version %s to work with this project."
version
| _ -> version
in

let project_key = "project" in
let project_packages =
Expand All @@ -262,17 +264,17 @@ let project_of_toml ?file ?default table =
match default with
| Some default -> default
| None ->
{ Globals.dummy_project with
synopsis = Globals.default_synopsis ~name;
description = Globals.default_description ~name
}
{ Globals.dummy_project with
synopsis = Globals.default_synopsis ~name;
description = Globals.default_description ~name
}
in
(name, default)
with
| Not_found -> (
match default with
| None -> Error.raise "Missing project field 'name'"
| Some default -> (default.package.name, default) )
match default with
| None -> Error.raise "Missing project field 'name'"
| Some default -> (default.package.name, default) )
in
let authors =
match
Expand Down Expand Up @@ -303,11 +305,11 @@ let project_of_toml ?file ?default table =
| None, None -> (default_version, default_version)
| None, Some edition
| Some edition, None ->
(edition, edition)
(edition, edition)
| Some edition, Some min_edition -> (
match VersionCompare.compare min_edition edition with
| 1 -> Error.raise "min-edition is greater than edition in drom.toml"
| _ -> (edition, min_edition) )
match VersionCompare.compare min_edition edition with
| 1 -> Error.raise "min-edition is greater than edition in drom.toml"
| _ -> (edition, min_edition) )
in
let dependencies =
EzToml.get_encoding_default Package.dependencies_encoding table
Expand Down Expand Up @@ -344,8 +346,8 @@ let project_of_toml ?file ?default table =
EzToml.get_bool_option table [ project_key; "create-project" ]
~default:false
with
| Some v -> v
| None -> false
| Some v -> v
| None -> false
in

let skeleton =
Expand Down Expand Up @@ -397,23 +399,23 @@ let project_of_toml ?file ?default table =
with
| Some list -> list
| None -> (
match
EzToml.get_string_option table [ "drom"; "skip" ]
~default:(String.concat " " d.skip)
with
| None -> []
| Some s -> EzString.split s ' ' )
match
EzToml.get_string_option table [ "drom"; "skip" ]
~default:(String.concat " " d.skip)
with
| None -> []
| Some s -> EzString.split s ' ' )
in
let _pack_modules =
(* obsolete *)
match EzToml.get_bool_option table [ project_key; "pack-modules" ] with
| Some v -> v
| None -> (
match
EzToml.get_bool_option table [ project_key; "wrapped" ] ~default:true
with
| Some v -> v
| None -> true )
match
EzToml.get_bool_option table [ project_key; "wrapped" ] ~default:true
with
| Some v -> v
| None -> true )
in
let sphinx_target =
EzToml.get_string_option table
Expand Down Expand Up @@ -451,45 +453,45 @@ let project_of_toml ?file ?default table =
let rec iter list =
match list with
| [] ->
let p = Package.find ?default name in
(p, p :: project_packages)
let p = Package.find ?default name in
(p, p :: project_packages)
| p :: tail ->
if p.name = name then
(p, project_packages)
else
iter tail
if p.name = name then
(p, project_packages)
else
iter tail
in
iter project_packages
in

let packages =
match EzToml.get_string_option table [ project_key; "kind" ] with
| Some "both" ->
package.dir <- "main";
package.kind <- Program;
package.p_dependencies <-
( Misc.package_lib package,
{ depname = None;
depversions = [ Version ];
deptest = false;
depdoc = false;
depopt = false;
dep_pin = None;
} )
:: package.p_dependencies;
package.p_gen_version <- None;
let lib_name = Misc.package_lib package in
let lib =
{ Globals.dummy_package with
name = lib_name;
dir = "src" // lib_name;
kind = Library
}
in
packages @ [ lib ]
package.dir <- "main";
package.kind <- Program;
package.p_dependencies <-
( Misc.package_lib package,
{ depname = None;
depversions = [ Version ];
deptest = false;
depdoc = false;
depopt = false;
dep_pin = None;
} )
:: package.p_dependencies;
package.p_gen_version <- None;
let lib_name = Misc.package_lib package in
let lib =
{ Globals.dummy_package with
name = lib_name;
dir = "src" // lib_name;
kind = Library
}
in
packages @ [ lib ]
| Some _
| None ->
packages
packages
in

let profiles =
Expand Down Expand Up @@ -525,10 +527,10 @@ let project_of_toml ?file ?default table =
let generators = ref StringSet.empty in
List.iter
(fun p ->
match p.p_generators with
| None -> ()
| Some p_generators ->
generators := StringSet.union !generators p_generators )
match p.p_generators with
| None -> ()
| Some p_generators ->
generators := StringSet.union !generators p_generators )
packages;
let generators = !generators in
let menhir_version =
Expand Down Expand Up @@ -571,19 +573,19 @@ let project_of_toml ?file ?default table =
(* No dune dependencies in packages tools or dependencies. *)
List.iter
(fun (p : package) ->
if find 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
(* 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 )
if find 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
(* 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
Expand Down Expand Up @@ -615,19 +617,20 @@ let project_of_toml ?file ?default table =
~bottom:"2.0" versions
with
| `unknown ->
Error.raise
"Can't determine the dune minimal version. Please consider less \
restrictive dune specification."
Error.raise
"Can't determine the dune minimal version. Please consider less \
restrictive dune specification."
| `conflict (version, constraint_) ->
Error.raise
"dune version must be (>=%s), which contradicts the (%s) specification"
version constraint_
Error.raise
"dune version must be (>=%s), which contradicts the (%s) specification"
version constraint_
| `found version -> version
in

let project =
{ package;
packages;
project_drom_version ;
project_share_repo;
project_share_version;
file;
Expand Down
9 changes: 8 additions & 1 deletion src/drom_lib/share.ml
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ let load ?(args=default_args()) ?p () =
version
in
let drom_version = get_drom_version () in

let drom_version = match p with
| None -> drom_version
| Some p ->
if VersionCompare.compare drom_version p.project_drom_version > 0 then
drom_version
else
p.project_drom_version
in
if VersionCompare.compare drom_version Version.version > 0 then begin
Printf.eprintf "Error: you cannot update this project files:\n%!";
Printf.eprintf " Your drom version is too old: %s\n%!" Version.version;
Expand Down
14 changes: 13 additions & 1 deletion src/drom_lib/subst.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ let project_brace ({ p; _ } as state ) v =
| "edition" -> p.edition
| "min-edition" -> p.min_edition
| "github-organization" -> maybe_string p.github_organization
| "authors-ampersand" -> String.concat " & " p.authors
| "authors-as-strings" ->
String.concat ", " (List.map (Printf.sprintf "%S") p.authors)
| "authors-for-toml" ->
Expand All @@ -89,7 +90,6 @@ let project_brace ({ p; _ } as state ) v =
| "header-c" -> License.header_c state.share p
| "header-mly" -> License.header_mly state.share p
| "header-mll" -> License.header_mll state.share p
| "authors-ampersand" -> String.concat " & " p.authors
(* general *)
| "start_year" -> string_of_int p.year
| "years" ->
Expand Down Expand Up @@ -375,6 +375,9 @@ let project_paren state name =
""
| Some default -> default

let is_0_9_2_dev4 state =
VersionCompare.compare state.share.drom_version "0.9.2~dev4" >= 0

let package_brace state v =
let package = state.p in
match v with
Expand All @@ -386,6 +389,15 @@ let package_brace state v =
| exception Not_found -> package.name
| name -> name
end
| "synopsis" when is_0_9_2_dev4 state -> Misc.p_synopsis package
| "description" when is_0_9_2_dev4 state -> Misc.p_description package
| "version" when is_0_9_2_dev4 state -> Misc.p_version package
| "authors-ampersand" when is_0_9_2_dev4 state ->
String.concat " & " (Misc.p_authors package)
| "authors-as-strings" when is_0_9_2_dev4 state ->
String.concat ", " (List.map (Printf.sprintf "%S") (Misc.p_authors package))
| "authors-for-toml" when is_0_9_2_dev4 state ->
String.concat ", " (List.map (Printf.sprintf "\"%s\"") (Misc.p_authors package))
| "skeleton" -> Misc.package_skeleton package
| "library-name" -> Misc.library_name package
| "pack" -> Misc.library_module package
Expand Down
1 change: 1 addition & 0 deletions src/drom_lib/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ and project =
mutable menhir_version : string option; (* from sub-packages *)
(* common fields *)
mutable skeleton : string option;
project_drom_version : string ;
project_share_repo : string option ;
project_share_version : string option ;
edition : string;
Expand Down

0 comments on commit 6ce330a

Please sign in to comment.