Initial .gitignore
[imt.git] / dep7.ml
blob6e8f78ac5764355e9c3d3b7ca1ba6e9a99961452
1 let note_re = Str.regexp "^Note: including file: *\\(.*\\)$"
3 let process_cl_dep7_output_line rejrel 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 if Utils.reject_path path rejrel
11 then
12 set
13 else
14 Utils.StringSet.add path set
15 | None ->
16 prerr_string
17 "Dep7.process_cl_dep7_output_line: Cannot find unix path for "
19 prerr_endline (String.escaped win_path);
20 set
21 else
22 begin
23 Cl.process_cl_output_line s;
24 set
25 end
27 let test () =
28 let re = Str.regexp "-showIncludes" in
29 let tool = Utils.tool_name "cl" in
30 let command = Wine.command tool ^ " -?" in
31 let ic = Unix.open_process_in command in
32 let process s =
33 if Str.string_match re s 0
34 then
35 exit 0
36 else
39 Utils.iter_crlf_chan ic process;
40 exit 1
42 let invoke_aux deponly oc target argv arg_start =
43 let rejrel = Utils.build_reject_list () in
44 let args = Utils.make_arg_string Path.check_and_modify_absolute argv arg_start in
45 let tool = Utils.tool_name "cl" in
46 let command =
47 Utils.construct_args tool args
48 (if deponly
49 then
50 "-Zs -showIncludes -nologo"
51 else
52 "-showIncludes -nologo"
55 let ic = Unix.open_process_in command in
56 let ifiles =
57 Utils.fold_crlf_chan ic (process_cl_dep7_output_line rejrel)
58 Utils.StringSet.empty
60 let code = Utils.close_process_in ic in
61 if code = 0
62 then
63 begin
64 Utils.output_quoted_path oc target;
65 output_string oc ": ";
66 Utils.StringSet.iter
67 begin
68 fun s ->
69 Utils.output_quoted_path oc s;
70 output_char oc ' '
71 end ifiles;
72 output_string oc "\n";
73 end;
74 code
76 let invoke = invoke_aux true stdout
78 let invoke2 target depfile argv arg_start =
79 let oc =
80 if depfile = "CON" || depfile = "con"
81 then
82 stdout
83 else
84 try
85 open_out depfile
86 with exn ->
87 prerr_endline
88 ("Dep7.invoke2 could not open output file `" ^ depfile ^ "':\n " ^
89 (Printexc.to_string exn));
90 exit 101
92 let code = invoke_aux false oc target argv arg_start in
93 close_out oc;
94 code