This file is indexed.

/usr/lib/ocaml/oasis/OCamlbuildCommon.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
(******************************************************************************)
(* 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              *)
(******************************************************************************)


(** Functions common to OCamlbuild build and doc plugin
  *)


open OASISGettext
open BaseEnv
open BaseStandardVar
open OASISTypes


TYPE_CONV_PATH "OCamlbuildCommon"

type extra_args = string list with odn


let ocamlbuild_clean_ev = "ocamlbuild-clean"


let ocamlbuildflags =
  var_define
    ~short_desc:(fun () -> "OCamlbuild additional flags")
    "ocamlbuildflags"
    (fun () -> "")


(** Fix special arguments depending on environment *)
let fix_args args extra_argv =
  List.flatten
    [
      if (os_type ()) = "Win32" then
        [
          "-classic-display";
          "-no-log";
          "-no-links";
          "-install-lib-dir";
          (Filename.concat (standard_library ()) "ocamlbuild")
        ]
      else
        [];

      if not (bool_of_string (is_native ())) || (os_type ()) = "Win32" then
        [
          "-byte-plugin"
        ]
      else
        [];
      args;

      if bool_of_string (debug ()) then
        ["-tag"; "debug"]
      else
        [];

      if bool_of_string (tests ()) then
        ["-tag"; "tests"]
      else
        [];

      if bool_of_string (profile ()) then
        ["-tag"; "profile"]
      else
        [];

      OASISString.nsplit (ocamlbuildflags ()) ' ';

      Array.to_list extra_argv;
    ]


(** Run 'ocamlbuild -clean' if not already done *)
let run_clean extra_argv =
  let extra_cli =
    String.concat " " (Array.to_list extra_argv)
  in
    (* Run if never called with these args *)
    if not (BaseLog.exists ocamlbuild_clean_ev extra_cli) then
      begin
        OASISExec.run ~ctxt:!BaseContext.default
          (ocamlbuild ()) (fix_args ["-clean"] extra_argv);
        BaseLog.register ocamlbuild_clean_ev extra_cli;
        at_exit
          (fun () ->
             try
               BaseLog.unregister ocamlbuild_clean_ev extra_cli
             with _ ->
               ())
      end


(** Run ocamlbuild, unregister all clean events *)
let run_ocamlbuild args extra_argv =
  (* TODO: enforce that target in args must be UNIX encoded i.e. toto/index.html
   *)
  OASISExec.run ~ctxt:!BaseContext.default
    (ocamlbuild ()) (fix_args args extra_argv);
  (* Remove any clean event, we must run it again *)
  List.iter
    (fun (e, d) -> BaseLog.unregister e d)
    (BaseLog.filter [ocamlbuild_clean_ev])


(** Determine real build directory *)
let build_dir extra_argv =
  let rec search_args dir =
    function
      | "-build-dir" :: dir :: tl ->
          search_args dir tl
      | _ :: tl ->
          search_args dir tl
      | [] ->
          dir
  in
    search_args "_build" (fix_args [] extra_argv)


(* END EXPORT *)

open OASISValues

let fix_build_tools tool pkg =
  let fix_build_tools' sct bs =
    if not (List.mem tool bs.bs_build_tools) then
      {bs with bs_build_tools = tool :: bs.bs_build_tools}
    else
      bs
  in

  let sections =
    List.fold_left
      (fun acc sct ->
         let sct =
           match sct with
             | Executable (cs, bs, exec) ->
                 let bs = fix_build_tools' sct bs in
                   Executable (cs, bs, exec)

             | Library (cs, bs, lib) ->
                 let bs = fix_build_tools' sct bs in
                   Library (cs, bs, lib)

             | Object (cs, bs, obj) ->
                 let bs = fix_build_tools' sct bs in
                   Object (cs, bs, obj)

             | Flag _ | SrcRepo _ | Test _ | Doc _ as sct ->
                 sct
         in
           sct :: acc)
      []
      pkg.sections
  in
    {pkg with sections = List.rev sections}


module Tag =
struct
  (** [filename_concat fn1 fn2] Concat filename, using semantic of _tags
      [fn1] must be a real filename whereas fn2 can contains wildcards.
    *)
  let filename_concat fn1 fn2 =
    OASISUnixPath.concat (OASISUnixPath.reduce fn1) fn2
end

(** Check OCaml version constraint defined in _oasis. *)
let check_ocaml_version version pkg =
  match pkg.ocaml_version with
    | Some ocaml_version ->
        let min_ocaml_version = OASISVersion.version_of_string version in
        OASISVersion.comparator_ge min_ocaml_version ocaml_version
    | None ->
        false


let ocamlbuild_more_args =
  OASISFeatures.create "ocamlbuild_more_args"
    OASISFeatures.alpha
    (fun () ->
       s_ "Allow to pass arguments to ocamlbuild.")


let ocamlbuild_supports_ocamlfind = check_ocaml_version "3.12.1"
let ocamlbuild_supports_plugin_tags = check_ocaml_version "4.01"


type ocamlbuild_common =
  {
    plugin_tags: string option;
    extra_args: string list;
  } with odn


let ocamlbuild_common_generator pivot_data schm id =
  let new_field nm = OASISSchema.new_field schm id nm in
  let plugin_tags =
    new_field
      "PluginTags"
      ~default:None
      ~feature:ocamlbuild_more_args
      (opt string_not_empty)
      (fun () -> s_ "Gives the plugin tags to ocambuild through \
                     '-plugin-tags' (OCaml >= 4.01 only)")
      pivot_data (fun _ t -> t.plugin_tags)
  in
  let extra_args =
    new_field
      "ExtraArgs"
      ~default:[]
      ~feature:ocamlbuild_more_args
      command_line_options
      (fun () -> s_ "Gives extra arguments to ocamlbuild")
      pivot_data (fun _ t -> t.extra_args)
  in
    fun data ->
      {
        extra_args = extra_args data;
        plugin_tags = plugin_tags data;
      }


let extra_args_ocamlbuild_common ~ctxt pkg t =
  let extra_args =
    if t.plugin_tags <> None &&
       not (ocamlbuild_supports_plugin_tags pkg) then begin
      OASISMessage.error
        ~ctxt:ctxt
        (f_ "'XOCamlbuildPluginTags' in only available for OCaml >= 4.01. \
             Please restrict your requirements with 'OCamlVersion: >= 4.01'");
      t.extra_args
    end else begin
      match t.plugin_tags with
        | Some tags -> "-plugin-tags" :: ("'" ^ tags ^ "'") :: t.extra_args
        | None -> t.extra_args
    end
  in
  let extra_args =
    if ocamlbuild_supports_ocamlfind pkg then
      "-use-ocamlfind" :: extra_args
    else
      extra_args
  in
  extra_args