Codebase list dune / upstream/1.6.3
New upstream version 1.6.3 Stephane Glondu authored 4 years ago Stephane Glondu committed 4 years ago
35 changed file(s) with 326 addition(s) and 180 deletion(s). Raw diff Collapse all Expand all
0 1.6.3 (08/01/2019)
1 ------------------
2
3 - Fix merlin handling of private module visibility (#1653 @bobot)
4
5 - skip directories when looking up programs in the PATH (#1628, fixes
6 #1616, @diml)
7
8 - Fix preprocessing for libraries with `(include_subdirs ..)` (#1624, fix #1626,
9 @nojb, @rgrinberg)
10
11 - Do not generate targets for archive that don't match the `modes` field.
12 (#1632, fix #1617, @rgrinberg)
13
14 - When executing actions, open files lazily and close them as soon as
15 possible in order to reduce the maximum number of file descriptors
16 opened by Dune (#1635, #1643, fixes #1633, @jonludlam, @rgrinberg,
17 @diml)
18
19 - Do not generate targets for archive that don't match the `modes` field.
20 (#1632, fix #1617, @rgrinberg)
21
22 - Get the correct environment node for multi project workspaces (#1648,
23 @rgrinberg)
24
25 - Fix an issue causing menhir generated parsers to fail to build in
26 some cases. The fix is to systematically use `-short-paths` when
27 calling `ocamlc -i` (#1743, fix #1504, @diml)
28
029 1.6.2 (05/12/2018)
130 ------------------
231
00 PREFIX_ARG := $(if $(PREFIX),--prefix $(PREFIX),)
11 LIBDIR_ARG := $(if $(LIBDIR),--libdir $(LIBDIR),)
22 INSTALL_ARGS := $(PREFIX_ARG) $(LIBDIR_ARG)
3 BIN := ./_build/default/bin/main_dune.exe
3 BIN := ./_build_bootstrap/default/bin/main_dune.exe
44
55 -include Makefile.dev
66
1414 ocaml bootstrap.ml
1515
1616 install:
17 $(BIN) install $(INSTALL_ARGS) dune
17 $(BIN) install $(INSTALL_ARGS) dune --build-dir _build_bootstrap
1818
1919 uninstall:
20 $(BIN) uninstall $(INSTALL_ARGS) dune
20 $(BIN) uninstall $(INSTALL_ARGS) dune --build-dir _build_bootstrap
2121
2222 reinstall: uninstall reinstall
2323
4343
4444 clean:
4545 rm -f ./boot.exe $(wildcard ./bootstrap.cmi ./bootstrap.cmo ./bootstrap.exe)
46 $(BIN) clean
46 $(BIN) clean || true
47 rm -rf _build_bootstrap
4748
4849 distclean: clean
4950 rm -f src/setup.ml
116116 ```sh
117117 $ ocaml bootstrap.ml
118118 $ ./boot.exe
119 $ ./_build/default/bin/main_dune.exe install dune
119 $ ./_build_bootstrap/default/bin/main_dune.exe install dune
120120 ```
121121
122122 Support
77 - cd "%APPVEYOR_BUILD_FOLDER%"
88 - ocaml bootstrap.ml
99 - boot.exe
10 - copy _build\install\default\bin\dune.exe dune.exe
10 - copy _build_bootstrap\install\default\bin\dune.exe dune.exe
1111 - dune.exe build @test\blackbox-tests\windows-diff
1212
1313 artifacts:
1414 - path: _build/log
1515 name: build-log
16 - path: _build_bootstrap/log
17 name: build_bootstrap-log
823823 in
824824 (term, Term.info "exec" ~doc ~man)
825825
826 (** A string that is "1.6.2" but not expanded by [dune subst] *)
826 (** A string that is "1.6.3" but not expanded by [dune subst] *)
827827 let literal_version =
828828 "%%" ^ "VERSION%%"
829829
11951195 `Help (`Pager, None)
11961196 in
11971197 (term,
1198 Term.info "dune" ~doc ~version:"1.6.2"
1198 Term.info "dune" ~doc ~version:"1.6.3"
11991199 ~man:
12001200 [ `S "DESCRIPTION"
12011201 ; `P {|Dune is a build system designed for OCaml projects only. It
0 version: "1.6.2"
0 version: "1.6.3"
11 opam-version: "2.0"
22 maintainer: "opensource@janestreet.com"
33 authors: ["Jane Street Group, LLC <opensource@janestreet.com>"]
66 ; purpose : Process.purpose
77 }
88
9 let get_std_output : _ -> Process.std_output_to = function
10 | None -> Terminal
11 | Some (fn, oc) ->
12 Opened_file { filename = fn
13 ; tail = false
14 ; desc = Channel oc }
15
16
17 let exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args =
9 let exec_run ~ectx ~dir ~env ~stdout_to ~stderr_to prog args =
1810 begin match ectx.context with
1911 | None
2012 | Some { Context.for_host = None; _ } -> ()
3426 ~purpose:ectx.purpose
3527 prog args
3628
37 let exec_run ~stdout_to ~stderr_to =
38 let stdout_to = get_std_output stdout_to in
39 let stderr_to = get_std_output stderr_to in
40 exec_run_direct ~stdout_to ~stderr_to
41
4229 let exec_echo stdout_to str =
43 Fiber.return
44 (match stdout_to with
45 | None -> print_string str; flush stdout
46 | Some (_, oc) -> output_string oc str)
30 Fiber.return (output_string (Process.Output.channel stdout_to) str)
4731
4832 let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
4933 match (t : Action.t) with
5943 | Redirect (Stdout, fn, Echo s) ->
6044 Io.write_file fn (String.concat s ~sep:" ");
6145 Fiber.return ()
62 | Redirect (outputs, fn, Run (Ok prog, args)) ->
63 let out = Process.File fn in
64 let stdout_to, stderr_to =
65 match outputs with
66 | Stdout -> (out, get_std_output stderr_to)
67 | Stderr -> (get_std_output stdout_to, out)
68 | Outputs -> (out, out)
69 in
70 exec_run_direct ~ectx ~dir ~env ~stdout_to ~stderr_to prog args
7146 | Redirect (outputs, fn, t) ->
7247 redirect ~ectx ~dir outputs fn t ~env ~stdout_to ~stderr_to
7348 | Ignore (outputs, t) ->
7752 | Echo strs -> exec_echo stdout_to (String.concat strs ~sep:" ")
7853 | Cat fn ->
7954 Io.with_file_in fn ~f:(fun ic ->
80 let oc =
81 match stdout_to with
82 | None -> stdout
83 | Some (_, oc) -> oc
84 in
85 Io.copy_channels ic oc);
55 Io.copy_channels ic (Process.Output.channel stdout_to));
8656 Fiber.return ()
8757 | Copy (src, dst) ->
8858 Io.copy_file ~src ~dst ();
194164 Fiber.return ()
195165
196166 and redirect outputs fn t ~ectx ~dir ~env ~stdout_to ~stderr_to =
197 let oc = Io.open_out fn in
198 let out = Some (fn, oc) in
167 let out = Process.Output.file fn in
199168 let stdout_to, stderr_to =
200169 match outputs with
201170 | Stdout -> (out, stderr_to)
203172 | Outputs -> (out, out)
204173 in
205174 exec t ~ectx ~dir ~env ~stdout_to ~stderr_to >>| fun () ->
206 close_out oc
175 Process.Output.release out
207176
208177 and exec_list l ~ectx ~dir ~env ~stdout_to ~stderr_to =
209178 match l with
212181 | [t] ->
213182 exec t ~ectx ~dir ~env ~stdout_to ~stderr_to
214183 | t :: rest ->
215 exec t ~ectx ~dir ~env ~stdout_to ~stderr_to >>= fun () ->
184 (let stdout_to = Process.Output.multi_use stdout_to in
185 let stderr_to = Process.Output.multi_use stderr_to in
186 exec t ~ectx ~dir ~env ~stdout_to ~stderr_to) >>= fun () ->
216187 exec_list rest ~ectx ~dir ~env ~stdout_to ~stderr_to
217188
218189 let exec ~targets ~context ~env t =
224195 in
225196 let purpose = Process.Build_job targets in
226197 let ectx = { purpose; context } in
227 exec t ~ectx ~dir:Path.root ~env ~stdout_to:None ~stderr_to:None
198 exec t ~ectx ~dir:Path.root ~env
199 ~stdout_to:Process.Output.stdout
200 ~stderr_to:Process.Output.stderr
33 { dir : Path.t
44 ; inherit_from : t Lazy.t option
55 ; scope : Scope.t
6 ; config : Dune_env.Stanza.t
7 ; mutable file_bindings : string File_bindings.t option
6 ; config : Dune_env.Stanza.t option
7 ; mutable local_binaries : string File_bindings.t option
88 ; mutable ocaml_flags : Ocaml_flags.t option
99 ; mutable external_ : Env.t option
1010 ; mutable artifacts : Artifacts.t option
2020 ; ocaml_flags = None
2121 ; external_ = env
2222 ; artifacts = None
23 ; file_bindings = None
23 ; local_binaries = None
2424 }
2525
26 let file_bindings t ~profile ~expander =
27 match t.file_bindings with
26 let find_config t ~profile =
27 let open Option.O in
28 t.config >>= fun config ->
29 Dune_env.Stanza.find config ~profile
30
31 let local_binaries t ~profile ~expander =
32 match t.local_binaries with
2833 | Some x -> x
2934 | None ->
30 let file_bindings =
31 match Dune_env.Stanza.find t.config ~profile with
35 let local_binaries =
36 match find_config t ~profile with
3237 | None -> []
3338 | Some cfg ->
3439 File_bindings.map cfg.binaries ~f:(fun template ->
3540 Expander.expand expander ~mode:Single ~template
3641 |> Value.to_string ~dir:t.dir)
3742 in
38 t.file_bindings <- Some file_bindings;
39 file_bindings
43 t.local_binaries <- Some local_binaries;
44 local_binaries
4045
4146 let rec external_ t ~profile ~default =
4247 match t.external_ with
4853 | Some (lazy t) -> external_ t ~default ~profile
4954 in
5055 let (env, have_binaries) =
51 match Dune_env.Stanza.find t.config ~profile with
56 match find_config t ~profile with
5257 | None -> (default, false)
5358 | Some cfg ->
5459 ( Env.extend_env default cfg.env_vars
7479 | Some (lazy t) -> artifacts t ~default ~profile ~expander
7580 in
7681 let artifacts =
77 file_bindings t ~profile ~expander
82 local_binaries t ~profile ~expander
7883 |> Artifacts.add_binaries default ~dir:t.dir
7984 in
8085 t.artifacts <- Some artifacts;
9095 | Some (lazy t) -> ocaml_flags t ~profile ~expander
9196 in
9297 let flags =
93 match Dune_env.Stanza.find t.config ~profile with
98 match find_config t ~profile with
9499 | None -> default
95100 | Some cfg ->
96101 let expander = Expander.set_dir expander ~dir:t.dir in
88 : dir:Path.t
99 -> inherit_from:t Lazy.t option
1010 -> scope:Scope.t
11 -> config:Dune_env.Stanza.t
11 -> config:Dune_env.Stanza.t option
1212 -> env:Env.t option
1313 -> t
1414
1818
1919 val ocaml_flags : t -> profile:string -> expander:Expander.t -> Ocaml_flags.t
2020
21 val file_bindings
21 val local_binaries
2222 : t
2323 -> profile:string
2424 -> expander:Expander.t
198198 begin match List.last comps with
199199 | Some ".bin" ->
200200 let src_dir = Path.parent_exn dir in
201 Super_context.file_bindings sctx ~dir
201 Super_context.local_binaries sctx ~dir:src_dir
202202 |> List.iter ~f:(fun t ->
203203 let src = File_bindings.src_path t ~dir:src_dir in
204204 let dst = File_bindings.dst_path t ~dir in
401401 ]
402402 modules
403403 in
404
405 let modes =
406 Mode_conf.Set.eval lib.modes
407 ~has_native:(Option.is_some ctx.ocamlopt) in
404408 (let modules = modules @ wrapped_compat in
405 List.iter Mode.all ~f:(fun mode ->
409 Mode.Dict.Set.to_list modes
410 |> List.iter ~f:(fun mode ->
406411 build_lib lib ~expander ~flags ~dir ~obj_dir ~mode ~top_sorted_modules
407412 ~modules));
408413 (* Build *.cma.js *)
409 SC.add_rules sctx ~dir (
410 let src =
411 Library.archive lib ~dir
412 ~ext:(Mode.compiled_lib_ext Mode.Byte) in
413 let target =
414 Path.relative obj_dir (Path.basename src)
415 |> Path.extend_basename ~suffix:".js" in
416 Js_of_ocaml_rules.build_cm cctx ~js_of_ocaml ~src ~target);
417 if Dynlink_supported.By_the_os.get ctx.natdynlink_supported then
414 if modes.byte then
415 SC.add_rules sctx ~dir (
416 let src =
417 Library.archive lib ~dir
418 ~ext:(Mode.compiled_lib_ext Mode.Byte) in
419 let target =
420 Path.relative obj_dir (Path.basename src)
421 |> Path.extend_basename ~suffix:".js" in
422 Js_of_ocaml_rules.build_cm cctx ~js_of_ocaml ~src ~target);
423 if Dynlink_supported.By_the_os.get ctx.natdynlink_supported
424 && modes.native then
418425 build_shared lib ~dir ~flags ~ctx
419426
420427 let library_rules (lib : Library.t) ~dir_contents ~dir ~expander ~scope
540547 ; compile_info
541548 };
542549
550 let objs_dirs = Path.Set.singleton obj_dir in
551 let objs_dirs = if Lib_modules.has_private_modules lib_modules then
552 Path.Set.add objs_dirs private_obj_dir
553 else objs_dirs in
554
543555 (cctx,
544556 Merlin.make ()
545557 ~requires:(Lib.Compile.requires compile_info)
546558 ~flags
547559 ~preprocess:(Buildable.single_preprocess lib.buildable)
548560 ~libname:(snd lib.name)
549 ~objs_dirs:(Path.Set.singleton obj_dir))
561 ~objs_dirs
562 )
550563
551564 let rules (lib : Library.t) ~dir_contents ~dir ~expander ~scope
552565 ~dir_kind : Compilation_context.t * Merlin.t =
143143 | None -> loop rest
144144 | Some prog ->
145145 Process.run_capture (Accept All) prog args ~env:Env.initial
146 ~stderr_to:(File Config.dev_null)
146 ~stderr_to:(Process.Output.file Config.dev_null)
147147 >>= function
148148 | Error _ -> loop rest
149149 | Ok s ->
171171 let bootstrap () =
172172 Colors.setup_err_formatter_colors ();
173173 Path.set_root Path.External.initial_cwd;
174 Path.set_build_dir (Path.Kind.of_string "_build");
174 Path.set_build_dir (Path.Kind.of_string "_build_bootstrap");
175175 let main () =
176176 let anon s = raise (Arg.Bad (Printf.sprintf "don't know what to do with %s\n" s)) in
177177 let subst () =
143143 Lib.src_dir lib
144144 |> Path.drop_optional_build_context)
145145 ,
146 let obj_dirs = Path.Set.add obj_dirs (Lib.obj_dir lib) in
147 match Lib.private_obj_dir lib with
148 | None -> obj_dirs
149 | Some private_obj_dir -> Path.Set.add obj_dirs private_obj_dir
146 Path.Set.add obj_dirs (Lib.obj_dir lib)
150147 ))
151148 in
152149 let src_dirs =
209209 | Some (m : Module.t) ->
210210 As ["-open"; Module.Name.to_string (Module.name m)])
211211 ; As flags
212 ; A "-short-paths"
212213 ; A "-i"; Ml_kind.flag Impl; Dep src
213214 ]
214215 >>^ (fun act -> Action.with_stdout_to output act)
664664 ~expander
665665 ~dep_kind
666666 ~targets:(Static [dst])
667 ~targets_dir:dir))
667 ~targets_dir:(Path.parent_exn dst)))
668668 |> setup_reason_rules sctx in
669669 if lint then lint_module ~ast ~source:m;
670670 ast)
2929 | 0 -> Ok (f ())
3030 | n -> Error n
3131
32 type std_output_to =
33 | Terminal
34 | File of Path.t
35 | Opened_file of opened_file
36
37 and opened_file =
38 { filename : Path.t
39 ; desc : opened_file_desc
40 ; tail : bool
41 }
42
43 and opened_file_desc =
44 | Fd of Unix.file_descr
45 | Channel of out_channel
32 module Output = struct
33 type t =
34 { kind : kind
35 ; fd : Unix.file_descr Lazy.t
36 ; channel : out_channel Lazy.t
37 ; mutable status : status
38 }
39
40 and kind =
41 | File of Path.t
42 | Terminal
43
44 and status =
45 | Keep_open
46 | Close_after_exec
47 | Closed
48
49 let terminal oc =
50 let fd = Unix.descr_of_out_channel oc in
51 { kind = Terminal
52 ; fd = lazy fd
53 ; channel = lazy stdout
54 ; status = Keep_open
55 }
56 let stdout = terminal stdout
57 let stderr = terminal stderr
58
59 let file fn =
60 let fd =
61 lazy (Unix.openfile (Path.to_string fn)
62 [O_WRONLY; O_CREAT; O_TRUNC; O_SHARE_DELETE] 0o666)
63 in
64 { kind = File fn
65 ; fd
66 ; channel = lazy (Unix.out_channel_of_descr (Lazy.force fd))
67 ; status = Close_after_exec
68 }
69
70 let flush t =
71 if Lazy.is_val t.channel then flush (Lazy.force t.channel)
72
73 let fd t =
74 flush t;
75 Lazy.force t.fd
76
77 let channel t = Lazy.force t.channel
78
79 let release t =
80 match t.status with
81 | Closed -> ()
82 | Keep_open -> flush t
83 | Close_after_exec ->
84 t.status <- Closed;
85 if Lazy.is_val t.channel then
86 close_out (Lazy.force t.channel)
87 else
88 Unix.close (Lazy.force t.fd)
89
90 let multi_use t =
91 { t with status = Keep_open }
92 end
4693
4794 type purpose =
4895 | Internal_job
111158 "-o" :: Colors.(apply_string output_filename) fn :: colorize_args rest
112159 | x :: rest -> x :: colorize_args rest
113160
114 let command_line ~prog ~args ~dir ~stdout_to ~stderr_to =
161 let command_line ~prog ~args ~dir
162 ~(stdout_to:Output.t) ~(stderr_to:Output.t) =
115163 let prog = Path.reach_for_running ?from:dir prog in
116164 let quote = quote_for_shell in
117165 let prog = colorize_prog (quote prog) in
123171 | None -> s
124172 | Some dir -> sprintf "(cd %s && %s)" (Path.to_string dir) s
125173 in
126 match stdout_to, stderr_to with
127 | (File fn1 | Opened_file { filename = fn1; _ }),
128 (File fn2 | Opened_file { filename = fn2; _ }) when Path.equal fn1 fn2 ->
174 match stdout_to.kind, stderr_to.kind with
175 | File fn1, File fn2 when Path.equal fn1 fn2 ->
129176 sprintf "%s &> %s" s (Path.to_string fn1)
130177 | _ ->
131178 let s =
132 match stdout_to with
179 match stdout_to.kind with
133180 | Terminal -> s
134 | File fn | Opened_file { filename = fn; _ } ->
181 | File fn ->
135182 sprintf "%s > %s" s (Path.to_string fn)
136183 in
137 match stderr_to with
184 match stderr_to.kind with
138185 | Terminal -> s
139 | File fn | Opened_file { filename = fn; _ } ->
186 | File fn ->
140187 sprintf "%s 2> %s" s (Path.to_string fn)
141188
142189 let pp_purpose ppf = function
190237 contexts;
191238 end
192239
193 let get_std_output ~default = function
194 | Terminal -> (default, None)
195 | File fn ->
196 let fd = Unix.openfile (Path.to_string fn)
197 [O_WRONLY; O_CREAT; O_TRUNC; O_SHARE_DELETE] 0o666 in
198 (fd, Some (Fd fd))
199 | Opened_file { desc; tail; _ } ->
200 let fd =
201 match desc with
202 | Fd fd -> fd
203 | Channel oc -> flush oc; Unix.descr_of_out_channel oc
204 in
205 (fd, Option.some_if tail desc)
206
207 let close_std_output = function
208 | None -> ()
209 | Some (Fd fd) -> Unix.close fd
210 | Some (Channel oc) -> close_out oc
211
212240 let gen_id =
213241 let next = ref (-1) in
214242 fun () -> incr next; !next
217245 List.fold_left args ~init:(String.length prog) ~f:(fun acc arg ->
218246 acc + String.length arg)
219247
220 let run_internal ?dir ?(stdout_to=Terminal) ?(stderr_to=Terminal) ~env ~purpose
221 fail_mode prog args =
248 let run_internal ?dir ?(stdout_to=Output.stdout) ?(stderr_to=Output.stderr)
249 ~env ~purpose fail_mode prog args =
222250 Scheduler.wait_for_available_job ()
223251 >>= fun scheduler ->
224252 let display = Scheduler.display scheduler in
253281 (args, None)
254282 in
255283 let argv = prog_str :: args in
256 let output_filename, stdout_fd, stderr_fd, to_close =
257 match stdout_to, stderr_to with
284 let output_filename, stdout_to, stderr_to =
285 match stdout_to.kind, stderr_to.kind with
258286 | (Terminal, _ | _, Terminal) when !Clflags.capture_outputs ->
259287 let fn = Temp.create "dune" ".output" in
260 let fd = Unix.openfile (Path.to_string fn) [O_WRONLY; O_SHARE_DELETE] 0 in
261 (Some fn, fd, fd, Some fd)
288 let terminal = Output.file fn in
289 let get (out : Output.t) =
290 if out.kind = Terminal then begin
291 Output.flush out;
292 terminal
293 end else
294 out
295 in
296 (Some fn, get stdout_to, get stderr_to)
262297 | _ ->
263 (None, Unix.stdout, Unix.stderr, None)
264 in
265 let stdout, close_stdout = get_std_output stdout_to ~default:stdout_fd in
266 let stderr, close_stderr = get_std_output stderr_to ~default:stderr_fd in
267 let run () =
268 Spawn.spawn ()
269 ~prog:prog_str
270 ~argv
271 ~env:(Spawn.Env.of_array (Env.to_unix env))
272 ~stdout
273 ~stderr
298 (None, stdout_to, stderr_to)
299 in
300 let run =
301 (* Output.fd might create the file with Unix.openfile. We need to
302 make sure to call it before doing the chdir as the path might
303 be relative. *)
304 let stdout = Output.fd stdout_to in
305 let stderr = Output.fd stderr_to in
306 fun () ->
307 Spawn.spawn ()
308 ~prog:prog_str
309 ~argv
310 ~env:(Spawn.Env.of_array (Env.to_unix env))
311 ~stdout
312 ~stderr
274313 in
275314 let pid =
276315 match dir with
277316 | None -> run ()
278317 | Some dir -> Scheduler.with_chdir scheduler ~dir ~f:run
279318 in
280 Option.iter to_close ~f:Unix.close;
281 close_std_output close_stdout;
282 close_std_output close_stderr;
319 Output.release stdout_to;
320 Output.release stderr_to;
283321 Scheduler.wait_for_process pid
284322 >>| fun exit_status ->
285323 Option.iter response_file ~f:Path.unlink;
353391 prog args ~f =
354392 let fn = Temp.create "dune" ".output" in
355393 map_result fail_mode
356 (run_internal ?dir ~stdout_to:(File fn) ?stderr_to
394 (run_internal ?dir ~stdout_to:(Output.file fn) ?stderr_to
357395 ~env ~purpose fail_mode prog args)
358396 ~f:(fun () ->
359397 let x = f fn in
1313 (** Accept the following non-zero exit codes, and return [Error
1414 code] if the process exists with one of these codes. *)
1515
16 (** Where to redirect standard output *)
17 type std_output_to =
18 | Terminal
19 | File of Path.t
20 | Opened_file of opened_file
16 module Output : sig
17 (** Where to redirect stdout/stderr *)
18 type t
2119
22 and opened_file =
23 { filename : Path.t
24 ; desc : opened_file_desc
25 ; tail : bool
26 (** If [true], the descriptor is closed after starting the command *)
27 }
20 val stdout : t
21 val stderr : t
2822
29 and opened_file_desc =
30 | Fd of Unix.file_descr
31 | Channel of out_channel
23 (** Create a [t] representing redirecting the output to a file. The
24 returned output can only be used by a single call to {!run}. If
25 you want to use it multiple times, you need to use [clone]. *)
26 val file : Path.t -> t
27
28 (** Call this when you no longer need this output *)
29 val release : t -> unit
30
31 (** Return a buffered channel for this output. The channel is
32 created lazily. *)
33 val channel : t -> out_channel
34
35 (** [multi_use t] returns a copy for which [release] does nothing *)
36 val multi_use : t -> t
37 end
3238
3339 (** Why a Fiber.t was run *)
3440 type purpose =
3844 (** [run ?dir ?stdout_to prog args] spawns a sub-process and wait for its termination *)
3945 val run
4046 : ?dir:Path.t
41 -> ?stdout_to:std_output_to
42 -> ?stderr_to:std_output_to
47 -> ?stdout_to:Output.t
48 -> ?stderr_to:Output.t
4349 -> env:Env.t
4450 -> ?purpose:purpose
4551 -> (unit, 'a) failure_mode
5056 (** Run a command and capture its output *)
5157 val run_capture
5258 : ?dir:Path.t
53 -> ?stderr_to:std_output_to
59 -> ?stderr_to:Output.t
5460 -> env:Env.t
5561 -> ?purpose:purpose
5662 -> (string, 'a) failure_mode
5965 -> 'a Fiber.t
6066 val run_capture_line
6167 : ?dir:Path.t
62 -> ?stderr_to:std_output_to
68 -> ?stderr_to:Output.t
6369 -> env:Env.t
6470 -> ?purpose:purpose
6571 -> (string, 'a) failure_mode
6874 -> 'a Fiber.t
6975 val run_capture_lines
7076 : ?dir:Path.t
71 -> ?stderr_to:std_output_to
77 -> ?stderr_to:Output.t
7278 -> env:Env.t
7379 -> ?purpose:purpose
7480 -> (string list, 'a) failure_mode
7581 -> Path.t
7682 -> string list
7783 -> 'a Fiber.t
78
1717
1818 let exe = if Sys.win32 then ".exe" else ""
1919
20 let exists fn =
21 match Unix.stat (Path.to_string fn) with
22 | { st_kind = S_DIR; _ } -> false
23 | exception (Unix.Unix_error _) -> false
24 | _ -> true
25
2026 let best_prog dir prog =
2127 let fn = Path.relative dir (prog ^ ".opt" ^ exe) in
22 if Path.exists fn then
28 if exists fn then
2329 Some fn
2430 else
2531 let fn = Path.relative dir (prog ^ exe) in
26 if Path.exists fn then
32 if exists fn then
2733 Some fn
2834 else
2935 None
7373 val external_ : t -> dir:Path.t -> External_env.t
7474 val artifacts_host : t -> dir:Path.t -> Artifacts.t
7575 val expander : t -> dir:Path.t -> Expander.t
76 val file_bindings : t -> dir:Path.t -> string File_bindings.t
76 val local_binaries : t -> dir:Path.t -> string File_bindings.t
7777 end = struct
7878 let get_env_stanza t ~dir =
7979 let open Option.O in
9595 | None -> raise_notrace Exit
9696 | Some parent -> lazy (get t ~dir:parent ~scope)
9797 in
98 match get_env_stanza t ~dir with
99 | None -> Lazy.force inherit_from
100 | Some config ->
101 Env_node.make ~dir ~scope ~config ~inherit_from:(Some inherit_from)
102 ~env:None
98 let config = get_env_stanza t ~dir in
99 Env_node.make ~dir ~scope ~config ~inherit_from:(Some inherit_from)
100 ~env:None
103101 in
104102 Hashtbl.add t.env dir node;
105103 node
125123 |> Expander.set_scope ~scope:(Env_node.scope node)
126124 |> Expander.set_dir ~dir
127125
128 let file_bindings t ~dir =
126 let local_binaries t ~dir =
129127 let node = get t ~dir in
130128 let expander = expander_for_artifacts t ~dir in
131 Env_node.file_bindings node ~profile:(profile t) ~expander
129 Env_node.local_binaries node ~profile:(profile t) ~expander
132130
133131 let artifacts t ~dir =
134132 let expander = expander_for_artifacts t ~dir in
238236 ~default:(Env.ocaml_flags t ~dir)
239237 ~eval:(Expander.expand_and_eval_set expander)
240238
241 let file_bindings t ~dir = Env.file_bindings t ~dir
239 let local_binaries t ~dir = Env.local_binaries t ~dir
242240
243241 let dump_env t ~dir =
244242 Ocaml_flags.dump (Env.ocaml_flags t ~dir)
313311 in
314312 match context.env_nodes with
315313 | { context = None; workspace = None } ->
316 make ~config:{ loc = Loc.none; rules = [] } ~inherit_from:None
317 | { context = Some config; workspace = None }
318 | { context = None; workspace = Some config } ->
314 make ~config:(Some { loc = Loc.none; rules = [] }) ~inherit_from:None
315 | { context = Some _ as config; workspace = None }
316 | { context = None; workspace = Some _ as config } ->
319317 make ~config ~inherit_from:None
320 | { context = Some context ; workspace = Some workspace } ->
318 | { context = Some _ as context ; workspace = Some _ as workspace } ->
321319 make ~config:context
322 ~inherit_from:(Some (lazy (make ~inherit_from:None ~config:workspace)))
320 ~inherit_from:(Some (lazy (make ~inherit_from:None
321 ~config:workspace)))
323322 ) in
324323 let expander =
325324 let artifacts_host =
5252 -> Buildable.t
5353 -> Ocaml_flags.t
5454
55 val file_bindings : t -> dir:Path.t -> string File_bindings.t
55 (** Binaries that are symlinked in the associated .bin directory of [dir]. This
56 associated directory is [Path.relative dir ".bin"] *)
57 val local_binaries : t -> dir:Path.t -> string File_bindings.t
5658
5759 (** Dump a directory environment in a readable form *)
5860 val dump_env : t -> dir:Path.t -> (unit, Dune_lang.t list) Build.t
143143 (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
144144
145145 (alias
146 (name double-echo)
147 (deps (package dune) (source_tree test-cases/double-echo))
148 (action
149 (chdir
150 test-cases/double-echo
151 (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
152
153 (alias
146154 (name dune-build-dir-exec-1101)
147155 (deps (package dune) (source_tree test-cases/dune-build-dir-exec-1101))
148156 (action
444452 (action
445453 (chdir
446454 test-cases/github1560
455 (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
456
457 (alias
458 (name github1616)
459 (deps (package dune) (source_tree test-cases/github1616))
460 (action
461 (chdir
462 test-cases/github1616
447463 (progn (run %{exe:cram.exe} -test run.t) (diff? run.t run.t.corrected)))))
448464
449465 (alias
11701186 (alias depend-on-the-universe)
11711187 (alias deps-conf-vars)
11721188 (alias dev-flag-1103)
1189 (alias double-echo)
11731190 (alias dune-build-dir-exec-1101)
11741191 (alias dune-jbuild-var-case)
11751192 (alias dune-ppx-driver-system)
12071224 (alias github1529)
12081225 (alias github1549)
12091226 (alias github1560)
1227 (alias github1616)
12101228 (alias github20)
12111229 (alias github24)
12121230 (alias github25)
13131331 (alias depend-on-the-universe)
13141332 (alias deps-conf-vars)
13151333 (alias dev-flag-1103)
1334 (alias double-echo)
13161335 (alias dune-build-dir-exec-1101)
13171336 (alias dune-jbuild-var-case)
13181337 (alias dune-ppx-driver-system)
13481367 (alias github1529)
13491368 (alias github1549)
13501369 (alias github1560)
1370 (alias github1616)
13511371 (alias github20)
13521372 (alias github24)
13531373 (alias github25)
0 (rule
1 (with-stdout-to foobar
2 (progn
3 (echo "foo")
4 (echo "bar"))))
5
6 (alias
7 (name default)
8 (action (echo %{read:foobar})))
0 #!/bin/sh
1 exec echo 'Hello, World!'
0 (alias
1 (name default)
2 (action (run prog)))
0 Regression test for #1616
1
2 $ env PATH="$PWD/bin2:$PWD/bin1:$PATH" dune build --root root
3 Entering directory 'root'
4 prog alias default
5 Hello, World!
1010 B $LIB_PREFIX/lib/ocaml
1111 B ../_build/default/exe/.x.eobjs
1212 B ../_build/default/lib/.foo.objs
13 B ../_build/default/lib/.foo.objs/.private
1413 S $LIB_PREFIX/lib/bytes
1514 S $LIB_PREFIX/lib/findlib
1615 S $LIB_PREFIX/lib/ocaml
2423 B $LIB_PREFIX/lib/ocaml
2524 B ../_build/default/lib/.bar.objs
2625 B ../_build/default/lib/.foo.objs
26 B ../_build/default/lib/.foo.objs/.private
2727 S $LIB_PREFIX/lib/bytes
2828 S $LIB_PREFIX/lib/findlib
2929 S $LIB_PREFIX/lib/ocaml
4848 Error: This stanza is not allowed in a sub-directory of directory with (include_subdirs unqualified).
4949 Hint: add (include_subdirs no) to this file.
5050 [1]
51
52 Test for (include_subdir unqualified) with (preprocess (action ...))
53 --------------------------------------------------------------------
54
55 $ dune build --display short --root test4 @all
56 Entering directory 'test4'
57 ocamldep .main.eobjs/main.ml.d
58 ocamlc .main.eobjs/main.{cmi,cmo,cmt}
59 ocamlopt .main.eobjs/main.{cmx,o}
60 ocamlopt main.exe
61 main sub/foo.pp.ml
62 ocamldep .foo.objs/foo.pp.ml.d
63 ocamlc .foo.objs/foo.{cmi,cmo,cmt}
64 ocamlopt .foo.objs/foo.{cmx,o}
65 ocamlopt foo.{a,cmxa}
66 ocamlopt foo.cmxs
67 ocamlc main.bc
68 ocamlc foo.cma
0 (executable
1 (name main)
2 (modules main))
3
4 (library
5 (name foo)
6 (preprocess (action (run ./main.exe %{input-file})))
7 (modules foo))
8
9 (include_subdirs unqualified)
0 let () =
1 print_endline "print_endline \"foo\""