This file is indexed.

/usr/lib/ocaml/oasis/OCamlbuildDocPlugin.ml is in liboasis-ocaml-dev 0.4.5-1build3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
(******************************************************************************)
(* OASIS: architecture for building OCaml libraries and applications          *)
(*                                                                            *)
(* Copyright (C) 2011-2013, Sylvain Le Gall                                   *)
(* Copyright (C) 2008-2011, OCamlCore SARL                                    *)
(*                                                                            *)
(* This library is free software; you can redistribute it and/or modify it    *)
(* under the terms of the GNU Lesser General Public License as published by   *)
(* the Free Software Foundation; either version 2.1 of the License, or (at    *)
(* your option) any later version, with the OCaml static compilation          *)
(* exception.                                                                 *)
(*                                                                            *)
(* This library is distributed in the hope that it will be useful, but        *)
(* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *)
(* or FITNESS FOR A PARTICULAR PURPOSE. See the file COPYING for more         *)
(* details.                                                                   *)
(*                                                                            *)
(* You should have received a copy of the GNU Lesser General Public License   *)
(* along with this library; if not, write to the Free Software Foundation,    *)
(* Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA              *)
(******************************************************************************)


(* Create documentation using ocamlbuild .odocl files
   @author Sylvain Le Gall
 *)


open OASISTypes
open OASISGettext
open OASISMessage
open OCamlbuildCommon
open BaseStandardVar


TYPE_CONV_PATH "OCamlbuildDocPlugin"

type run_t =
  {
    extra_args: string list;
    run_path: unix_filename;
  } with odn


let doc_build run pkg (cs, doc) argv =
  let index_html =
    OASISUnixPath.make
      [
        run.run_path;
        cs.cs_name^".docdir";
        "index.html";
      ]
  in
  let tgt_dir =
    OASISHostPath.make
      [
        build_dir argv;
        OASISHostPath.of_unix run.run_path;
        cs.cs_name^".docdir";
      ]
  in
    run_ocamlbuild (index_html :: run.extra_args) argv;
    List.iter
      (fun glb ->
         BaseBuilt.register
           BaseBuilt.BDoc
           cs.cs_name
           [OASISFileUtil.glob ~ctxt:!BaseContext.default
              (Filename.concat tgt_dir glb)])
      ["*.html"; "*.css"]


let doc_clean run pkg (cs, doc) argv =
  run_clean argv;
  BaseBuilt.unregister BaseBuilt.BDoc cs.cs_name


(* END EXPORT *)


open OASISFileTemplate
open OASISPlugin
open OASISValues
open OASISUtils
open OASISPlugin
open OASISSchema
open OCamlbuildId


