Skip to content

Commit fa5ada2

Browse files
committed
Add proper error checking for duplicate stub usage
Signed-off-by: Rudi Grinberg <[email protected]>
1 parent a951b6a commit fa5ada2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/c_sources.ml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,22 @@ let make (d : _ Dir_with_dune.t)
109109
in this directory"
110110
Lib_name.pp_quoted name
111111
in
112+
let () =
113+
let rev_map =
114+
List.concat_map libs ~f:(fun (_, c_sources) ->
115+
String.Map.values c_sources
116+
|> List.map ~f:(fun (loc, source) ->
117+
(C.Source.path source, loc)))
118+
|> Path.Map.of_list
119+
in
120+
match rev_map with
121+
| Ok _ -> ()
122+
| Error (_, loc1, loc2) ->
123+
Errors.fail loc2
124+
"This c stub is already used in another stanza:@\n\
125+
@[<v>%a@]@\n"
126+
(Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line)
127+
loc1
128+
in
112129
{ libraries
113130
}

test/blackbox-tests/test-cases/duplicate-c-cxx/run.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ c_names and cxx_names with overlapping names in the same stanza
1010
c_names with overlapping names in different stanzas
1111
$ dune build --root diff-stanza @all
1212
Entering directory 'diff-stanza'
13-
Multiple rules generated for _build/default/foo$ext_obj:
14-
- dune:9
13+
File "dune", line 9, characters 10-13:
14+
9 | (c_names foo))
15+
^^^
16+
Error: This c stub is already used in another stanza:
1517
- dune:4
18+
1619
[1]

0 commit comments

Comments
 (0)