-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of C_sources for include_subdirs
Signed-off-by: Rudi Grinberg <[email protected]>
- Loading branch information
Showing
15 changed files
with
234 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
open Stdune | ||
|
||
module Kind = struct | ||
type t = | ||
| C | ||
| Cxx | ||
|
||
let pp fmt t : unit = | ||
match t with | ||
| C -> Format.pp_print_string fmt "c" | ||
| Cxx -> Format.pp_print_string fmt "cpp" | ||
|
||
let split_fn fn = | ||
match String.lsplit2 fn ~on:'.' with | ||
| Some (obj, "c") -> Some (obj, C) | ||
| Some (obj, "cpp") -> Some (obj, Cxx) | ||
| _ -> None | ||
|
||
let possible_fns t fn = | ||
match t with | ||
| C -> [fn ^ ".c"] | ||
| Cxx -> [fn ^ ".cpp"] | ||
|
||
module Dict = struct | ||
type 'a t = | ||
{ c : 'a | ||
; cxx : 'a | ||
} | ||
|
||
let make a = | ||
{ c = a | ||
; cxx = a | ||
} | ||
|
||
let get { c; cxx } = function | ||
| C -> c | ||
| Cxx -> cxx | ||
|
||
let add t k v = | ||
match k with | ||
| C -> { t with c = v } | ||
| Cxx -> { t with cxx = v } | ||
|
||
let update t k ~f = | ||
let v = get t k in | ||
add t k (f v) | ||
|
||
let merge t1 t2 ~f = | ||
{ c = f t1.c t2.c | ||
; cxx = f t1.cxx t2.cxx | ||
} | ||
end | ||
end | ||
|
||
module Source = struct | ||
type t = | ||
{ kind : Kind.t | ||
; path : Path.t | ||
} | ||
|
||
let kind t = t.kind | ||
let path t = t.path | ||
let src_dir t = Path.parent_exn t.path | ||
|
||
let make ~kind ~path = | ||
{ kind | ||
; path | ||
} | ||
end | ||
|
||
module Sources = struct | ||
type t = (Loc.t * Source.t) String.Map.t | ||
|
||
let foreign_objects (t : t) ~dir ~ext_obj = | ||
String.Map.keys t | ||
|> List.map ~f:(fun c -> Path.relative dir (c ^ ext_obj)) | ||
|
||
let split_by_kind t = | ||
let (c, cxx) = | ||
String.Map.partition t ~f:(fun (_, s) -> | ||
match (Source.kind s : Kind.t) with | ||
| C -> true | ||
| Cxx -> false) | ||
in | ||
{Kind.Dict. c; cxx} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open Stdune | ||
|
||
module Kind : sig | ||
type t = | ||
| C | ||
| Cxx | ||
|
||
val pp : t Fmt.t | ||
|
||
val split_fn : string -> (string * t) option | ||
|
||
val possible_fns : t -> string -> string list | ||
|
||
module Dict : sig | ||
type kind | ||
type 'a t = | ||
{ c : 'a | ||
; cxx : 'a | ||
} | ||
|
||
val make : 'a -> 'a t | ||
|
||
val update : 'a t -> kind -> f:('a -> 'a) -> 'a t | ||
|
||
val merge : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t | ||
end with type kind := t | ||
end | ||
|
||
module Source : sig | ||
type t | ||
|
||
val kind : t -> Kind.t | ||
val path : t -> Path.t | ||
val src_dir : t -> Path.t | ||
|
||
val make : kind:Kind.t -> path:Path.t -> t | ||
end | ||
|
||
module Sources : sig | ||
type t = (Loc.t * Source.t) String.Map.t | ||
|
||
val foreign_objects : t -> dir:Path.t -> ext_obj:string -> Path.t list | ||
|
||
val split_by_kind : t -> t Kind.Dict.t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
open Stdune | ||
|
||
module Files : sig | ||
type 'a t = | ||
{ c : 'a | ||
; cxx : 'a | ||
} | ||
|
||
val make : files:String.Set.t -> String.Set.t t | ||
|
||
val foreign_objects | ||
: (Loc.t * Path.t) String.Map.t t | ||
-> dir:Path.t | ||
-> ext_obj:string | ||
-> Path.t list | ||
end | ||
|
||
type t | ||
|
||
val empty : t | ||
|
||
val for_lib : t -> dir:Path.t -> name:Lib_name.t -> (Loc.t * Path.t) String.Map.t Files.t | ||
val for_lib : t -> dir:Path.t -> name:Lib_name.t -> C.Sources.t | ||
|
||
val load_sources | ||
: dir:Path.t | ||
-> files:String.Set.t | ||
-> C.Source.t String.Map.t C.Kind.Dict.t | ||
|
||
val make | ||
: Stanza.t list Dir_with_dune.t | ||
-> c_files:String.Set.t Files.t | ||
-> c_sources:C.Source.t String.Map.t C.Kind.Dict.t | ||
-> t |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.