0.93
[imt.git] / dep7.ml
blob51a6bdf7b3e3071a5a0de4ee5ed7983aa6e4ca12
1 let note_re = Str.regexp "^Note: including file: *\\(.*\\)$"
3 let process_cl_dep7_output_line s set =
4 if Str.string_match note_re s 0
5 then
6 let win_path = Utils.safe_group 1 s in
7 let unix_path = Path.find2 win_path in
8 match unix_path with
9 | Some path ->
10 Utils.StringSet.add path set
11 | None ->
12 prerr_string
13 "Dep7.process_cl_dep7_output_line: Cannot find unix path for ";
14 prerr_endline (String.escaped win_path);
15 set
16 else
17 begin
18 Cl.process_cl_output_line s;
19 set
20 end
22 let test () =
23 let re = Str.regexp "/showIncludes" in
24 let tool = Utils.tool_name "cl" in
25 let command = Wine.command tool ^ " /?" in
26 let ic = Unix.open_process_in command in
27 let process s =
28 if Str.string_match re s 0
29 then
30 exit 0
31 else
34 Utils.iter_crlf_chan ic process;
35 exit 1
37 let invoke_aux deponly oc target argv arg_start =
38 let args = Utils.make_arg_string Path.check_and_modify_absolute argv arg_start in
39 let tool = Utils.tool_name "cl" in
40 let command =
41 Wine.command tool ^
42 (if deponly
43 then
44 " /Zs /showIncludes /nologo "
45 else
46 " /showIncludes /nologo "
47 ) ^
48 args
50 let ic = Unix.open_process_in command in
51 let ifiles =
52 Utils.fold_crlf_chan ic process_cl_dep7_output_line
53 Utils.StringSet.empty
55 let code = Utils.close_process_in ic in
56 if code = 0
57 then
58 begin
59 output_string oc target;
60 output_string oc ": ";
61 Utils.StringSet.iter
62 begin
63 fun s ->
64 output_string oc s;
65 output_char oc ' '
66 end ifiles;
67 output_string oc "\n";
68 end;
69 code
71 let invoke = invoke_aux true stdout
73 let invoke2 target depfile argv arg_start =
74 let oc =
75 try
76 open_out depfile
77 with exn ->
78 prerr_endline
79 ("Dep7.invoke2 could not open output file `" ^ depfile ^ "':\n " ^
80 (Printexc.to_string exn));
81 exit 101
83 let code = invoke_aux false oc target argv arg_start in
84 close_out oc;
85 code