From 9df1bad58cc8902bf8ee528db9168358d4f1c513 Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Thu, 18 May 2017 16:50:53 +0100 Subject: [PATCH] Change an error into a warning Otherwise this breaks the build of atd. --- src/jbuild_types.ml | 15 ++++++--------- src/loc.ml | 10 ++++++++++ src/loc.mli | 6 ++++++ src/main.ml | 14 +++++++------- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/jbuild_types.ml b/src/jbuild_types.ml index eb4c6753..4553b80d 100644 --- a/src/jbuild_types.ml +++ b/src/jbuild_types.ml @@ -649,15 +649,12 @@ module Executables = struct in match to_install with | [] -> - map_validate (field_o "package" string) ~f:(function - | None -> Ok () - | Some _ -> - Error - (sprintf - "this field is useless without a (public_name%s ...) field" - (if multi then "s" else ""))) - >>= fun () -> - return (t, None) + (field_o "package" Sexp.Ast.loc >>= function + | None -> return (t, None) + | Some loc -> + Loc.warn loc "This field is useless without a (public_name%s ...) field." + (if multi then "s" else ""); + return (t, None)) | files -> Pkgs.package_field pkgs >>= fun package -> return (t, Some { Install_conf. section = Bin; files; package }) diff --git a/src/loc.ml b/src/loc.ml index 09112c81..e8abee43 100644 --- a/src/loc.ml +++ b/src/loc.ml @@ -31,3 +31,13 @@ let in_file fn = } let none = in_file "" + +let print ppf { start; stop } = + let start_c = start.pos_cnum - start.pos_bol in + let stop_c = stop.pos_cnum - start.pos_bol in + Format.fprintf ppf + "@{File \"%s\", line %d, characters %d-%d:@}@\n" + start.pos_fname start.pos_lnum start_c stop_c + +let warn t fmt = + Format.eprintf ("%a@{Warning@}: " ^^ fmt ^^ "@.") print t diff --git a/src/loc.mli b/src/loc.mli index 2d9b0ef4..dd09a63b 100644 --- a/src/loc.mli +++ b/src/loc.mli @@ -13,3 +13,9 @@ val fail_lex : Lexing.lexbuf -> ('a, unit, string, _) format4 -> 'a val in_file : string -> t val none : t + +(** Prints "File ..., line ..., characters ...:\n" *) +val print : Format.formatter -> t -> unit + +(** Prints a warning *) +val warn : t -> ('a, Format.formatter, unit) format -> 'a diff --git a/src/main.ml b/src/main.ml index 5fe42735..20ec6979 100644 --- a/src/main.ml +++ b/src/main.ml @@ -77,13 +77,13 @@ let external_lib_deps ?log ~packages () = let report_error ?(map_fname=fun x->x) ppf exn ~backtrace = match exn with - | Loc.Error ({ start; stop }, msg) -> - let start_c = start.pos_cnum - start.pos_bol in - let stop_c = stop.pos_cnum - start.pos_bol in - Format.fprintf ppf - "@{File \"%s\", line %d, characters %d-%d:@}\n\ - @{Error@}: %s\n" - (map_fname start.pos_fname) start.pos_lnum start_c stop_c msg + | Loc.Error (loc, msg) -> + let loc = + { loc with + start = { loc.start with pos_fname = map_fname loc.start.pos_fname } + } + in + Format.fprintf ppf "%a@{Error@}: %s\n" Loc.print loc msg | Fatal_error "" -> () | Fatal_error msg -> Format.fprintf ppf "%s\n" (String.capitalize_ascii msg)