Skip to content

Commit

Permalink
Add proper error checking for duplicate stub usage
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Jan 31, 2019
1 parent a951b6a commit fa5ada2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/c_sources.ml
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,22 @@ let make (d : _ Dir_with_dune.t)
in this directory"
Lib_name.pp_quoted name
in
let () =
let rev_map =
List.concat_map libs ~f:(fun (_, c_sources) ->
String.Map.values c_sources
|> List.map ~f:(fun (loc, source) ->
(C.Source.path source, loc)))
|> Path.Map.of_list
in
match rev_map with
| Ok _ -> ()
| Error (_, loc1, loc2) ->
Errors.fail loc2
"This c stub is already used in another stanza:@\n\
@[<v>%a@]@\n"
(Fmt.prefix (Fmt.string "- ") Loc.pp_file_colon_line)
loc1
in
{ libraries
}
7 changes: 5 additions & 2 deletions test/blackbox-tests/test-cases/duplicate-c-cxx/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ c_names and cxx_names with overlapping names in the same stanza
c_names with overlapping names in different stanzas
$ dune build --root diff-stanza @all
Entering directory 'diff-stanza'
Multiple rules generated for _build/default/foo$ext_obj:
- dune:9
File "dune", line 9, characters 10-13:
9 | (c_names foo))
^^^
Error: This c stub is already used in another stanza:
- dune:4

[1]

0 comments on commit fa5ada2

Please sign in to comment.