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

Make File_bindings.Expanded.t type more precise #2041

Merged
merged 1 commit into from
Apr 10, 2019
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
12 changes: 9 additions & 3 deletions src/file_binding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type ('src, 'dst) t =
}

module Expanded = struct
type nonrec t = (Loc.t * Path.t, Loc.t * string) t
type nonrec t = (Loc.t * Path.t, Loc.t * Path.Local.t) t

let src t = snd t.src
let dst t = Option.map ~f:snd t.dst
Expand All @@ -21,9 +21,10 @@ module Expanded = struct
let basename = Path.basename src in
String.drop_suffix basename ~suffix:".exe"
|> Option.value ~default:basename
|> Path.Local.of_string

let dst_path t ~dir =
Path.relative dir (dst_basename t)
Path.append_local dir (dst_basename t)
end

module Unexpanded = struct
Expand All @@ -43,7 +44,12 @@ module Unexpanded = struct
(loc, Path.relative dir expanded)
in
{ src
; dst = Option.map ~f t.dst
; dst =
let f sw =
let (loc, p) = f sw in
(loc, Path.Local.of_string p)
in
Option.map ~f t.dst
}

module L = struct
Expand Down
2 changes: 1 addition & 1 deletion src/file_binding.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Expanded : sig
type t

val src : t -> Path.t
val dst : t -> string option
val dst : t -> Path.Local.t option

val src_loc : t -> Loc.t

Expand Down
3 changes: 2 additions & 1 deletion src/install_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,8 @@ let init_binary_artifacts sctx package =
List.map files ~f:(fun fb ->
let loc = File_binding.Expanded.src_loc fb in
let src = File_binding.Expanded.src fb in
let dst = File_binding.Expanded.dst fb in
let dst = Option.map ~f:Path.Local.to_string
(File_binding.Expanded.dst fb) in
( Some loc
, Install.Entry.make section src ?dst
)))
Expand Down
1 change: 1 addition & 0 deletions src/stdune/path.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Local : sig
val to_sexp : t -> Sexp.t
val equal : t -> t -> bool
val to_string : t -> string
val of_string : ?error_loc:Loc0.t -> string -> t
val pp : Format.formatter -> t -> unit
module L : sig
val relative : ?error_loc:Loc0.t -> t -> string list -> t
Expand Down