From d65845abb80957a7e66cb7519f88b47182ab0b6a Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 11 Apr 2018 21:26:51 +0700 Subject: [PATCH 1/4] Pass ocamlc explicitly to configurator using DUNE_CONFIGURATOR --- src/configurator/v1.ml | 5 +++-- src/context.ml | 1 + test/blackbox-tests/test-cases/configurator/config/run.ml | 4 ++++ test/blackbox-tests/test-cases/configurator/run.t | 1 + 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 1a159b40..5f6b5893 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -419,13 +419,14 @@ module Pkg_config = struct end let main ?(args=[]) ~name f = - let ocamlc = ref None in + let ocamlc = ref (Sys.getenv_opt "DUNE_CONFIGURATOR") in let verbose = ref false in let dest_dir = ref None in let args = Arg.align ([ "-ocamlc", Arg.String (fun s -> ocamlc := Some s), - "PATH ocamlc command to use" + "PATH ocamlc command to use. \ + This value is set automatically when configurator is invoked by dune." ; "-verbose", Arg.Set verbose, " be verbose" ; "-dest-dir", Arg.String (fun s -> dest_dir := Some s), diff --git a/src/context.ml b/src/context.ml index 4d0a90d8..4528c30f 100644 --- a/src/context.ml +++ b/src/context.ml @@ -303,6 +303,7 @@ let create ~(kind : Kind.t) ~path ~env ~name ~merlin ~targets () = "lib") ; extend_var "MANPATH" (Config.local_install_man_dir ~context:name) + ; "DUNE_CONFIGURATOR", (Path.to_string ocamlc) ] in Env.extend env ~vars:(Env.Map.of_list_exn vars) diff --git a/test/blackbox-tests/test-cases/configurator/config/run.ml b/test/blackbox-tests/test-cases/configurator/config/run.ml index b6f088d5..41bc97f0 100644 --- a/test/blackbox-tests/test-cases/configurator/config/run.ml +++ b/test/blackbox-tests/test-cases/configurator/config/run.ml @@ -1,6 +1,10 @@ module Configurator = Configurator.V1 let () = + begin match Sys.getenv_opt "DUNE_CONFIGURATOR" with + | None -> failwith "DUNE_CONFIGURATOR is not passed" + | Some _ -> print_endline "DUNE_CONFIGURATOR is present" + end; Configurator.main ~name:"config" (fun t -> match Configurator.ocaml_config_var t "version" with | None -> failwith "version is absent" diff --git a/test/blackbox-tests/test-cases/configurator/run.t b/test/blackbox-tests/test-cases/configurator/run.t index 9fbda06e..d5fc8675 100644 --- a/test/blackbox-tests/test-cases/configurator/run.t +++ b/test/blackbox-tests/test-cases/configurator/run.t @@ -1,5 +1,6 @@ Show that config values are present $ jbuilder exec config/run.exe + DUNE_CONFIGURATOR is present version is present We're able to compile C program sucessfully From 22576fac7eca5ec2149ff1ec22c18c6495f7d9af Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 11 Apr 2018 22:37:25 +0700 Subject: [PATCH 2/4] Fix compatibility for ocaml without Sys.getenv_opt --- src/configurator/v1.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 5f6b5893..ad347739 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -419,7 +419,10 @@ module Pkg_config = struct end let main ?(args=[]) ~name f = - let ocamlc = ref (Sys.getenv_opt "DUNE_CONFIGURATOR") in + let ocamlc = ref ( + match Sys.getenv "DUNE_CONFIGURATOR" with + | s -> Some s + | exception Not_found -> None) in let verbose = ref false in let dest_dir = ref None in let args = From 86e4df847bda5ecf611ab233edcdfc6377edb015 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 12 Apr 2018 00:00:31 +0700 Subject: [PATCH 3/4] Warn the user when DUNE_CONFIGURATOR is overwritten with -ocamlc --- src/configurator/v1.ml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index ad347739..7c209e93 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -427,7 +427,14 @@ let main ?(args=[]) ~name f = let dest_dir = ref None in let args = Arg.align - ([ "-ocamlc", Arg.String (fun s -> ocamlc := Some s), + ([ "-ocamlc", Arg.String (fun s -> + Option.iter !ocamlc ~f:(fun _ -> + Format.eprintf + "ocamlc is already passed through DUNE_CONFIGURATOR. \ + There's no need to pass it manually through -ocamlc.@." + ); + ocamlc := Some s + ), "PATH ocamlc command to use. \ This value is set automatically when configurator is invoked by dune." ; "-verbose", Arg.Set verbose, From 75bc824f97ddc1584978178e569ac0a9d1ce0aef Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Thu, 12 Apr 2018 18:05:40 +0700 Subject: [PATCH 4/4] Get rid of the -ocamlc arg altogether --- src/configurator/v1.ml | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/configurator/v1.ml b/src/configurator/v1.ml index 7c209e93..154c6f37 100644 --- a/src/configurator/v1.ml +++ b/src/configurator/v1.ml @@ -422,22 +422,15 @@ let main ?(args=[]) ~name f = let ocamlc = ref ( match Sys.getenv "DUNE_CONFIGURATOR" with | s -> Some s - | exception Not_found -> None) in + | exception Not_found -> + die "Configurator scripts must be ran with jbuilder. \ + To manually run a script, use $ jbuilder exec." + ) in let verbose = ref false in let dest_dir = ref None in let args = Arg.align - ([ "-ocamlc", Arg.String (fun s -> - Option.iter !ocamlc ~f:(fun _ -> - Format.eprintf - "ocamlc is already passed through DUNE_CONFIGURATOR. \ - There's no need to pass it manually through -ocamlc.@." - ); - ocamlc := Some s - ), - "PATH ocamlc command to use. \ - This value is set automatically when configurator is invoked by dune." - ; "-verbose", Arg.Set verbose, + ([ "-verbose", Arg.Set verbose, " be verbose" ; "-dest-dir", Arg.String (fun s -> dest_dir := Some s), "DIR save temporary files to this directory"