Move sexp's io functions to Io.Sexp
to avoid circular dependencies when adding Path.t to Io
This commit is contained in:
parent
0d76abca91
commit
79e434c658
|
@ -660,7 +660,7 @@ module Promotion = struct
|
||||||
|
|
||||||
let load_db () =
|
let load_db () =
|
||||||
if Sys.file_exists db_file then
|
if Sys.file_exists db_file then
|
||||||
Sexp.load ~fname:db_file ~mode:Many
|
Io.Sexp.load ~fname:db_file ~mode:Many
|
||||||
|> List.map ~f:File.t
|
|> List.map ~f:File.t
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Promoted_to_delete = struct
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
if Sys.file_exists fn then
|
if Sys.file_exists fn then
|
||||||
Sexp.load ~fname:fn ~mode:Many
|
Io.Sexp.load ~fname:fn ~mode:Many
|
||||||
|> List.map ~f:Path.t
|
|> List.map ~f:Path.t
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
@ -1126,7 +1126,7 @@ module Trace = struct
|
||||||
let load () =
|
let load () =
|
||||||
let trace = Hashtbl.create 1024 in
|
let trace = Hashtbl.create 1024 in
|
||||||
if Sys.file_exists file then begin
|
if Sys.file_exists file then begin
|
||||||
let sexp = Sexp.load ~fname:file ~mode:Single in
|
let sexp = Io.Sexp.load ~fname:file ~mode:Single in
|
||||||
let bindings =
|
let bindings =
|
||||||
let open Sexp.Of_sexp in
|
let open Sexp.Of_sexp in
|
||||||
list (pair Path.t (fun s -> Digest.from_hex (string s))) sexp
|
list (pair Path.t (fun s -> Digest.from_hex (string s))) sexp
|
||||||
|
@ -1207,7 +1207,7 @@ let update_universe t =
|
||||||
let fname = Path.to_string universe_file in
|
let fname = Path.to_string universe_file in
|
||||||
let n =
|
let n =
|
||||||
if Sys.file_exists fname then
|
if Sys.file_exists fname then
|
||||||
Sexp.Of_sexp.int (Sexp.load ~mode:Single ~fname) + 1
|
Sexp.Of_sexp.int (Io.Sexp.load ~mode:Single ~fname) + 1
|
||||||
else
|
else
|
||||||
0
|
0
|
||||||
in
|
in
|
||||||
|
|
|
@ -81,7 +81,7 @@ let t =
|
||||||
let user_config_file = Filename.concat Xdg.config_dir "dune/config"
|
let user_config_file = Filename.concat Xdg.config_dir "dune/config"
|
||||||
|
|
||||||
let load_config_file ~fname =
|
let load_config_file ~fname =
|
||||||
t (Sexp.load_many_as_one ~fname)
|
t (Io.Sexp.load_many_as_one ~fname)
|
||||||
|
|
||||||
let load_user_config_file () =
|
let load_user_config_file () =
|
||||||
if Sys.file_exists user_config_file then
|
if Sys.file_exists user_config_file then
|
||||||
|
|
|
@ -39,7 +39,7 @@ let of_sexp =
|
||||||
(fun () l -> parse_sub_systems l)
|
(fun () l -> parse_sub_systems l)
|
||||||
]
|
]
|
||||||
|
|
||||||
let load ~fname = of_sexp (Sexp.load ~mode:Single ~fname)
|
let load ~fname = of_sexp (Io.Sexp.load ~mode:Single ~fname)
|
||||||
|
|
||||||
let gen confs =
|
let gen confs =
|
||||||
let sexps =
|
let sexps =
|
||||||
|
|
|
@ -1244,7 +1244,7 @@ module Stanzas = struct
|
||||||
(Path.to_string_maybe_quoted file);
|
(Path.to_string_maybe_quoted file);
|
||||||
if List.exists include_stack ~f:(fun (_, f) -> f = file) then
|
if List.exists include_stack ~f:(fun (_, f) -> f = file) then
|
||||||
raise (Include_loop (file, include_stack));
|
raise (Include_loop (file, include_stack));
|
||||||
let sexps = Sexp.load ~fname:(Path.to_string file) ~mode:Many in
|
let sexps = Io.Sexp.load ~fname:(Path.to_string file) ~mode:Many in
|
||||||
parse pkgs sexps ~default_version:Jbuild_version.V1 ~file ~include_stack)
|
parse pkgs sexps ~default_version:Jbuild_version.V1 ~file ~include_stack)
|
||||||
; cstr "documentation" (Documentation.v1 pkgs @> nil)
|
; cstr "documentation" (Documentation.v1 pkgs @> nil)
|
||||||
(fun d -> [Documentation d])
|
(fun d -> [Documentation d])
|
||||||
|
|
|
@ -157,7 +157,7 @@ end
|
||||||
die "@{<error>Error:@} %s failed to produce a valid jbuild file.\n\
|
die "@{<error>Error:@} %s failed to produce a valid jbuild file.\n\
|
||||||
Did you forgot to call [Jbuild_plugin.V*.send]?"
|
Did you forgot to call [Jbuild_plugin.V*.send]?"
|
||||||
(Path.to_string file);
|
(Path.to_string file);
|
||||||
let sexps = Sexp.load ~fname:(Path.to_string generated_jbuild) ~mode:Many in
|
let sexps = Io.Sexp.load ~fname:(Path.to_string generated_jbuild) ~mode:Many in
|
||||||
Fiber.return (dir, scope, Stanzas.parse scope sexps ~file:generated_jbuild
|
Fiber.return (dir, scope, Stanzas.parse scope sexps ~file:generated_jbuild
|
||||||
|> filter_stanzas ~ignore_promoted_rules))
|
|> filter_stanzas ~ignore_promoted_rules))
|
||||||
>>| fun dynamic ->
|
>>| fun dynamic ->
|
||||||
|
@ -184,14 +184,14 @@ module Sexp_io = struct
|
||||||
let load_many_or_ocaml_script fname =
|
let load_many_or_ocaml_script fname =
|
||||||
Io.with_file_in fname ~f:(fun ic ->
|
Io.with_file_in fname ~f:(fun ic ->
|
||||||
let state = Parser.create ~fname ~mode:Many in
|
let state = Parser.create ~fname ~mode:Many in
|
||||||
let buf = Bytes.create buf_len in
|
let buf = Bytes.create Io.buf_len in
|
||||||
let rec loop stack =
|
let rec loop stack =
|
||||||
match input ic buf 0 buf_len with
|
match input ic buf 0 Io.buf_len with
|
||||||
| 0 -> Parser.feed_eoi state stack
|
| 0 -> Parser.feed_eoi state stack
|
||||||
| n -> loop (Parser.feed_subbytes state buf ~pos:0 ~len:n stack)
|
| n -> loop (Parser.feed_subbytes state buf ~pos:0 ~len:n stack)
|
||||||
in
|
in
|
||||||
let rec loop0 stack i =
|
let rec loop0 stack i =
|
||||||
match input ic buf i (buf_len - i) with
|
match input ic buf i (Io.buf_len - i) with
|
||||||
| 0 ->
|
| 0 ->
|
||||||
let stack = Parser.feed_subbytes state buf ~pos:0 ~len:i stack in
|
let stack = Parser.feed_subbytes state buf ~pos:0 ~len:i stack in
|
||||||
Sexps (Parser.feed_eoi state stack)
|
Sexps (Parser.feed_eoi state stack)
|
||||||
|
|
|
@ -76,3 +76,28 @@ let copy_file ~src ~dst =
|
||||||
|
|
||||||
(* TODO: diml: improve this *)
|
(* TODO: diml: improve this *)
|
||||||
let compare_files fn1 fn2 = String.compare (read_file fn1) (read_file fn2)
|
let compare_files fn1 fn2 = String.compare (read_file fn1) (read_file fn2)
|
||||||
|
|
||||||
|
let buf_len = 65_536
|
||||||
|
|
||||||
|
module Sexp = struct
|
||||||
|
open Sexp
|
||||||
|
|
||||||
|
let load ~fname ~mode =
|
||||||
|
with_file_in fname ~f:(fun ic ->
|
||||||
|
let state = Parser.create ~fname ~mode in
|
||||||
|
let buf = Bytes.create buf_len in
|
||||||
|
let rec loop stack =
|
||||||
|
match input ic buf 0 buf_len with
|
||||||
|
| 0 -> Parser.feed_eoi state stack
|
||||||
|
| n -> loop (Parser.feed_subbytes state buf ~pos:0 ~len:n stack)
|
||||||
|
in
|
||||||
|
loop Parser.Stack.empty)
|
||||||
|
|
||||||
|
let load_many_as_one ~fname =
|
||||||
|
match load ~fname ~mode:Many with
|
||||||
|
| [] -> Ast.List (Loc.in_file fname, [])
|
||||||
|
| x :: l ->
|
||||||
|
let last = Option.value (List.last l) ~default:x in
|
||||||
|
let loc = { (Ast.loc x) with stop = (Ast.loc last).stop } in
|
||||||
|
Ast.List (loc, x :: l)
|
||||||
|
end
|
||||||
|
|
|
@ -25,3 +25,12 @@ val copy_channels : in_channel -> out_channel -> unit
|
||||||
val copy_file : src:string -> dst:string -> unit
|
val copy_file : src:string -> dst:string -> unit
|
||||||
|
|
||||||
val read_all : in_channel -> string
|
val read_all : in_channel -> string
|
||||||
|
|
||||||
|
module Sexp : sig
|
||||||
|
val load : fname:string -> mode:'a Sexp.Parser.Mode.t -> 'a
|
||||||
|
val load_many_as_one : fname:string -> Sexp.Ast.t
|
||||||
|
end
|
||||||
|
|
||||||
|
(**/**)
|
||||||
|
(* used in jbuild_load *)
|
||||||
|
val buf_len : int
|
||||||
|
|
|
@ -1,26 +1,5 @@
|
||||||
include Usexp
|
include Usexp
|
||||||
|
|
||||||
let buf_len = 65_536
|
|
||||||
|
|
||||||
let load ~fname ~mode =
|
|
||||||
Io.with_file_in fname ~f:(fun ic ->
|
|
||||||
let state = Parser.create ~fname ~mode in
|
|
||||||
let buf = Bytes.create buf_len in
|
|
||||||
let rec loop stack =
|
|
||||||
match input ic buf 0 buf_len with
|
|
||||||
| 0 -> Parser.feed_eoi state stack
|
|
||||||
| n -> loop (Parser.feed_subbytes state buf ~pos:0 ~len:n stack)
|
|
||||||
in
|
|
||||||
loop Parser.Stack.empty)
|
|
||||||
|
|
||||||
let load_many_as_one ~fname =
|
|
||||||
match load ~fname ~mode:Many with
|
|
||||||
| [] -> Ast.List (Loc.in_file fname, [])
|
|
||||||
| x :: l ->
|
|
||||||
let last = Option.value (List.last l) ~default:x in
|
|
||||||
let loc = { (Ast.loc x) with stop = (Ast.loc last).stop } in
|
|
||||||
Ast.List (loc, x :: l)
|
|
||||||
|
|
||||||
module type Combinators = sig
|
module type Combinators = sig
|
||||||
type 'a t
|
type 'a t
|
||||||
val unit : unit t
|
val unit : unit t
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
include module type of struct include Usexp end with module Loc := Usexp.Loc
|
include module type of struct include Usexp end with module Loc := Usexp.Loc
|
||||||
|
|
||||||
val load : fname:string -> mode:'a Parser.Mode.t -> 'a
|
|
||||||
val load_many_as_one : fname:string -> Ast.t
|
|
||||||
|
|
||||||
module type Combinators = sig
|
module type Combinators = sig
|
||||||
type 'a t
|
type 'a t
|
||||||
val unit : unit t
|
val unit : unit t
|
||||||
|
@ -155,7 +152,3 @@ module Of_sexp : sig
|
||||||
|
|
||||||
val enum : (string * 'a) list -> 'a t
|
val enum : (string * 'a) list -> 'a t
|
||||||
end
|
end
|
||||||
|
|
||||||
(**/**)
|
|
||||||
(* used in jbuild_load *)
|
|
||||||
val buf_len : int
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ module Cached_digest = struct
|
||||||
|
|
||||||
let load () =
|
let load () =
|
||||||
if Sys.file_exists db_file then begin
|
if Sys.file_exists db_file then begin
|
||||||
let sexp = Sexp.load ~fname:db_file ~mode:Single in
|
let sexp = Io.Sexp.load ~fname:db_file ~mode:Single in
|
||||||
let bindings =
|
let bindings =
|
||||||
let open Sexp.Of_sexp in
|
let open Sexp.Of_sexp in
|
||||||
list
|
list
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct
|
||||||
let to_string path x = To_sexp.t path x |> Sexp.to_string
|
let to_string path x = To_sexp.t path x |> Sexp.to_string
|
||||||
|
|
||||||
let load path =
|
let load path =
|
||||||
Of_sexp.t path (Sexp.load ~fname:(Path.to_string path) ~mode:Single)
|
Of_sexp.t path (Io.Sexp.load ~fname:(Path.to_string path) ~mode:Single)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -135,4 +135,4 @@ let t ?x sexps =
|
||||||
; contexts = List.rev contexts
|
; contexts = List.rev contexts
|
||||||
}
|
}
|
||||||
|
|
||||||
let load ?x fname = t ?x (Sexp.load ~fname ~mode:Many)
|
let load ?x fname = t ?x (Io.Sexp.load ~fname ~mode:Many)
|
||||||
|
|
Loading…
Reference in New Issue