-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added --output/-o, refactoring, optimizations
- Loading branch information
Showing
8 changed files
with
223 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
open! Core | ||
|
||
type t = { | ||
path: string; | ||
strings: string Queue.t; | ||
possible_scripts: string Queue.t; | ||
file_errors: string Queue.t; | ||
} | ||
[@@deriving sexp] | ||
|
||
let create ~path = | ||
{ path; strings = Queue.create (); possible_scripts = Queue.create (); file_errors = Queue.create () } | ||
|
||
let render_errors { file_errors; path; _ } = | ||
match Queue.length file_errors with | ||
| 0 -> None | ||
| 1 -> | ||
let buf = Buffer.create 256 in | ||
bprintf buf "\n❌ 1 error in %s: %s" path (Queue.get file_errors 0); | ||
Some (Buffer.contents buf) | ||
| len -> | ||
let buf = Buffer.create 256 in | ||
bprintf buf "\n❌ %d errors in %s:\n" len path; | ||
Queue.iter file_errors ~f:(bprintf buf "- %s\n"); | ||
Some (Buffer.contents buf) | ||
|
||
let blit_transfer ~src ~dst = | ||
Queue.blit_transfer ~src:src.strings ~dst:dst.strings (); | ||
Queue.blit_transfer ~src:src.possible_scripts ~dst:dst.possible_scripts (); | ||
Queue.blit_transfer ~src:src.file_errors ~dst:dst.file_errors () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
open! Core | ||
|
||
let human = function | ||
| Failure msg -> msg | ||
| Lwt.Canceled -> "Timed out." | ||
| Core_unix.Unix_error (c, n, p) -> | ||
sprintf {s|System Error "%s" during '%s("%s")'|s} (String.uppercase (Core_unix.Error.message c)) n p | ||
| unknown -> Exn.to_string unknown | ||
|
||
let full ex = sprintf !"%s\n%{Backtrace}" (human ex) (Backtrace.get ()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
open! Core | ||
open Lwt.Infix | ||
open Lwt.Syntax | ||
|
||
let read_flags = Core_unix.[ O_RDONLY; O_NONBLOCK ] | ||
|
||
let write_flags = Core_unix.[ O_WRONLY; O_NONBLOCK; O_TRUNC; O_CREAT ] | ||
|
||
let directory_exists path = | ||
Lwt.try_bind | ||
(fun () -> Lwt_unix.stat path) | ||
(function | ||
| { st_kind = S_DIR; _ } -> Lwt.return_true | ||
| { st_kind = _; _ } -> failwithf "%s already exists, but is not a directory" path ()) | ||
(fun _ -> Lwt.return_false) | ||
|
||
let mkdir_p ~dir_name ~perms = | ||
let+ (_ : string) = | ||
Filename.parts dir_name | ||
|> Lwt_list.fold_left_s | ||
(fun acc part -> | ||
match acc with | ||
| "" -> Lwt.return part | ||
| acc -> ( | ||
let path = Filename.concat acc part in | ||
Lwt_unix.file_exists path >>= function | ||
| true -> Lwt.return path | ||
| false -> | ||
let+ () = Lwt_unix.mkdir path perms in | ||
path)) | ||
"" | ||
in | ||
() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
open! Core | ||
|
||
let start () = | ||
let t0 = Time_now.nanoseconds_since_unix_epoch () in | ||
fun `Stop -> | ||
let t1 = Time_now.nanoseconds_since_unix_epoch () in | ||
Int63.((t1 - t0) / of_int 1_000_000) |
This file was deleted.
Oops, something went wrong.