Refactor workspace type
Make the opam workspace include the shared fields from a base type Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
6b29a24d89
commit
20fe7a9d20
|
@ -454,7 +454,8 @@ let create_for_opam ?root ~env ~targets ~profile ~switch ~name
|
||||||
let create ?merlin ~env def =
|
let create ?merlin ~env def =
|
||||||
match (def : Workspace.Context.t) with
|
match (def : Workspace.Context.t) with
|
||||||
| Default { targets; profile; _ } -> default ~env ~profile ~targets ?merlin ()
|
| Default { targets; profile; _ } -> default ~env ~profile ~targets ?merlin ()
|
||||||
| Opam { name; switch; root; targets; profile; _ } ->
|
| Opam { base = { targets ; profile ; loc = _ }
|
||||||
|
; name; switch; root; merlin = _ } ->
|
||||||
create_for_opam ?root ~env ~profile ~switch ~name ?merlin ~targets ()
|
create_for_opam ?root ~env ~profile ~switch ~name ?merlin ~targets ()
|
||||||
|
|
||||||
let which t s = which ~cache:t.which_cache ~path:t.path s
|
let which t s = which ~cache:t.which_cache ~path:t.path s
|
||||||
|
|
|
@ -40,60 +40,63 @@ module Context = struct
|
||||||
name)
|
name)
|
||||||
end
|
end
|
||||||
|
|
||||||
module Opam = struct
|
module Base = struct
|
||||||
type t =
|
|
||||||
{ loc : Loc.t
|
|
||||||
; name : string
|
|
||||||
; profile : string
|
|
||||||
; switch : string
|
|
||||||
; root : string option
|
|
||||||
; merlin : bool
|
|
||||||
; targets : Target.t list
|
|
||||||
}
|
|
||||||
|
|
||||||
let t ~profile ~x =
|
|
||||||
field "switch" string >>= fun switch ->
|
|
||||||
field "name" Name.t ~default:switch >>= fun name ->
|
|
||||||
field "targets" (list Target.t) ~default:[Target.Native] >>= fun targets ->
|
|
||||||
field_o "root" string >>= fun root ->
|
|
||||||
field_b "merlin" >>= fun merlin ->
|
|
||||||
field "profile" string ~default:profile >>= fun profile ->
|
|
||||||
loc >>= fun loc ->
|
|
||||||
return { loc
|
|
||||||
; switch
|
|
||||||
; name
|
|
||||||
; root
|
|
||||||
; merlin
|
|
||||||
; targets = Target.add targets x
|
|
||||||
; profile
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
module Default = struct
|
|
||||||
type t =
|
type t =
|
||||||
{ loc : Loc.t
|
{ loc : Loc.t
|
||||||
; profile : string
|
; profile : string
|
||||||
; targets : Target.t list
|
; targets : Target.t list
|
||||||
}
|
}
|
||||||
|
|
||||||
let t ~profile ~x =
|
let t ~profile =
|
||||||
field "targets" (list Target.t) ~default:[Target.Native]
|
field "targets" (list Target.t) ~default:[Target.Native]
|
||||||
>>= fun targets ->
|
>>= fun targets ->
|
||||||
field "profile" string ~default:profile
|
field "profile" string ~default:profile
|
||||||
>>= fun profile ->
|
>>= fun profile ->
|
||||||
loc
|
loc >>= fun loc ->
|
||||||
>>= fun loc ->
|
return
|
||||||
return { loc
|
{ targets
|
||||||
; targets = Target.add targets x
|
; profile
|
||||||
; profile
|
; loc
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
module Opam = struct
|
||||||
|
type t =
|
||||||
|
{ base : Base.t
|
||||||
|
; name : string
|
||||||
|
; switch : string
|
||||||
|
; root : string option
|
||||||
|
; merlin : bool
|
||||||
|
}
|
||||||
|
|
||||||
|
let t ~profile ~x =
|
||||||
|
Base.t ~profile >>= fun base ->
|
||||||
|
field "switch" string >>= fun switch ->
|
||||||
|
field "name" Name.t ~default:switch >>= fun name ->
|
||||||
|
field_o "root" string >>= fun root ->
|
||||||
|
field_b "merlin" >>= fun merlin ->
|
||||||
|
let base = { base with targets = Target.add base.targets x } in
|
||||||
|
return { base
|
||||||
|
; switch
|
||||||
|
; name
|
||||||
|
; root
|
||||||
|
; merlin
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Default = struct
|
||||||
|
type t = Base.t
|
||||||
|
|
||||||
|
let t ~profile ~x =
|
||||||
|
Base.t ~profile >>= fun t ->
|
||||||
|
return { t with targets = Target.add t.targets x }
|
||||||
|
end
|
||||||
|
|
||||||
type t = Default of Default.t | Opam of Opam.t
|
type t = Default of Default.t | Opam of Opam.t
|
||||||
|
|
||||||
let loc = function
|
let loc = function
|
||||||
| Default x -> x.loc
|
| Default x -> x.loc
|
||||||
| Opam x -> x.loc
|
| Opam x -> x.base.loc
|
||||||
|
|
||||||
let t ~profile ~x =
|
let t ~profile ~x =
|
||||||
sum
|
sum
|
||||||
|
@ -121,7 +124,7 @@ module Context = struct
|
||||||
|
|
||||||
let targets = function
|
let targets = function
|
||||||
| Default x -> x.targets
|
| Default x -> x.targets
|
||||||
| Opam x -> x.targets
|
| Opam x -> x.base.targets
|
||||||
|
|
||||||
let all_names t =
|
let all_names t =
|
||||||
let n = name t in
|
let n = name t in
|
||||||
|
|
|
@ -8,24 +8,25 @@ module Context : sig
|
||||||
| Native
|
| Native
|
||||||
| Named of string
|
| Named of string
|
||||||
end
|
end
|
||||||
module Opam : sig
|
module Base : sig
|
||||||
type t =
|
type t =
|
||||||
{ loc : Loc.t
|
{ loc : Loc.t
|
||||||
; name : string
|
|
||||||
; profile : string
|
; profile : string
|
||||||
|
; targets : Target.t list
|
||||||
|
}
|
||||||
|
end
|
||||||
|
module Opam : sig
|
||||||
|
type t =
|
||||||
|
{ base : Base.t
|
||||||
|
; name : string
|
||||||
; switch : string
|
; switch : string
|
||||||
; root : string option
|
; root : string option
|
||||||
; merlin : bool
|
; merlin : bool
|
||||||
; targets : Target.t list
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
module Default : sig
|
module Default : sig
|
||||||
type t =
|
type t = Base.t
|
||||||
{ loc : Loc.t
|
|
||||||
; profile : string
|
|
||||||
; targets : Target.t list
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
type t = Default of Default.t | Opam of Opam.t
|
type t = Default of Default.t | Opam of Opam.t
|
||||||
|
|
Loading…
Reference in New Issue