Skip to content

Commit b30b31f

Browse files
authored
Merge pull request #160 from whitequark/no-toolchain-for-plugin
Do not pass the -toolchain option when building a plugin
2 parents 11b04c9 + e0a90f2 commit b30b31f

File tree

3 files changed

+59
-29
lines changed

3 files changed

+59
-29
lines changed

src/options.ml

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let nostdlib = ref false
3939
let use_menhir = ref false
4040
let catch_errors = ref true
4141
let use_ocamlfind = ref false
42+
let plugin_use_ocamlfind = ref false
4243
let toolchain = ref ""
4344

4445
(* Currently only ocamlfind and menhir is defined as no-core tool,
@@ -85,7 +86,9 @@ let () =
8586
["ocamlc"; "ocamlopt"; "ocamldep"; "ocamldoc";
8687
"ocamlyacc"; "menhir"; "ocamllex"; "ocamlmklib"; "ocamlmktop"; "ocamlfind"]
8788
let ocamlc = ref (V"OCAMLC")
89+
let plugin_ocamlc = ref (V"OCAMLC")
8890
let ocamlopt = ref (V"OCAMLOPT")
91+
let plugin_ocamlopt = ref (V"OCAMLOPT")
8992
let ocamldep = ref (V"OCAMLDEP")
9093
let ocamldoc = ref (V"OCAMLDOC")
9194
let ocamlyacc = ref N
@@ -99,6 +102,7 @@ let ocamlfind arg =
99102
S[!ocamlfind_cmd; arg]
100103
else
101104
S[!ocamlfind_cmd; A"-toolchain"; A!toolchain; arg]
105+
let plugin_ocamlfind arg = S[!ocamlfind_cmd; arg]
102106
let program_to_execute = ref false
103107
let must_clean = ref false
104108
let show_documentation = ref false
@@ -142,7 +146,9 @@ let dummy = "*invalid-dummy-string*";; (* Dummy string for delimiting the latest
142146
* multiple/installed plugins *)
143147
let use_jocaml () =
144148
ocamlc := A "jocamlc";
149+
plugin_ocamlc := A "jocamlc";
145150
ocamlopt := A "jocamlopt";
151+
plugin_ocamlopt := A "jocamlopt";
146152
ocamldep := A "jocamldep";
147153
ocamlyacc := A "jocamlyacc";
148154
ocamllex := A "jocamllex";
@@ -234,11 +240,16 @@ let spec = ref (
234240
"-classic-display", Set Log.classic_display, " Display executed commands the old-fashioned way";
235241
"-use-menhir", Set use_menhir, " Use menhir instead of ocamlyacc";
236242
"-use-jocaml", Unit use_jocaml, " Use jocaml compilers instead of ocaml ones";
237-
"-use-ocamlfind", Set use_ocamlfind, " Use the 'ocamlfind' wrapper instead of \
243+
"-use-ocamlfind", Unit (fun () -> use_ocamlfind := true; plugin_use_ocamlfind := true), " Use the 'ocamlfind' wrapper instead of \
238244
using Findlib directly to determine command-line arguments. \
239-
Use -no-ocamlfind to disable.";
240-
"-no-ocamlfind", Clear use_ocamlfind, " Don't use ocamlfind.";
241-
"-toolchain", Set_string toolchain, "<toolchain> Set the Findlib toolchain to use.";
245+
Use -no-ocamlfind to disable. Implies -plugin-use-ocamlfind.";
246+
"-no-ocamlfind", Unit (fun () -> use_ocamlfind := false; plugin_use_ocamlfind := false), " Don't use ocamlfind. Implies -plugin-no-ocamlfind.";
247+
"-plugin-use-ocamlfind", Set plugin_use_ocamlfind, " Use the 'ocamlfind' wrapper \
248+
for building myocamlbuild.ml";
249+
"-plugin-no-ocamlfind", Clear plugin_use_ocamlfind, " Don't use ocamlfind \
250+
for building myocamlbuild.ml";
251+
"-toolchain", Set_string toolchain, "<toolchain> Set the Findlib toolchain to use. \
252+
The default toolchain is always used for building myocamlbuild.ml.";
242253

243254
"-j", Set_int Command.jobs, "<N> Allow N jobs at once (0 for unlimited)";
244255

@@ -248,7 +259,11 @@ let spec = ref (
248259
"-where", Unit (fun () -> print_endline !Ocamlbuild_where.libdir; raise Exit_OK), " Display the install library directory";
249260
"-which", String (fun cmd -> print_endline (find_tool cmd); raise Exit_OK), "<command> Display path to the tool command";
250261
"-ocamlc", set_cmd ocamlc, "<command> Set the OCaml bytecode compiler";
262+
"-plugin-ocamlc", set_cmd plugin_ocamlc, "<command> Set the OCaml bytecode compiler \
263+
used when building myocamlbuild.ml (only)";
251264
"-ocamlopt", set_cmd ocamlopt, "<command> Set the OCaml native compiler";
265+
"-plugin-ocamlopt", set_cmd plugin_ocamlopt, "<command> Set the OCaml native compiler \
266+
used when building myocamlbuild.ml (only)";
252267
"-ocamldep", set_cmd ocamldep, "<command> Set the OCaml dependency tool";
253268
"-ocamldoc", set_cmd ocamldoc, "<command> Set the OCaml documentation generator";
254269
"-ocamlyacc", set_cmd ocamlyacc, "<command> Set the ocamlyacc tool";
@@ -305,34 +320,47 @@ let init () =
305320
Log.init log
306321
in
307322

323+
let with_ocamlfind (ocamlfind, command_name, command_ref) =
324+
command_ref := match !command_ref with
325+
| Sh user_command ->
326+
(* this command has been set by the user
327+
using an -ocamlc, -ocamlopt, etc. flag;
328+
329+
not all such combinations make sense (eg. "ocamlfind
330+
/my/special/path/to/ocamlc" will make ocamlfind choke),
331+
but the user will see the error and hopefully fix the
332+
flags. *)
333+
ocamlfind & (Sh user_command);
334+
| _ -> ocamlfind & A command_name
335+
in
336+
308337
if !use_ocamlfind then begin
309338
begin try ignore(Command.search_in_path "ocamlfind")
310339
with Not_found ->
311340
failwith "ocamlfind not found on path, but -no-ocamlfind not used"
312341
end;
313342

314-
let with_ocamlfind (command_name, command_ref) =
315-
command_ref := match !command_ref with
316-
| Sh user_command ->
317-
(* this command has been set by the user
318-
using an -ocamlc, -ocamlopt, etc. flag;
319-
320-
not all such combinations make sense (eg. "ocamlfind
321-
/my/special/path/to/ocamlc" will make ocamlfind choke),
322-
but the user will see the error and hopefully fix the
323-
flags. *)
324-
ocamlfind & (Sh user_command);
325-
| _ -> ocamlfind & A command_name
326-
in
327343
(* Note that plugins can still modify these variables After_options.
328344
This design decision can easily be changed. *)
329345
List.iter with_ocamlfind [
330-
"ocamlc", ocamlc;
331-
"ocamlopt", ocamlopt;
332-
"ocamldep", ocamldep;
333-
"ocamldoc", ocamldoc;
334-
"ocamlmklib", ocamlmklib;
335-
"ocamlmktop", ocamlmktop;
346+
ocamlfind, "ocamlc", ocamlc;
347+
ocamlfind, "ocamlopt", ocamlopt;
348+
ocamlfind, "ocamldep", ocamldep;
349+
ocamlfind, "ocamldoc", ocamldoc;
350+
ocamlfind, "ocamlmklib", ocamlmklib;
351+
ocamlfind, "ocamlmktop", ocamlmktop;
352+
]
353+
end;
354+
355+
if !plugin_use_ocamlfind then begin
356+
begin try ignore(Command.search_in_path "ocamlfind")
357+
with Not_found ->
358+
failwith "ocamlfind not found on path, but -no-plugin-ocamlfind not used"
359+
end;
360+
361+
List.iter with_ocamlfind [
362+
plugin_ocamlfind, "ocamlc", plugin_ocamlc;
363+
plugin_ocamlfind, "ocamlopt", plugin_ocamlopt;
336364
]
337365
end;
338366

src/plugin.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,17 @@ module Make(U:sig end) =
8686

8787
let cma, cmo, compiler, byte_or_native =
8888
if !Options.native_plugin then
89-
"cmxa", "cmx", !Options.ocamlopt, "native"
89+
"cmxa", "cmx", !Options.plugin_ocamlopt, "native"
9090
else
91-
"cma", "cmo", !Options.ocamlc, "byte"
91+
"cma", "cmo", !Options.plugin_ocamlc, "byte"
9292
in
9393

94-
9594
let (unix_spec, ocamlbuild_lib_spec, ocamlbuild_module_spec) =
9695

9796
let use_light_mode =
9897
not !Options.native_plugin && !*My_unix.is_degraded in
9998
let use_ocamlfind_pkgs =
100-
!Options.use_ocamlfind && !Options.plugin_tags <> [] in
99+
!Options.plugin_use_ocamlfind && !Options.plugin_tags <> [] in
101100
(* The plugin has the following dependencies that must be
102101
included during compilation:
103102
@@ -127,7 +126,7 @@ module Make(U:sig end) =
127126
to support modular construction of
128127
ocamlbuild plugins). Indeed, if we hard-code linking to
129128
unix.cmxa in all cases, and the user
130-
enables -use-ocamlfind and
129+
enables -plugin-use-ocamlfind and
131130
passes -plugin-tag "package(unix)" (or package(foo) for
132131
any foo which depends on unix), the command-line finally
133132
executed will be
@@ -146,7 +145,7 @@ module Make(U:sig end) =
146145
147146
We switch to this behavior when two conditions, embodied in
148147
the boolean variable [use_ocamlfind_pkgs], are met:
149-
(a) use-ocamlfind is enabled
148+
(a) plugin-use-ocamlfind is enabled
150149
(b) the user is passing some plugin tags
151150
152151
Condition (a) is overly conservative as the double-linking

src/signatures.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ module type OPTIONS = sig
382382
val exclude_dirs : string list ref
383383
val nothing_should_be_rebuilt : bool ref
384384
val ocamlc : command_spec ref
385+
val plugin_ocamlc : command_spec ref
385386
val ocamlopt : command_spec ref
387+
val plugin_ocamlopt : command_spec ref
386388
val ocamldep : command_spec ref
387389
val ocamldoc : command_spec ref
388390
val ocamlyacc : command_spec ref
@@ -406,6 +408,7 @@ module type OPTIONS = sig
406408
val show_documentation : bool ref
407409
val recursive : bool ref
408410
val use_ocamlfind : bool ref
411+
val plugin_use_ocamlfind : bool ref
409412

410413
val targets : string list ref
411414
val ocaml_libs : string list ref

0 commit comments

Comments
 (0)