这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/ocaml-index/bin/ocaml_index.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ let rewrite_root = ref false
let store_shapes = ref false
let do_not_use_cmt_loadpath = ref false

type command = Aggregate | Dump | Stats | Gather_shapes
type command = Aggregate | Dump | Dump_file_stats | Stats | Gather_shapes

let parse_command = function
| "aggregate" -> Some Aggregate
| "dump" -> Some Dump
| "dump-file-stats" -> Some Dump_file_stats
| "stats" -> Some Stats
| "gather-shapes" -> Some Gather_shapes
| _ -> None
Expand Down Expand Up @@ -90,6 +91,19 @@ let () =
List.iter
(fun file -> Index_format.(read_exn ~file |> pp Format.std_formatter))
(List.rev !input_files_rev)
| Some Dump_file_stats ->
List.iter
(fun file ->
let open Merlin_index_format.Index_format in
let index = read_exn ~file in
Printf.printf "File stats for index %S:\n" file;
Stats.iter
(fun file { mtime; size; source_digest } ->
Printf.printf " %S: { mtime=%f; size=%d; source_digest=%S }\n" file
mtime size
(Option.value source_digest ~default:"none"))
index.stats)
(List.rev !input_files_rev)
| Some Gather_shapes ->
Index.gather_shapes ~output_file:!output_file (List.rev !input_files_rev)
| Some Stats ->
Expand Down
25 changes: 25 additions & 0 deletions src/ocaml-index/tests/tests-dirs/dump-file-stats.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Test using the dump-file-stats subcommand

mtime will not be consistent between tests, so don't include it
$ normalize () {
> cat | sed -E "s/mtime=[0-9\.]+/mtime=<mtime>/g"
> }

Create a small project
$ mkdir foo
$ cat > foo/a.ml << EOF
> let hello = "hello"
> EOF
$ cat > foo/b.ml << EOF
> let world = "world"
> EOF

Compile the project and create an index file
$ $OCAMLC -c -bin-annot -bin-annot-occurrences foo/a.ml foo/b.ml
$ ocaml-index aggregate foo/a.cmt foo/b.cmt -o foo.merlin-index

Dump the file stats from the index
$ ocaml-index dump-file-stats foo.merlin-index | normalize
File stats for index "foo.merlin-index":
"foo/a.ml": { mtime=<mtime>; size=20; source_digest="\147<\155xp\000:M2\170\163\134K`\235\226" }
"foo/b.ml": { mtime=<mtime>; size=20; source_digest="erv\218\000\233\177\190e\189\199\026q\156\195#" }
Loading