From 9d3c0b649c602c15821a47e21fd5f4b2ff6b982b Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Thu, 7 Dec 2017 21:12:16 +0000 Subject: [PATCH] Fix copy# for Microsoft C compiler Microsoft CL doesn't support #n and requires the more strictly correct directive #line Signed-off-by: David Allsopp --- CHANGES.md | 2 ++ src/action.ml | 8 +++++++- src/path.ml | 2 ++ src/path.mli | 2 ++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f3a81243..84b1e400 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -26,6 +26,8 @@ next - Fix doc generation when several private libraries have the same name (#369) +- Fix copy# for C/C++ with Microsoft C compiler (#353) + 1.0+beta16 (05/11/2017) ----------------------- diff --git a/src/action.ml b/src/action.ml index b350a95f..1fb48b1d 100644 --- a/src/action.ml +++ b/src/action.ml @@ -596,7 +596,13 @@ let rec exec t ~ectx ~dir ~env_extra ~stdout_to ~stderr_to = Io.with_file_in (Path.to_string src) ~f:(fun ic -> Io.with_file_out (Path.to_string dst) ~f:(fun oc -> let fn = Path.drop_build_context src in - Printf.fprintf oc "# 1 %S\n" (Path.to_string fn); + let directive = + if List.mem (Path.extension fn) ~set:[".c"; ".cpp"; ".h"] then + "line" + else + "" + in + Printf.fprintf oc "#%s 1 %S\n" directive (Path.to_string fn); Io.copy_channels ic oc)); return () | System cmd -> diff --git a/src/path.ml b/src/path.ml index 81d56ed6..1d5cc623 100644 --- a/src/path.ml +++ b/src/path.ml @@ -426,4 +426,6 @@ let change_extension ~ext t = let t = try Filename.chop_extension t with Not_found -> t in t ^ ext +let extension = Filename.extension + let pp = Format.pp_print_string diff --git a/src/path.mli b/src/path.mli index 31d781d2..33b106e2 100644 --- a/src/path.mli +++ b/src/path.mli @@ -112,4 +112,6 @@ val rm_rf : t -> unit (** Changes the extension of the filename (or adds an extension if there was none) *) val change_extension : ext:string -> t -> t +val extension : t -> string + val pp : t Fmt.t