Commits

Dmitry Grebeniuk  committed f33701f Draft

+ Install.patch

  • Participants
  • Parent commits 773b5a5

Comments (0)

Files changed (2)

File src/common.ml

            )
         )
 
-    let run ~show argv =
+    let run_gen ~stdin ~show argv =
       if argv = [| |]
       then invalid_arg "Reb_sys.run: empty argv"
       else
       let pid =
-        let f = Unix.create_process argv.(0) argv Unix.stdin in
+        let f = Unix.create_process argv.(0) argv stdin in
         if show
         then f Unix.stdout Unix.stderr
         else let n = Lazy.force null_fd_write in f n n
           (dump_argv argv) s
       | Unix.WSTOPPED _ -> assert false
 
+    let run =
+      run_gen ~stdin:Unix.stdin
+
 
     let lines_of_process cmd =
       let ch = Unix.open_process_in cmd in

File src/pre_template.ml

     val make : string list (* targets *) -> installation_instructions
     val none : installation_instructions
     val run : string list -> installation_instructions
+    val patch : ?p:int -> string -> installation_instructions
   end
  =
   struct
         | c -> failwith "Install.run: command %s exited with code %i"
                  (Reb_sys.dump_argv argv) c
 
+    let patch ?(p=1) patchfn = fun () ->
+      try
+        let pfd = openfile patchfn [O_RDONLY] 0 in
+        let finally () = close pfd in
+        let c = Reb_sys.run_gen ~stdin:pfd ~show:true
+          [| "patch" ; Printf.sprintf "-p%i" p |] in
+        let () =
+          match c with
+          | 0 -> ()
+          | c -> ( finally ()
+                 ; failwith "\"patch\" command exited with code %i" c
+                 )
+        in
+        finally ()
+      with
+      | e -> failchain e "Install.patch: error applying patch -p%i %S in \
+                          directory %S"
+               p patchfn (Sys.getcwd ())
+
   end