let plugin =
  `Doc, name, Some version


type t =
    {
      path:      unix_dirname;
      modules:   string list;
      libraries: findlib_full list;
      intro:     unix_filename option;
      flags:     string list;
      common:    ocamlbuild_common;
    }


let pivot_data = data_new_property plugin
let pivot_sub_data = data_new_property plugin


let self_id, all_id =
  Doc.create plugin


let new_field nm ?default vl hlp sync =
  new_field
    OASISDocument.schema
    all_id
    nm
    ?default
    vl
    (fun () -> s_ hlp)
    pivot_data sync


let path =
  new_field
    "Path"
    directory
    (ns_ "Top level directory for building ocamldoc documentation")
    (fun _ t -> t.path)


let modules =
  new_field
    "Modules"
    ~default:[]
    modules
    (ns_ "List of OCaml modules used to generate ocamldoc documentation")
    (fun _ t -> t.modules)


let libraries =
  new_field
    "Libraries"
    ~default:[]
    (comma_separated findlib_full)
    (ns_ "Findlib names of internal libraries used to generate the ocamldoc \
          documentation")
    (fun _ t -> t.libraries)


(* TODO: the following 2 options require to edit _tags after OCamlbuildDoc
 *)
(*
let intro =
  new_field
    ~default:None
    "Intro"
    (opt file)
    (ns_ "OCamldoc formatted file used to generate index.html of the ocamldoc \
          documentation")
    (fun _ t -> t.intro)


let flags =
  new_field
    ~default:[]
    "Flags"
    space_separated
    (ns_ "OCamldoc flags")
    (fun _ t -> t.flags)
 *)


(* TODO: use -t for title *)


let generator =
  let generator_common =
    (* Register fields. *)
    ocamlbuild_common_generator pivot_sub_data OASISDocument.schema all_id
  in
    fun data pkg ->
      let path = path data in

      let modules_from_libraries =
        (* Convert findlib name to internal library and compute
         * the module they shipped.
         *)
        let lib_of_findlib =
          let _, _, library_name_of_findlib_name =
            OASISFindlib.findlib_mapping pkg
          in
          let lib_of_name =
            List.fold_left
              (fun mp ->
                 function
                   | Library ({cs_name = name}, bs, lib) ->
                       MapString.add name (bs, lib) mp
                   | _ ->
                       mp)
              MapString.empty
              pkg.sections
          in
            fun fndlb_nm ->
              let nm =
                library_name_of_findlib_name fndlb_nm
              in
                MapString.find nm lib_of_name
        in

          (* Fetch modules from internal libraries *)
          List.flatten
            (List.map
               (fun fndlb_nm ->
                  let bs, lib =
                    lib_of_findlib fndlb_nm
                  in
                    (* Rebase modules in the doc path *)
                    List.map
                      (fun modul ->
                         OASISUnixPath.make_relative
                           path
                           (OASISUnixPath.concat bs.bs_path modul))
                      lib.lib_modules)

               (libraries data))
      in

      let modules_from_doc =
        (* Fetch modules defined directly *)
        modules data
      in

      let modules =
        modules_from_libraries @ modules_from_doc
      in
      {
        path = path;
        modules = modules;
        libraries = libraries data;
        intro = None;
        flags = [];
        common = generator_common data;
      }


let doit ctxt pkg (cs, doc) =
  let t = generator cs.cs_data pkg in

  let ctxt =
    (* Create .odocl file *)
    add_file
      (template_make
         (OASISHostPath.add_extension
            (Filename.concat t.path cs.cs_name)
            "odocl")
         comment_ocamlbuild
         []
         t.modules
         [])
      ctxt
  in

  let ctxt =
    (* Checks consistency of options *)
    (* TODO: merge with qstrt_completion *)
    List.fold_left
      (fun ctxt f -> f ctxt)
      ctxt
      [
        set_error
          (not (List.mem (ExternalTool "ocamldoc") doc.doc_build_tools))
          (Printf.sprintf
             (f_ "ocamldoc in field BuildTools of document %s is mandatory.")
             cs.cs_name);

        set_error
          (not (List.mem (ExternalTool "ocamlbuild") doc.doc_build_tools))
          (Printf.sprintf
             (f_ "ocamlbuild in field BuildTools of document %s is mandatory.")
             cs.cs_name);

        set_error
          (t.modules = [])
          (Printf.sprintf
             (f_ "No module defined for document %s.")
             cs.cs_name);
      ]
  in

  let run =
    {
      run_path = t.path;
      extra_args = extra_args_ocamlbuild_common ~ctxt:ctxt.ctxt pkg t.common;
    }
  in
  ctxt,
  {
    chng_moduls =
      [OCamlbuildData.ocamlbuildsys_ml];

    chng_main =
      ODNFunc.func_with_arg
        doc_build "OCamlbuildDocPlugin.doc_build"
        run odn_of_run_t;

    chng_clean =
      Some
        (ODNFunc.func_with_arg
           doc_clean "OCamlbuildDocPlugin.doc_clean"
           run odn_of_run_t);

    chng_distclean =
      None;
  }


let qstrt_completion pkg =
  List.fold_left
    (fun pkg tool -> fix_build_tools tool pkg)
    pkg
    [ExternalTool "ocamlbuild";
     ExternalTool "ocamldoc"]


let init () =
  OCamlbuildId.init ();
  Doc.register_act self_id doit;
  register_quickstart_completion all_id qstrt_completion