Skip to content

Commit

Permalink
Minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
SGrondin committed Jun 18, 2023
1 parent b13e7d5 commit 462c14a
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 373 deletions.
94 changes: 0 additions & 94 deletions src/angstrom_eio/angstrom_eio.ml

This file was deleted.

68 changes: 0 additions & 68 deletions src/angstrom_eio/angstrom_eio.mli

This file was deleted.

1 change: 1 addition & 0 deletions src/cli/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
(libraries
parsing
quickjs
dispatcher
utils

stdlib-shims
Expand Down
25 changes: 14 additions & 11 deletions src/cli/strings.ml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
open! Core
open Eio.Std

let version = "2.2.1"

let plural i = if i = 1 then "" else "s"
let version = "2.3.0"

type counts = {
vue: int ref;
Expand All @@ -18,6 +16,7 @@ type common_options = {
targets: string list;
template_script: Vue.template_script;
slow_pug: bool;
show_debugging: bool;
}

type action =
Expand All @@ -34,7 +33,7 @@ type file_type =
type traversal = {
table: String.Set.t String.Table.t;
counts: counts;
dispatcher: Utils.Dispatcher.t;
dispatcher: Dispatcher.t;
slow_pug: bool;
template_script: Vue.template_script;
}
Expand Down Expand Up @@ -66,7 +65,7 @@ let reduce_collector env table count collector =
| None -> String.Set.add String.Set.empty realname
| Some set -> String.Set.add set realname ) )

let do_work ({ path; _ } as job) =
let process_job ({ path; _ } as job) =
let collector = Utils.Collector.create ~path in
(match job with
| { file_type = JS; eio_path; _ } ->
Expand Down Expand Up @@ -110,7 +109,7 @@ let rec traverse env ({ slow_pug; template_script; counts; _ } as traversal) dir
let job =
{ file_type; eio_path = Eio.Path.(env#fs / path); path; template_script; slow_pug }
in
let collector = Utils.Dispatcher.run_exn traversal.dispatcher ~f:(fun () -> do_work job) in
let collector = Dispatcher.run_exn traversal.dispatcher ~f:(fun () -> process_job job) in
let count =
match job.file_type with
| JS -> counts.js
Expand Down Expand Up @@ -165,6 +164,7 @@ let main env options = function
| Run ->
let overall_time = Utils.Timing.start () in
let outdir = options.outdir in
if List.is_empty options.targets then failwith "Please specify at least one directory";
(* Check current directory *)
let strings_dir_files =
let git_dir, strings_dir =
Expand All @@ -185,7 +185,7 @@ let main env options = function
let counts = { vue = ref 0; pug = ref 0; html = ref 0; js = ref 0; ts = ref 0 } in
Switch.run (fun sw ->
let dispatcher =
Utils.Dispatcher.create ~sw ~num_domains:Utils.Io.num_processors
Dispatcher.create ~sw ~num_domains:Utils.Io.num_processors
~domain_concurrency:Utils.Io.processor_async env#domain_mgr
in
options.targets
Expand All @@ -209,7 +209,7 @@ let main env options = function
let english =
String.Table.map table ~f:(fun set -> String.Set.to_array set |> String.concat_array ~sep:", ")
in
let f ext i = sprintf "%d %s file%s" i ext (plural i) in
let f ext i = sprintf "%d %s file%s" i ext (if i = 1 then "" else "s") in
let time = Int63.(time `Stop - Atomic.get Quickjs.init_time) in
Eio.Flow.copy_string
(sprintf
Expand Down Expand Up @@ -256,8 +256,10 @@ let () =
~doc:
"Use the official Pug parser. Much slower, especially on large files. Use this option if any \
translation seems to be missing from a Pug file, and report the bug if this option fixes it."
and show_debugging =
flag "--show-debugging" ~full_flag_required:() no_arg ~doc:"Use this option when reporting bugs."
in
{ outdir; targets; template_script = (if use_ts then TS else JS); slow_pug }
{ outdir; targets; template_script = (if use_ts then TS else JS); slow_pug; show_debugging }
in
let action =
let open Param in
Expand Down Expand Up @@ -289,8 +291,9 @@ let () =
Param.both common action
>>| (fun (common, action) () ->
let program env = main env common action in
Eio_main.run (fun env ->
(* TODO: Revert to Eio_main.run once Eio issue #559 is fixed *)
Eio_posix.run (fun env ->
try program env with
| exn -> handle_system_failure env#stderr exn ))
| exn when not common.show_debugging -> handle_system_failure env#stderr exn ))
|> basic ~summary:"Extract i18n strings - https://github.com/okTurtles/strings"
|> Command_unix.run ~version
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/angstrom_eio/dune → src/dispatcher/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name angstrom_eio)
(name dispatcher)
(libraries
angstrom
core
eio_main
)
(preprocess (pps
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SZXX

utils
angstrom_eio
angstrom-eio
flow_parser
)
(preprocess (pps
Expand Down
7 changes: 4 additions & 3 deletions src/quickjs/quickjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,19 @@ let init_contexts =
let p, w = Promise.create () in
let cell = Some p in
fun () ->
let num_js_workers = Utils.Io.num_js_workers in
if Atomic.compare_and_set initialized None cell
then (
let time = Utils.Timing.start () in
(fun () -> stub_init_contexts Utils.Io.num_js_workers) () |> Result.ok_or_failwith;
(fun () -> stub_init_contexts num_js_workers) () |> Result.ok_or_failwith;

let time = time `Stop in
Atomic.set init_time time;
Promise.resolve w (Pool.create Utils.Io.num_js_workers);
Promise.resolve w (Pool.create num_js_workers);
print_endline
(sprintf
!"✅ [%{Int63}ms] Initialized %d JS runtimes for TS and/or Pug processing\n"
time Utils.Io.num_js_workers ) );
time num_js_workers ) );
p

(* Re-indent from 0 if base indent is greater than 0 *)
Expand Down
6 changes: 1 addition & 5 deletions src/utils/collector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ let analyzed_possible_scripts collector =
let render_errors { file_errors; path; _ } =
match Queue.length file_errors with
| 0 -> None
| 1 ->
(* TODO: review/optimize *)
let buf = Buffer.create 256 in
bprintf buf "\n❌ 1 error in %s: %s" path (Queue.get file_errors 0);
Some (Buffer.contents buf)
| 1 -> Some (sprintf "\n❌ 1 error in %s: %s" path (Queue.get file_errors 0))
| len ->
let buf = Buffer.create 256 in
bprintf buf "\n❌ %d errors in %s:\n" len path;
Expand Down
2 changes: 0 additions & 2 deletions src/utils/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ let run_in_pool fn x =

let stat path = run_in_pool Core_unix.stat path

let read_flow flow = Eio.Buf_read.(parse_exn ~max_size:Int.max_value take_all flow)

let load_flow flow =
let open Eio in
(* Taken from [Eio.Path.load] *)
Expand Down
Loading

0 comments on commit 462c14a

Please sign in to comment.