Skip to content

Commit

Permalink
refactor: move [Lib_name] to [Dune_lang] (#8081)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg authored Jul 3, 2023
1 parent b3f033b commit 6467301
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 24 deletions.
16 changes: 11 additions & 5 deletions bin/arg.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
open Stdune
include Cmdliner.Arg
module Stanza = Dune_lang.Stanza
module String_with_vars = Dune_lang.String_with_vars
module Profile = Dune_lang.Profile
module Pform = Dune_lang.Pform

include struct
open Dune_lang
module Stanza = Stanza
module String_with_vars = String_with_vars
module Profile = Profile
module Pform = Pform
module Lib_name = Lib_name
end

module Dep_conf = Dune_rules.Dep_conf
module Package = Dune_rules.Package
module Context_name = Dune_engine.Context_name
Expand Down Expand Up @@ -132,6 +138,6 @@ let graph_format : Dune_graph.Graph.File_format.t conv =

let context_name : Context_name.t conv = conv Context_name.conv

let lib_name = conv Dune_rules.Lib_name.conv
let lib_name = conv Lib_name.conv

let version = pair ~sep:'.' int int
2 changes: 1 addition & 1 deletion bin/arg.mli
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ val package_name : Package.Name.t conv

val profile : Dune_lang.Profile.t conv

val lib_name : Lib_name.t conv
val lib_name : Dune_lang.Lib_name.t conv

val version : Dune_lang.Syntax.Version.t conv
2 changes: 1 addition & 1 deletion bin/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ include struct
open Dune_rules
module Super_context = Super_context
module Context = Context
module Lib_name = Lib_name
module Workspace = Workspace
module Package = Package
module Section = Install.Section
Expand Down Expand Up @@ -59,6 +58,7 @@ include struct
open Dune_lang
module Stanza = Stanza
module Profile = Profile
module Lib_name = Lib_name
end

module Log = Dune_util.Log
Expand Down
1 change: 1 addition & 0 deletions src/dune_lang/dune_lang.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include Dune_sexp
module Lib_name = Lib_name
module Alias = Alias
module Format = Format
module Stanza = Stanza
Expand Down
17 changes: 10 additions & 7 deletions src/dune_rules/lib_name.ml → src/dune_lang/lib_name.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
open Import
open Stdune
module Stringlike = Dune_util.Stringlike

module type Stringlike = Dune_util.Stringlike

let private_key = "__private__"

Expand Down Expand Up @@ -62,7 +65,7 @@ end
let split t =
match String.split t ~on:'.' with
| [] -> assert false
| pkg :: rest -> (Package.Name.of_string pkg, rest)
| pkg :: rest -> (Package_name.of_string pkg, rest)

let to_local = Local.of_string_user_error

Expand Down Expand Up @@ -93,8 +96,8 @@ include Stringlike.Make (struct
end)

type analyze =
| Public of Package.Name.t * string list
| Private of Package.Name.t * Local.t
| Public of Package_name.t * string list
| Private of Package_name.t * Local.t

let analyze t =
let pkg, rest = split t in
Expand All @@ -104,11 +107,11 @@ let analyze t =

let mangled pkg local_name =
let under_pkg = Local.mangled_path_under_package local_name in
Package.Name.to_string pkg :: under_pkg |> String.concat ~sep:"." |> of_string
Package_name.to_string pkg :: under_pkg |> String.concat ~sep:"." |> of_string

let of_local (_loc, t) = t

let of_package_name p = Package.Name.to_string p
let of_package_name p = Package_name.to_string p

let hash = String.hash

Expand All @@ -126,7 +129,7 @@ module Set = struct
end

let package_name t =
Package.Name.of_string
Package_name.of_string
(match String.lsplit2 t ~on:'.' with
| None -> t
| Some (p, _) -> p)
Expand Down
18 changes: 9 additions & 9 deletions src/dune_rules/lib_name.mli → src/dune_lang/lib_name.mli
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
open Import
open Stdune

type t

val hash : t -> int

include Stringlike with type t := t
include Dune_util.Stringlike with type t := t

module Local : sig
include Stringlike
include Dune_util.Stringlike

(** Description of valid library names *)
val valid_format_doc : User_message.Style.t Pp.t
Expand All @@ -25,19 +25,19 @@ val to_local : Loc.t * t -> (Local.t, User_message.t) result

val to_local_exn : t -> Local.t

val split : t -> Package.Name.t * string list
val split : t -> Package_name.t * string list

val package_name : t -> Package.Name.t
val package_name : t -> Package_name.t

val of_package_name : Package.Name.t -> t
val of_package_name : Package_name.t -> t

type analyze =
| Public of Package.Name.t * string list
| Private of Package.Name.t * Local.t
| Public of Package_name.t * string list
| Private of Package_name.t * Local.t

val analyze : t -> analyze

val mangled : Package.Name.t -> Local.t -> t
val mangled : Package_name.t -> Local.t -> t

module Map : Map.S with type key = t

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 @@ -50,7 +50,6 @@ module Coq_sources = Coq_sources
module Coq_lib_name = Coq_lib_name
module Coq_lib = Coq_lib
module Command = Command
module Lib_name = Lib_name
module Clflags = Clflags
module Dune_project = Dune_project
module Source_tree = Source_tree
Expand Down
2 changes: 2 additions & 0 deletions src/dune_rules/gen_meta.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Import

(** Generate a META file *)

val requires : ?preds:Meta.predicate list -> Lib_name.Set.t -> Meta.entry
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 @@ -59,6 +59,7 @@ module Syntax = Dune_sexp.Syntax

include struct
open Dune_lang
module Lib_name = Lib_name
module Wrapped = Wrapped
module Targets_spec = Targets_spec
module Profile = Profile
Expand Down
1 change: 1 addition & 0 deletions test/expect-tests/findlib_tests.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
open Stdune
module Lib_name = Dune_lang.Lib_name
open Dune_rules
open Dune_rules.For_tests
open Dune_tests_common
Expand Down

0 comments on commit 6467301

Please sign in to comment.