84 lines
2.9 KiB
Diff
84 lines
2.9 KiB
Diff
From 1a9bd729b97db408022995f93b19678706a79ca7 Mon Sep 17 00:00:00 2001
|
|
From: Rudi Grinberg <me@rgrinberg.com>
|
|
Date: Mon, 24 Aug 2020 02:39:59 -0700
|
|
Subject: [PATCH] [configurator] more workaround for extracting #define
|
|
|
|
allow duplicate values if they are the same _after_ conversion
|
|
|
|
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
|
|
---
|
|
otherlibs/configurator/src/v1.ml | 46 ++++++++++++++++++--------------
|
|
1 file changed, 26 insertions(+), 20 deletions(-)
|
|
|
|
diff --git a/otherlibs/configurator/src/v1.ml b/otherlibs/configurator/src/v1.ml
|
|
index 721c0e7384..7e5dc19883 100644
|
|
--- a/otherlibs/configurator/src/v1.ml
|
|
+++ b/otherlibs/configurator/src/v1.ml
|
|
@@ -466,10 +466,6 @@ module C_define = struct
|
|
| Switch of bool
|
|
| Int of int
|
|
| String of string
|
|
-
|
|
- let switch b = Switch b
|
|
-
|
|
- let int i = Int i
|
|
end
|
|
|
|
let extract_program ?prelude includes vars =
|
|
@@ -544,29 +540,39 @@ const char *s%i = "BEGIN-%i-false-END";
|
|
Error [ v; v' ] )))
|
|
in
|
|
List.mapi vars ~f:(fun i (name, t) ->
|
|
- let raw_val =
|
|
+ let raw_vals =
|
|
match Int.Map.find values i with
|
|
+ | Some (Ok v) -> [ v ]
|
|
+ | Some (Error vs) -> vs
|
|
| None -> die "Unable to get value for %s" name
|
|
- | Some (Ok v) -> v
|
|
- | Some (Error vs) ->
|
|
- let vs = List.sort_uniq ~cmp:compare vs in
|
|
+ in
|
|
+ let parse_val_or_exn f =
|
|
+ let f x =
|
|
+ match f x with
|
|
+ | Some s -> s
|
|
+ | None ->
|
|
+ die
|
|
+ "Unable to read variable %S of type %s. Invalid value %S in %s \
|
|
+ found"
|
|
+ name (Type.name t) x obj_file
|
|
+ in
|
|
+ let vs =
|
|
+ List.map ~f:(fun x -> (x, f x)) raw_vals
|
|
+ |> List.sort_uniq ~cmp:(fun (_, x) (_, y) -> compare x y)
|
|
+ in
|
|
+ match vs with
|
|
+ | [] -> assert false
|
|
+ | [ (_, v) ] -> v
|
|
+ | vs ->
|
|
+ let vs = List.map ~f:fst vs in
|
|
die "Duplicate values for %s:\n%s" name
|
|
(vs |> List.map ~f:(sprintf "- %s") |> String.concat ~sep:"\n")
|
|
in
|
|
let value =
|
|
match t with
|
|
- | Type.Switch -> Bool.of_string raw_val |> Option.map ~f:Value.switch
|
|
- | Int -> Int.of_string raw_val |> Option.map ~f:Value.int
|
|
- | String -> Some (String raw_val)
|
|
- in
|
|
- let value =
|
|
- match value with
|
|
- | Some v -> v
|
|
- | None ->
|
|
- die
|
|
- "Unable to read variable %S of type %s. Invalid value %S in %s \
|
|
- found"
|
|
- name (Type.name t) raw_val obj_file
|
|
+ | Type.Switch -> Value.Switch (parse_val_or_exn Bool.of_string)
|
|
+ | Int -> Value.Int (parse_val_or_exn Int.of_string)
|
|
+ | String -> String (parse_val_or_exn (fun x -> Some x))
|
|
in
|
|
(name, value))
|
|
|