Skip to content

Commit

Permalink
refactor: remove [Dune_rules.Package] (#10818)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Aug 11, 2024
1 parent 0862778 commit 1f9dd2e
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 107 deletions.
2 changes: 1 addition & 1 deletion bin/arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include struct
module Dep_conf = Dep_conf
end

module Package = Dune_rules.Package
module Package = Dune_lang.Package
module Context_name = Dune_engine.Context_name

let package_name = conv Package.Name.conv
Expand Down
2 changes: 1 addition & 1 deletion bin/arg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val dep : Dep.t conv
val graph_format : Dune_graph.Graph.File_format.t conv
val path : Path.t conv
val external_path : Path.External.t conv
val package_name : Dune_rules.Package.Name.t conv
val package_name : Dune_lang.Package.Name.t conv
val profile : Dune_lang.Profile.t conv
val lib_name : Dune_lang.Lib_name.t conv
val version : Dune_lang.Syntax.Version.t conv
3 changes: 2 additions & 1 deletion bin/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ end

open struct
open Dune_rules
module Package = Package
module Colors = Colors
module Only_packages = Only_packages
end
Expand All @@ -26,6 +25,8 @@ open struct
module Manpage = Manpage
end

module Package = Dune_lang.Package

module Let_syntax = struct
let ( let+ ) t f = Term.(const f $ t)
let ( and+ ) a b = Term.(const (fun x y -> x, y) $ a $ b)
Expand Down
2 changes: 1 addition & 1 deletion bin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ include struct
module Super_context = Super_context
module Context = Context
module Workspace = Workspace
module Package = Package
module Dune_project = Dune_project
module Dune_package = Dune_package
module Resolve = Resolve
Expand Down Expand Up @@ -67,6 +66,7 @@ include struct
module Profile = Profile
module Lib_name = Lib_name
module Package_name = Package_name
module Package = Package
module Package_version = Package_version
module Source_kind = Source_kind
module Package_info = Package_info
Expand Down
84 changes: 84 additions & 0 deletions src/dune_pkg/opam_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,87 @@ module Create = struct
{ file_contents; file_name }
;;
end

let load_opam_file_with_contents ~contents:opam_file_string file name =
let loc = Loc.in_file (Path.source file) in
let opam =
let opam =
let lexbuf =
Lexbuf.from_string opam_file_string ~fname:(Path.Source.to_string file)
in
try Ok (parse lexbuf) with
| User_error.E _ as exn -> Error exn
in
match opam with
| Ok s -> Some s
| Error exn ->
(* CR-rgrinberg: make it possible to disable this warning *)
User_warning.emit
~loc
[ Pp.text
"Unable to read opam file. Some information about this package such as its \
version will be ignored."
; Pp.textf "Reason: %s" (Printexc.to_string exn)
];
None
in
let open Option.O in
let get_one name =
let* value =
let* opam = opam in
get_field opam name
in
match value.pelem with
| String s -> Some s
| _ -> None
in
let get_many name =
let* value =
let* opam = opam in
get_field opam name
in
match value.pelem with
| String s -> Some [ s ]
| List l ->
List.fold_left
l.pelem
~init:(Some [])
~f:(fun acc (v : OpamParserTypes.FullPos.value) ->
let* acc = acc in
match v.pelem with
| String s -> Some (s :: acc)
| _ -> None)
>>| List.rev
| _ -> None
in
let dir = Path.Source.parent_exn file in
let info =
Dune_lang.Package_info.create
~maintainers:(get_many "maintainer")
~authors:(get_many "authors")
~homepage:(get_one "homepage")
~bug_reports:(get_one "bug-reports")
~documentation:(get_one "doc")
~license:(get_many "license")
~source:
(let+ url = get_one "dev-repo" in
Dune_lang.Source_kind.Url url)
in
Dune_lang.Package.create
~name
~dir
~loc
~version:(get_one "version" |> Option.map ~f:Package_version.of_string)
~conflicts:[]
~depends:[]
~depopts:[]
~info
~synopsis:(get_one "synopsis")
~description:(get_one "description")
~has_opam_file:(Exists true)
~tags:(Option.value (get_many "tags") ~default:[])
~deprecated_package_names:Package_name.Map.empty
~sites:Dune_lang.Site.Map.empty
~allow_empty:true
~original_opam_file:(Some { file; contents = opam_file_string })
;;
7 changes: 7 additions & 0 deletions src/dune_pkg/opam_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ module Create : sig
val normalise_field_order : (string * value) list -> (string * value) list
val of_bindings : (string * value) list -> file:Path.t -> t
end

(** Construct a package description from an opam file and its contents *)
val load_opam_file_with_contents
: contents:string
-> Path.Source.t
-> Package_name.t
-> Dune_lang.Package.t
2 changes: 1 addition & 1 deletion src/dune_rules/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,7 @@ let gen_load ~read ~dir ~files ~infer_from_opam_files : t option Memo.t =
let loc = Loc.in_file (Path.source opam_file) in
let pkg =
let+ contents = read opam_file in
Package.load_opam_file_with_contents ~contents opam_file name
Dune_pkg.Opam_file.load_opam_file_with_contents ~contents opam_file name
in
(name, (loc, pkg)) :: acc)
|> Package.Name.Map.of_list_exn
Expand Down
1 change: 0 additions & 1 deletion src/dune_rules/dune_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ module Dune_project = Dune_project
module Source_tree = Source_tree
module Source_dir_status = Source_dir_status
module Dune_file0 = Dune_file0
module Package = Package
module Dialect = Dialect
module Private_context = Private_context
module Odoc = Odoc
Expand Down
1 change: 1 addition & 0 deletions src/dune_rules/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ include struct
module Package_dependency = Package_dependency
module Package_constraint = Package_constraint
module Dune_project_name = Dune_project_name
module Package = Package
end

include Dune_engine.No_io
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,8 @@ end = struct
Some (name, entries)
;;

module Package_map_traversals = Memo.Make_parallel_map (Package.Name.Map)

let stanzas_to_entries sctx =
let ctx = Context.build_context (Super_context.context sctx) in
let* stanzas = Dune_load.dune_files ctx.name in
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/only_packages.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Import

(** Restrict the set of visible packages *)

module Clflags : sig
Expand Down
87 changes: 0 additions & 87 deletions src/dune_rules/package.ml

This file was deleted.

7 changes: 0 additions & 7 deletions src/dune_rules/package.mli

This file was deleted.

1 change: 0 additions & 1 deletion src/dune_rules/package_map_traversals.ml

This file was deleted.

5 changes: 0 additions & 5 deletions src/dune_rules/package_map_traversals.mli

This file was deleted.

8 changes: 7 additions & 1 deletion test/expect-tests/findlib_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ open Stdune
module Lib_name = Dune_lang.Lib_name
module Meta = Dune_findlib.Findlib.Meta
module Findlib_config = Dune_findlib.Findlib.Config
module Lib_dep = Dune_lang.Lib_dep

include struct
open Dune_lang
module Lib_dep = Lib_dep
module Package = Package
end

open Dune_rules
open Dune_rules.For_tests
open Dune_tests_common
Expand Down

0 comments on commit 1f9dd2e

Please sign in to comment.