From d6a6a817f7e1681f79e40f42bc4c0bbef5a6e861 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Tue, 13 Mar 2018 20:27:07 +0700 Subject: [PATCH] Move Io to stdune This allows configurator to drop the dependency on jbuilder itself --- src/configurator/configurator.ml | 1 - src/configurator/jbuild | 2 +- src/{ => stdune}/io.ml | 14 ++++++-------- src/{ => stdune}/io.mli | 2 -- src/stdune/jbuild | 2 +- src/stdune/stdune.ml | 1 + 6 files changed, 9 insertions(+), 13 deletions(-) rename src/{ => stdune}/io.ml (86%) rename src/{ => stdune}/io.mli (98%) diff --git a/src/configurator/configurator.ml b/src/configurator/configurator.ml index 6de14d78..7b676e8c 100644 --- a/src/configurator/configurator.ml +++ b/src/configurator/configurator.ml @@ -1,7 +1,6 @@ open Stdune let sprintf = Printf.sprintf let eprintf = Printf.eprintf -module Io = Jbuilder.Io let ( ^/ ) = Filename.concat diff --git a/src/configurator/jbuild b/src/configurator/jbuild index 46c21619..03b0c4fd 100644 --- a/src/configurator/jbuild +++ b/src/configurator/jbuild @@ -1,7 +1,7 @@ (library ((name configurator) (flags (:standard -safe-string)) - (libraries (jbuilder stdune)) + (libraries (stdune ocaml_config)) (preprocess no_preprocessing))) (jbuild_version 1) diff --git a/src/io.ml b/src/stdune/io.ml similarity index 86% rename from src/io.ml rename to src/stdune/io.ml index 78acf2d6..fc39d707 100644 --- a/src/io.ml +++ b/src/stdune/io.ml @@ -1,5 +1,3 @@ -open Import - module P = Pervasives let open_in ?(binary=true) fn = @@ -12,10 +10,10 @@ let close_in = close_in let close_out = close_out let with_file_in ?binary fn ~f = - protectx (open_in ?binary fn) ~finally:close_in ~f + Exn.protectx (open_in ?binary fn) ~finally:close_in ~f let with_file_out ?binary fn ~f = - protectx (open_out ?binary fn) ~finally:close_out ~f + Exn.protectx (open_out ?binary fn) ~finally:close_out ~f let with_lexbuf_from_file fn ~f = with_file_in fn ~f:(fun ic -> @@ -68,10 +66,10 @@ let copy_channels = let copy_file ~src ~dst = with_file_in src ~f:(fun ic -> let perm = (Unix.fstat (Unix.descr_of_in_channel ic)).st_perm in - protectx (P.open_out_gen - [Open_wronly; Open_creat; Open_trunc; Open_binary] - perm - dst) + Exn.protectx (P.open_out_gen + [Open_wronly; Open_creat; Open_trunc; Open_binary] + perm + dst) ~finally:close_out ~f:(fun oc -> copy_channels ic oc)) diff --git a/src/io.mli b/src/stdune/io.mli similarity index 98% rename from src/io.mli rename to src/stdune/io.mli index 227dbfb9..9b621f36 100644 --- a/src/io.mli +++ b/src/stdune/io.mli @@ -1,7 +1,5 @@ (** IO operations *) -open Stdune - val open_in : ?binary:bool (* default true *) -> string -> in_channel val open_out : ?binary:bool (* default true *) -> string -> out_channel diff --git a/src/stdune/jbuild b/src/stdune/jbuild index ce7f7e81..36e4eaa0 100644 --- a/src/stdune/jbuild +++ b/src/stdune/jbuild @@ -1,4 +1,4 @@ (library ((name stdune) (synopsis "Standard library of Dune") - (libraries (caml)))) + (libraries (caml unix)))) diff --git a/src/stdune/stdune.ml b/src/stdune/stdune.ml index 44c8ecd2..9e1c4541 100644 --- a/src/stdune/stdune.ml +++ b/src/stdune/stdune.ml @@ -15,6 +15,7 @@ module Result = Result module Set = Set module Staged = Staged module String = String +module Io = Io external reraise : exn -> _ = "%reraise"