/
odig.mli
1422 lines (1034 loc) · 45.7 KB
/
odig.mli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(*---------------------------------------------------------------------------
Copyright (c) 2016 Daniel C. Bünzli. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
%%NAME%% %%VERSION%%
---------------------------------------------------------------------------*)
(** Mining OCaml package installs.
{b Warning.} [Odig] is a work in progress. Do not expect these
APIs to be stable.
{e %%VERSION%% — {{:%%PKG_HOMEPAGE%% }homepage}} *)
(** {1 Odig} *)
(** OCaml compilation objects.
{b Note.} All paths returned by functions of this module
are made absolute (using {{:https://github.com/dbuenzli/bos/issues/49}for
now}, a fake [realpath(2)]). *)
module Cobj : sig
(** {1:cobjs Compilation objects} *)
(** Compilation object digests. *)
module Digest : sig
(** {1 Digests} *)
include module type of Digest
val pp : Format.formatter -> t -> unit
(** [pp ppf d] prints the digest [d] as an hexadecimal string. *)
val pp_opt : Format.formatter -> t option -> unit
(** [pp_opt ppf od] prints the optional digest [od] either like
{!pp} or, for [None] as dashes. *)
module Set : Asetmap.Set.S with type elt = t
type set = Set.t
(** The type for digest sets. *)
module Map : Asetmap.Map.S_with_key_set with type key_set = Set.t
and type key = t
type 'a map = 'a Map.t
(** The type for digest maps. *)
end
type digest = Digest.t
(** The type for compilation object digests. *)
type dep = string * digest option
(** The type for compilation object dependencies. A module name
and an optional digest (often a [cmi] digest). *)
type mli
(** The type for [mli] files. *)
type cmi
(** The type for [cmi] files. *)
type cmti
(** The type for [cmti] files. *)
type ml
(** The type for [ml] files. *)
type cmo
(** The type for [cmo] files. *)
type cmt
(** The type for [cmt] files. *)
type cma
(** The type for [cma] files. *)
type cmx
(** The type for [cmx] files. *)
type cmxa
(** The type for [cmxa] files. *)
type cmxs
(** The type for [cmxs] files. *)
(** [mli] files. *)
module Mli : sig
(** {1 Mli} *)
type t = mli
(** The type for mli files. *)
val read : Fpath.t -> (mli, [`Msg of string]) result
(** [read f] reads an [mli] file from [f].
{b Warning.} Does only check the file exists, not that it is
syntactically correct. *)
val name : mli -> string
(** [name mli] is the name of the module interface. *)
val path : mli -> Fpath.t
(** [path mli] is the file path to the mli file. *)
end
(** [cmi] files. *)
module Cmi : sig
(** {1 Cmi} *)
type t = cmi
(** The type for cmi files. *)
val read : Fpath.t -> (cmi, [`Msg of string]) result
(** [read f] reads a [cmi] file from [f]. *)
val name : cmi -> string
(** [name cmi] is the name of the module interface. *)
val digest : cmi -> digest
(** [digest cmi] is the digest of the module interface. *)
val deps : cmi -> dep list
(** [deps cmi] is the list of imported module interfaces names with their
digest, if known. *)
val path : cmi -> Fpath.t
(** [path cmi] is the file path to the [cmi] file. *)
(** {1 Derived information} *)
val to_cmi_dep : cmi -> dep
(** [to_cmi_dep cmi] is [cmi] as a dependency. *)
end
(** [cmti] files. *)
module Cmti : sig
(** {1 Cmti} *)
type t = cmti
(** The type for [cmti] files. *)
val read : Fpath.t -> (cmti, [`Msg of string]) result
(** [read f] reads a [cmti] file from [f]. *)
val name : cmti -> string
(** [name cmti] is the name of the module interface. *)
val digest : cmti -> digest
(** [digest cmti] is the digest of the module interface. *)
val deps : cmti -> dep list
(** [deps cmti] is the list of imported module interfaces with their
digest, if known. *)
val path : cmti -> Fpath.t
(** [path cmti] is the file path to the [cmti] file. *)
(** {1 Derived information} *)
val to_cmi_dep : cmti -> dep
(** [to_cmi_dep cmti] is [cmti] as a dependency. *)
end
(** [ml] files. *)
module Ml : sig
(** {1 Ml} *)
type t = ml
(** The type for ml files. *)
val read : Fpath.t -> (ml, [`Msg of string]) result
(** [read f] reads an [ml] file from [f].
{b Warning.} Does only check the file exists, not that it is
syntactically correct. *)
val name : ml -> string
(** [name ml] is the name of the module interface. *)
val path : ml -> Fpath.t
(** [path ml] is the file path to the ml file. *)
end
(** [cmo] files. *)
module Cmo : sig
(** {1 Cmo} *)
type t = cmo
(** The type for [cmo] files. *)
val read : Fpath.t -> (cmo, [`Msg of string]) result
(** [read f] reads a [cmo] file from [f]. *)
val name : cmo -> string
(** [name cmo] is the name of the module implementation. *)
val cmi_digest : cmo -> digest
(** [cmi_digest cmo] is the digest of the module interface of the
implementation. *)
val cmi_deps : cmo -> dep list
(** [cmi_deps cmo] is the list of imported module interfaces names
with their digest, if known. *)
val cma : cmo -> cma option
(** [cma cmo] is an enclosing [cma] file (if any). *)
val path : cmo -> Fpath.t
(** [path cmo] is the file path to the [cmo] file. Note that this
is a [cma] file if [cma cmo] is [Some _]. *)
(** {1 Derived information} *)
val to_cmi_dep : cmo -> dep
(** [to_cmi_dep cmo] is [cmo] as a [cmi] dependency. *)
end
(** [cmt] files. *)
module Cmt : sig
(** {1 Cmt} *)
type t = cmt
(** The type for [cmt] files. *)
val read : Fpath.t -> (cmt, [`Msg of string]) result
(** [read f] reads a [cmt] file from [f]. *)
val name : cmt -> string
(** [name cmt] is the name of the module interface. *)
val cmi_digest : cmt -> digest
(** [cmi_digest cmt] is the digest of the module interface of the
implementation. *)
val cmi_deps : cmt -> dep list
(** [cmi_deps cmt] is the list of imported module interfaces names
with their digest, if known. *)
val path : cmt -> Fpath.t
(** [path cm] is the file path to the [cmt] file. *)
end
(** [cma] files. *)
module Cma : sig
(** {1 Cma} *)
type t = cma
(** The type for cma files. *)
val read : Fpath.t -> (cma, [`Msg of string]) result
(** [read f] reads a [cma] file from [f]. *)
val name : cma -> string
(** [name cma] is [cma]'s basename. *)
val cmos : cma -> cmo list
(** [cmos cma] are the [cmo]s contained in the [cma]. *)
val custom : cma -> bool
(** [custom cma] is [true] if it requires custom mode linking. *)
val custom_cobjs : cma -> string list
(** [cma_custom_cobjs] are C objects files needed for custom mode
linking. *)
val custom_copts : cma -> string list
(** [cma_custom_copts] are C link options for custom mode linking. *)
val dllibs : cma -> string list
(** [cma_dllibs] are dynamically loaded C libraries for ocamlrun
dynamic linking. *)
val path : cma -> Fpath.t
(** [path cma] is the file path to the [cma] file. *)
(** {1 Derived information}
FIXME most of this can be removed. *)
val names : ?init:Digest.t Astring.String.map -> cma ->
Digest.t Astring.String.map
(** [names ~init cma] adds to [init] (defaults to
{!String.Map.empty}) the module names defined by [cma] mapped
to their [cmi] digests. If a name already exists in [init] it
is overriden. *)
val cmi_digests : ?init:string Digest.map -> cma -> string Digest.map
(** [cmi_digests ~init cma] adds to [init] (defaults to
{!Digest.Map.empty}) the [cmi] digests of the modules defined
by [cma] mapped to their module name. If a digest already
exists in [init] it is overriden. *)
val to_cmi_deps : ?init:dep list -> cma -> dep list
(** [to_cmi_deps ~init cma] adds to [init] (default to [[]])
the module names and [cmi] digests of the modules defined
by [cma]. *)
val cmi_deps :
?conflict:(string -> keep:Digest.t -> Digest.t -> unit) ->
cma -> dep list
(** [cmi_deps ~conflict cma] is the list of cmi imported by the [cmo]s
in the library. The result excludes self-dependencies
that is the set {!cmi_digest} of digests that are implemented
by the [cma] itself.
[conflict] is called if the module interface of a dependency
sports two different digests in the archive. The default
function logs a warning. *)
end
(** [cmx] files. *)
module Cmx : sig
(** {1 Cmx} *)
type t = cmx
(** The type for [cmx] files. *)
val read : Fpath.t -> (cmx, [`Msg of string]) result
(** [read f] reads a [cmx] file from [f]. *)
val name : cmx -> string
(** [name cmx] is the name of the module implementation. *)
val digest : cmx -> digest
(** [digest cmx] is the digest of the implementation. *)
val cmi_digest : cmx -> digest
(** [cmi_digest cmx] is the digest of the module interface of the
implementation. *)
val cmi_deps : cmx -> dep list
(** [cmi_deps cmx] is the list of imported module interfaces names
with their digest, if known. *)
val cmx_deps : cmx -> dep list
(** [cmx_deps cmx] is the list of imported module implementations names
with their digest, if known. *)
val cmxa : cmx -> cmxa option
(** [cmxa cmx] is an enclosing [cmxa] file (if any). *)
val path : cmx -> Fpath.t
(** [path cmx] is the file path to the [cmx] file. Note that this
is a [cmxa] file if [cmxa cmx] is [Some _]. *)
(** {1 Derived information} *)
val to_cmi_dep : cmx -> dep
(** [to_cmi_dep cmx] is [cmx] as a [cmi] dependency. *)
end
(** [cmxa] files. *)
module Cmxa : sig
(** {1 Cmxa} *)
type t = cmxa
(** The type for [cmxa] files. *)
val read : Fpath.t -> (t, [`Msg of string]) result
(** [read f] reads a [cmxa] file from [f]. *)
val name : cmxa -> string
(** [name cmxa] is [cmxa]'s basename. *)
val cmxs : cmxa -> cmx list
(** [cmxs cmxa] are the [cmx]s contained in the [cmxa]. *)
val cobjs : cmxa -> string list
(** [cobjs] are C objects needed files needed for linking. *)
val copts : cmxa -> string list
(** [copts] are options for the C linker. *)
val path : cmxa -> Fpath.t
(** [path cmxa] is the file path to the [cmxa] file. *)
(** {1 Derived information} *)
val names : ?init:Digest.t Astring.String.map -> cmxa ->
Digest.t Astring.String.map
(** [names ~init cmxa] adds to [init] (defaults to
{!String.Map.empty}) the module names defined by [cmxa] mapped
to their [cmi] digests. If a name already exists in [init] it
is overriden. *)
val cmi_digests : ?init:string Digest.map -> cmxa -> string Digest.map
(** [cmi_digests ~init cmxa] adds to [init] (defaults to
{!Digest.Map.empty}) the [cmi] digests of the modules defined
by [cmxa] mapped to their module name. If a digest already
exists in [init] it is overriden. *)
val to_cmi_deps : ?init:dep list -> cmxa -> dep list
(** [to_cmi_deps ~init cmxa] adds to [init] (default to [[]])
the module names and [cmi] digests of the modules defined
by [cmxa]. *)
val cmi_deps :
?conflict:(string -> keep:Digest.t -> Digest.t -> unit) ->
cmxa -> dep list
(** [cmi_deps ~conflict cmxa] is the list of cmi imported by the [cmx]s
in the library. The result excludes self-dependencies
that is the set {!cmi_digest} of digests that are implemented
by the [cmxa] itself.
[conflict] is called if the module interface of a dependency
sports two different digests in the archive. The default
function logs a warning. *)
end
(** [cmxs] files. *)
module Cmxs : sig
(** {1 Cmxs} *)
type t = cmxs
(** The type for [cmxs] files. *)
val read : Fpath.t -> (t, [`Msg of string]) result
(** [read f] reads a [cmxs] file from [f].
{b Warning.} Only checks that the file exists. *)
val name : cmxs -> string
(** [name cmxs] is [cmxs]'s basename. *)
val path : cmxs -> Fpath.t
(** [path cmxs] is the file path to the [cmxs] file. *)
end
(** {1 Compilation object sets} *)
type set
(** The type for sets of compilation objects. *)
val empty_set : set
(** [empty_set] is an empty set of compilation objects. *)
val mlis : set -> mli list
(** [mlis s] is the list of [mli]s contained in [s]. *)
val cmis : set -> cmi list
(** [cmis s] is the list of [cmi]s contained in [s]. *)
val cmtis : set -> cmti list
(** [cmtis s] is the list of [cmti]s contained in [s]. *)
val mls : set -> ml list
(** [mls s] is the list of [ml]s contained in [s]. *)
val cmos : ?files:bool -> set -> cmo list
(** [cmos ~files s] is the list of [cmo]s contained in [s]. If
[files] is [true] (defaults to [false]), only the [cmo] files
are listed and [cmo]s that are part of [cma] files are omitted. *)
val cmts : set -> cmt list
(** [cmts s] is the list of [cmt]s contained in [s]. *)
val cmas : set -> cma list
(** [cmas s] is the list of [cma]s contained in [s]. *)
val cmxs : ?files:bool -> set -> cmx list
(** [cmxs ~files s] is the list of [cmx]s contained in [s]. If
[files] is [true] (defaults to [false]), only the [cmx] files
are listed and [cmx]s that are part of [cmxa] files are omitted. *)
val cmxas : set -> cmxa list
(** [cmxa s] is the list of [cmxa]s contained in [s]. *)
val cmxss : set -> cmxs list
(** [cmxss s] is the list of [cmxs]s contained in [s]. *)
val set_of_dir :
?err:(Fpath.t -> ('a, [`Msg of string]) result -> unit) ->
Fpath.t -> set
(** [set_of_dir ~err d] is the set of compilation objects that
are present in the file hierarchy rooted at [d].
This is a best-effort function, it will call [err] on errors and
continue; at worst you'll get an {!empty_set}. [err]'s default
simply logs the error at level {!Logs.Error}. *)
(** {1:indexes Compilation object indexes} *)
type 'a index
(** See {!Index.t}. *)
(** Compilation object indexes *)
module Index : sig
(** {1 Compilation objects indexes} *)
type 'a t = 'a index
(** The type for compilation objects indexes whose query results
are tagged with ['a]. *)
val empty : 'a index
(** [empty] is an empty index. *)
val of_set : ?init:'a index -> 'a -> set -> 'a index
(** [of_set ~init t s] is an index from [s] whose objects
are tagged with [t]. [init] is the index to add to (defaults to
{!empty}.) *)
(** {1 Queries} *)
type query = [`Digest of digest | `Name of string ]
(** The type for queries. Either by digest or by (capitalized)
module name. *)
val query_of_dep : dep -> query
(** [query_of_dep dep] is the most precise query for [dep]. *)
val query :
'a t -> query ->
('a * cmi) list *
('a * cmti) list *
('a * cmo) list *
('a * cmx) list *
('a * cmt) list
(** [query i q] is [(cmis, cmtis, cmos, cmxs, cmt)] the compilations
objects matching query [q] in [i]:
{ul
{- [cmis] are those whose {!Cobj.Cmi.name} or {!Cobj.Cmi.digest} match.}
{- [cmtis] are those whose {!Cobj.Cmti.name} or
{!Cobj.Cmti.digest} match.}
{- [cmos] are those whose {!Cobj.Cmo.name} or
{!Cobj.Cmo.cmi_digest} match.}
{- [cmxs] are those whose {!Cobj.Cmx.name} or
{!Cobj.Cmx.digest} or {!Cobj.Cmx.cmi_digest} match.}
{- [cmts] are those whose {!Cobj.Cmt.name} or
{!Cobj.Cmt.cmi_digest} match.}} *)
val cmis_for_interface : 'a index -> query -> ('a * cmi) list
(** [cmi_for_interface i q] is a list of [cmi]s whose module interface
matches [q]. *)
val cmtis_for_interface : 'a index -> query -> ('a * cmti) list
(** [cmti_for_interface i q] is a list of [cmti]s whose module
interface matches [q]. *)
val cmos_for_interface : 'a index -> query -> ('a * cmo) list
(** [cmo_for_interface i d] is a list of [cmo] whose module
interface matches [q]. *)
val cmxs_for_interface : 'a index -> query -> ('a * cmx) list
(** [cmxs_for_interface i cmx] is a list of [cmx] objects whose
module interface matches [q]. *)
val cmts_for_interface : 'a index -> query -> ('a * cmt) list
(** [cmxs_for_interface i cmx] is a list of [cmx] objects whose
module interface matches [q]. *)
end
(** {1:depresolve Dependency resolution} *)
type ('a, 'o) dep_resolution =
[ `None | `Some of ('a * 'o) | `Amb of ('a * 'o) list ]
(** The type for dependency resolutions. Either no, some or
an ambiguous resolution. *)
type ('a, 'o) dep_resolver = dep -> ('a * 'o) list -> ('a, 'o) dep_resolution
(** The type for dependency resolvers. Determines a resolution from
a dependency and list of matching candidates. *)
val cmi_for_interface :
resolve:('a, cmi) dep_resolver -> 'a index -> dep ->
('a, cmi) dep_resolution
(** [cmi_for_interface ~resolve i dep] is the resolution [resolve] of
[cmi]s matching module interface [dep] in [i]. *)
val cmo_for_interface :
resolve:('a, cmo) dep_resolver -> 'a index -> dep ->
('a, cmo) dep_resolution
(** [cmo_for_interface ~resolve i dep] is the resolution [resolve] of
[cmo]s matching module interface [dep] in [i]. *)
val cmx_for_interface :
resolve:('a, cmx) dep_resolver -> 'a index -> dep ->
('a, cmx) dep_resolution
(** [cmx_for_interface ~resolve i dep] is the resolution [resolve] of
[cmx]s matching module interface [dep] in [i]. *)
(** {2:recdepresolve Recursive resolution} *)
type ('a, 'o) dep_src = ('a * 'o) list
(** The type for dependency sources. Tracks an object (head) to its source
(tail). This is only used to allow good end-user feedback. *)
type ('a, 'o) rec_dep_resolution =
[ `Resolved of ('a * 'o) * ('a, 'o) dep_src
| `Unresolved of dep * [ `None | `Amb of ('a * 'o) list ] * ('a, 'o) dep_src
| `Conflict of string * ('a, 'o) dep_src list Digest.map ]
(** The type for recursive dependency resolution:
{ul
{- [`Resolved (obj, src)], a resolved object [obj]. [src] is
one of the sources for [obj].}
{- [`Unresolved (dep, reason, src)], unresolved dependency [dep]
for reason [reason]; either not found or ambiguous. [src]
is one of the sources of [dep].}
{- [`Conflict (n, dm)], conflicting resolution for module name
[n]. [dm] is the set of conflicting digests for [n] mapped to one
of their source.}} *)
val pp_rec_dep_resolution : ('a * 'o) Fmt.t ->
('a, 'o) rec_dep_resolution Fmt.t
(** [pp_rec_dep_resolution pp_obj] is an unspecified formatter
for recursive dependency resolutions using [pp_obj] to format
objects. *)
val rec_cmis_for_interfaces :
resolve:('a, cmi) dep_resolver -> 'a index ->
(dep * ('a, cmi) dep_src) list ->
('a, cmi) rec_dep_resolution Astring.String.map
(** See, {e mutatis mutandis}, {!rec_cmos_for_interfaces}. *)
val rec_cmos_for_interfaces :
resolve:('a, cmo) dep_resolver -> 'a index ->
(dep * ('a, cmo) dep_src) list ->
('a, cmo) rec_dep_resolution Astring.String.map
(** [rec_cmos_for_interfaces ~resolve i deps] maps module names to
the result of recursively resolving module interface
dependencies [deps] (tupled with a dependency source) to [cmo]s
in [i] using [resolve]. More precisely:
{ul
{- First [deps] are resolved to [cmo]s. Then for each of these
[cmo]s, their {{!Cmo.cmi_deps}interface dependencies} are resolved
to [cmo]s and recursively.}
{- Conflicts occur if two module interface dependencies occur with the
same module name but different interface digests. This means
that the resolution request is inconsistent and cannot be used
for linking.}
{- Unresolvedness may be due to: missing objects in [index], existing
objects excluded by [resolve], ambiguous objects not decided by
[resolve] or because a module interface has no corresponding
implementation – the OCaml compilation model allows this.}} *)
val fold_rec_dep_resolutions :
deps:('o -> dep list) ->
(string -> ('a, 'o) rec_dep_resolution -> 'b -> 'b) ->
('a, 'o) rec_dep_resolution Astring.String.map -> 'b -> 'b
(** [fold_rec_dep_resolutions ~deps f res acc] folds [f] with [acc]
over the partial evaluation order of [res] using [deps] on resolved
objects. Conflicts and unresolved dependencies are also folded over.
@raise Invalid_argument if [deps] returns, on a resolved object,
a name that is not in the domain of [res]. *)
end
(** Odig configuration. *)
module Conf : sig
(** {1 Configuration} *)
type t
(** The type for odig configuration. *)
val default_file : Fpath.t
(** [default_file] is the default configuration file. *)
val v :
?trust_cache:bool -> cachedir:Fpath.t -> libdir:Fpath.t ->
docdir:Fpath.t -> docdir_href:string option -> unit -> t
(** [v ~trust_cache ~cachedir ~libdir ~docdir ~docdir_href ()] is a
configuration using [cachedir] as the odig cache directory,
[libdir] for looking up package compilation objects, [docdir]
for looking up package documentation and [docdir_href] for
specifying the location of [docdir] in generated html. If
[trust_cache] is [true] (defaults to [false]) indicates the data
of [cachedir] should be trusted regardless of whether [libdir]
and [docdir] may have changed. *)
val with_conf : ?trust_cache:bool -> ?docdir_href:string option -> t -> t
(** [of_conf ~trust_cache ~docdir_href c] is [c] updated with
arguments specified, unspecfied ones are left untouched. *)
val of_file : ?trust_cache:bool -> Fpath.t -> (t, [`Msg of string]) result
(** [of_file f] reads a configuration from configuration file [f].
See {!v}. *)
val of_opam_switch :
?trust_cache:bool -> ?switch:string -> ?docdir_href:string ->
unit -> (t, [`Msg of string]) result
(** [of_opam_switch ~switch ()] is a configuration for the opam switch
[switch] (defaults to the current switch). See {!v}. *)
val libdir : t -> Fpath.t
(** [libdir c] is [c]'s package library directory. *)
val docdir : t -> Fpath.t
(** [docdir c] is [c]'s package documentation directory. *)
val docdir_href : t -> string option
(** [docdir_href c] is, for HTML generation, the base URI under
which {!docdir} is accessible expressed (if) relative to the
root package list. If unspecified links to {!docdir} are made
by relativizing {!docdir} w.r.t. to the location of the
generated HTML file. *)
(** {1 Cache} *)
val cachedir : t -> Fpath.t
(** [cachedir c] is [c]'s odig cache directory. *)
val trust_cache : t -> bool
(** [trust_cache c] indicates if [c] is trusting [odig]'s cache. *)
val clear_cache : t -> (unit, [`Msg of string]) result
(** [clear_cache c] deletes [c]'s cache directory. *)
(** {1 Package cache} *)
val pkg_cachedir : t -> Fpath.t
(** [pkg_cachedir c] is [c]'s cache directory for packages it is
located inside {!cachedir}. *)
val cached_pkgs_names : t -> (Astring.String.set, [`Msg of string]) result
(** [cached_pkgs_names c] is the set of names of the packages that
are cached in [c]. Note that these packages may not correspond
or be up-to-date with packages {{!Pkg.list}found} in the
configuration. *)
end
(** Packages.
Information about how packages are recognized and their data looked up
is kept in [odig help packaging].
{b TODO.} Add a note about freshness and concurrent access. *)
module Pkg : sig
(** {1 Package names} *)
type name = string
(** The type for package names. *)
val is_name : string -> bool
(** [is_name n] is [true] iff [n] is a valid package name. [n]
must not be empty and be a valid {{!Fpath.is_segment}path segment}. *)
val name_of_string : string -> (name, [`Msg of string]) result
(** [name_of_string s] is [Ok s] if [is_name s] is [true] and
an error message otherwise *)
val dir_is_package : Fpath.t -> name option
(** [dir_is_package dir] is [Some name] if a package named [name]
is detected in directory [dir].
{b Note} At the moment function will not detect a package name
if [dir] ends with a relative segment. *)
(** {1 Packages and lookup} *)
type t
(** The type for packages. *)
type set
(** The type for package sets. *)
val set : Conf.t -> (set, [`Msg of string]) result
(** [set c] is the set of all packages in configuration [c].
{b FIXME.} Currently results are memoized, which may not
be suitable for long running programs. *)
val conf_cobj_index :
Conf.t -> ([`Pkg of t] Cobj.Index.t, [`Msg of string]) result
(** [conf_cobj_cobjs c] is an index for all compilation objects in present in
packages of configuration [c]. Query results are tagged with
the package they belong to.
{b FIXME.} Currently results are memoized, which may not
be suitable for long running programs. Also this should be
simpler to access from a given package. *)
val lookup : Conf.t -> name -> (t, [`Msg of string]) result
(** [lookup c n] is the package named [n] in [c]. An error
is returned if [n] doesn't exist in [c] or if [n] is
not a {{!is_name}package name}. *)
val find : Conf.t -> name -> t option
(** [find c n] tries to find a package named [n] in [c].
[None] is returned if [n] doesn't exist in [c] or if [n]
is not a {{!is_name}package name}. *)
val find_set : Conf.t -> Astring.String.set -> set * Astring.String.set
(** [find_set c ns] is [(pkgs, not_found)] where [pkgs] are
the elements of [ns] which could be matched to a package in
configuration [c] and [not_found] are those that could not
be found or are not {{!is_name}package names}. *)
(** {1 Basic properties} *)
val field : err:'a -> (t -> ('a, [`Msg of string]) result) -> t -> 'a
(** [field ~err field f] is [v] if [field p = Ok v] and [err] otherwise. *)
val name : t -> name
(** [name p] is [p]'s name. *)
val libdir : t -> Fpath.t
(** [libdir p] is [p]'s library directory (has the compilation objects). *)
val docdir : t -> Fpath.t
(** [docdir p] is [p]'s documentation directory. *)
val cobjs : t -> Cobj.set
(** [cobjs p] are [p]'s compilation objects. *)
val conf : t -> Conf.t
(** [conf p] is the configuration in which [p] was found. *)
(** {1 Package metadata (opam file)} *)
val opam_file : t -> Fpath.t
(** [opam_file p] is [p]'s expected opam file path. *)
val opam_fields :
t -> (string list Astring.String.map, [`Msg of string]) result
(** [opam_fields p] is the package's opam fields. This is
{!String.Set.empty} [opam_file p] does not exist. *)
val license_tags : t -> (string list, [`Msg of string]) result
(** [license_tags p] is [p]'s [license:] field. *)
val version : t -> (string option, [`Msg of string]) result
(** [version p] is [p]'s [version:] field. *)
val homepage : t -> (string list, [`Msg of string]) result
(** [version p] is [p]'s [homepage:] field. *)
val online_doc : t -> (string list, [`Msg of string]) result
(** [online_doc p] is [p]'s [doc:] field. *)
val issues : t -> (string list, [`Msg of string]) result
(** [issues p] is [p]'s [bug-report:] field. *)
val tags : t -> (string list, [`Msg of string]) result
(** [tags p] is [p]'s [tags:] field. *)
val maintainers : t -> (string list, [`Msg of string]) result
(** [maintainers p] is [p]'s [maintainer:] field. *)
val authors : t -> (string list, [`Msg of string]) result
(** [authors p] is [p]'s [authors:] field. *)
val repo : t -> (string list, [`Msg of string]) result
(** [repo p] is [p]'s [dev-repo:] field. *)
val deps : ?opts:bool -> t -> (Astring.String.set, [`Msg of string]) result
(** [deps p] are [p]'s opam dependencies if [opt] is [true]
(default) includes optional dependencies. *)
val depopts : t -> (Astring.String.set, [`Msg of string]) result
(** [deps p] are [p]'s opam optional dependencies. *)
(** {1 Standard distribution documentation}
See {!Odoc} and {!Ocamldoc} for generated documentation. *)
val readmes : t -> (Fpath.t list, [`Msg of string]) result
(** [readmes p] are the readme files of [p]. *)
val change_logs : t -> (Fpath.t list, [`Msg of string]) result
(** [change_logs p] are the change log files of [p]. *)
val licenses : t -> (Fpath.t list, [`Msg of string]) result
(** [licences p] are the license files of [p]. *)
(** {1 Predicates} *)
val equal : t -> t -> bool
(** [equal p p'] is [true] if [p] and [p'] have the same name. *)
val compare : t -> t -> int
(** [compare p p'] is a total order on [p] and [p']'s names. *)
(** {1 Package sets and maps} *)
(** Package sets. *)
module Set : Asetmap.Set.S with type elt = t and type t = set
(** Package maps. *)
module Map : Asetmap.Map.S_with_key_set with type key = t
and type key_set = Set.t
(** {1 Classifying} *)
val classify :
?cmp:('a -> 'a -> int) -> classes:(t -> 'a list) -> t list ->
('a * Set.t) list
(** {1 Cache} *)
val cachedir : t -> Fpath.t
(** [cachedir p] is [p]'s cache directory, located somewhere in the
configuration's {!Conf.cachedir}. *)
type cache_status = [ `New | `Stale | `Fresh ]
(** The type for package status.
{ul
{- [`New] indicates that no cached information could be found
for the package.}
{- [`Fresh] indicates that cached information corresponds to the
package install state. {b Warning.} Freshness only refers to the
root information handled by this module. For example a
package may be fresh but it's API documentation may be
stale.}
{- [`Stale] indicates that cached information does not
correspond to the package install's state}} *)
val cache_status : t -> (cache_status, [`Msg of string]) result
(** [cache_status p] is [p]'s cache status. *)
val refresh_cache : t -> (unit, [`Msg of string]) result
(** [refresh_cache p] ensures [p]'s cache status becomes
[`Fresh]. {b Note.} Clients usually don't need to call this
as it is handled transparently by the API. *)
val clear_cache : t -> (unit, [`Msg of string]) result
(** [clear_cache p] deletes [p]'s {!cachedir}. Ensures [p]'s
cache status becomes [`New]. *)
end
(** {1:toplevel Toplevel helpers}
{b WARNING.} Proof of concepts do not start using this in your
scripts. For now only available in the bytecode toplevel.
To use the toplevel helpers simply bring the [Odig] module
in your scope: type or add the following line to your
[~/.ocamlinit] file.
{[#use "odig.top"]}
{2:loadsem Load semantics and effects}
Take into account the following points:
{ul
{- Loading an object means: add its containing directory to the
included directories, load the object and (if not prevented)
its dependencies.}
{- If an object is available both as a standalone file and in a library
archive, [Odig] favours loading the library archive.}
{- When a library [lib] is loaded, if there is a file called
[lib_top_init.ml] at the same location that file is loaded aswell,
This can be prevented by using the [~init] argument of
load functions.}
{- Library names ending with [_top] are currently prevented from loading.}
{- Dependency searches are currently unrestricted. This semantics will
change in the future, notably to ensure reproducible results regardless
of the package install state.}} *)
(** {2:localsearch Local search}
Some functions take a [~dir] argument that specifies a directory
where objects can be looked up in addition to packages. This
directoy defaults to [_build] or the value of the environment
value [ODIG_TOP_LOAD_DIR]. These load functions always first look up
for objects locally and then in packages. *)
(** {2:loaders Loaders} *)
val load :
?force:bool -> ?deps:bool -> ?init:bool -> ?dir:Fpath.t -> string -> unit
(** [load ~force ~deps ~init ~dir "Mod"] loads and setups include directories
for the module [Mod] found in [dir] or in any package.
{ul
{- If [init] is [true] (default) toplevel library initialisation files
are loaded.}
{- If [deps] is [true] (default) objects that are needed by the
module are also loaded.}
{- If [force] is [true] (defaults to [false]) reloads any loaded
object that needs to be loaded.}}
{b Warning.} Do not use this function in scripts, its outcome
depends on the package install state. *)
val load_libs :
?force:bool -> ?deps:bool -> ?init:bool -> ?dir:Fpath.t -> unit -> unit
(** [load_libs ~force ~deps ~init ~dir ()] loads and setups include
directories for libraries found in [dir].
{ul
{- If [init] is [true] (default) toplevel library initialisation files
are loaded.}
{- If [deps] is [true] (default) objects that are needed by the
libraries are also loaded.}
{- If [force] is [true] (defaults to [false]) reloads any loaded
object that needs to be loaded.}} *)
val load_pkg :
?force:bool -> ?deps:bool -> ?init:bool -> string -> unit