Keep the package context after parsing

This commit is contained in:
Jeremie Dimino 2017-05-05 11:21:46 +01:00
parent fbe0810156
commit ef6be544a3
10 changed files with 38 additions and 40 deletions

View File

@ -450,7 +450,7 @@ let external_lib_deps =
(Build_system.all_lib_deps_by_context setup.build_system targets) (Build_system.all_lib_deps_by_context setup.build_system targets)
~f:(fun ~key:context_name ~data:lib_deps acc -> ~f:(fun ~key:context_name ~data:lib_deps acc ->
let internals = let internals =
Jbuild_types.Stanza.lib_names Jbuild_types.Stanzas.lib_names
(match String_map.find context_name setup.Main.stanzas with (match String_map.find context_name setup.Main.stanzas with
| None -> assert false | None -> assert false
| Some x -> x) | Some x -> x)

View File

@ -576,7 +576,7 @@ module Gen(P : Params) = struct
| Stanza | | Stanza |
+-----------------------------------------------------------------+ *) +-----------------------------------------------------------------+ *)
let rules { SC.Dir_with_jbuild. src_dir; ctx_dir; stanzas } = let rules { SC.Dir_with_jbuild. src_dir; ctx_dir; stanzas; pkgs = _ } =
(* Interpret user rules and other simple stanzas first in order to populate the known (* Interpret user rules and other simple stanzas first in order to populate the known
target table, which is needed for guessing the list of modules. *) target table, which is needed for guessing the list of modules. *)
List.iter stanzas ~f:(fun stanza -> List.iter stanzas ~f:(fun stanza ->
@ -907,8 +907,9 @@ let gen ~contexts ?(filter_out_optional_stanzas_with_missing_deps=true)
match only_packages with match only_packages with
| None -> stanzas | None -> stanzas
| Some pkgs -> | Some pkgs ->
List.map stanzas ~f:(fun (dir, stanzas) -> List.map stanzas ~f:(fun (dir, pkgs_ctx, stanzas) ->
(dir, (dir,
pkgs_ctx,
List.filter stanzas ~f:(fun stanza -> List.filter stanzas ~f:(fun stanza ->
match (stanza : Stanza.t) with match (stanza : Stanza.t) with
| Library { public = Some { package; _ }; _ } | Library { public = Some { package; _ }; _ }

View File

@ -1,4 +1,5 @@
open! Import open! Import
open Jbuild_types
val gen val gen
: contexts:Context.t list : contexts:Context.t list
@ -7,4 +8,4 @@ val gen
-> Jbuild_load.conf -> Jbuild_load.conf
-> (Build_interpret.Rule.t list * -> (Build_interpret.Rule.t list *
(* Evaluated jbuilds per context names *) (* Evaluated jbuilds per context names *)
(Path.t * Jbuild_types.Stanzas.t) list String_map.t) Future.t (Path.t * Pkgs.t * Stanzas.t) list String_map.t) Future.t

View File

@ -3,13 +3,12 @@ open Jbuild_types
module Jbuilds = struct module Jbuilds = struct
type script = type script =
{ dir : Path.t { dir : Path.t
; visible_packages : Package.t String_map.t ; pkgs : Pkgs.t
; closest_packages : Package.t list
} }
type one = type one =
| Literal of Path.t * Stanza.t list | Literal of (Path.t * Pkgs.t * Stanza.t list)
| Script of script | Script of script
type t = one list type t = one list
@ -66,12 +65,8 @@ end
let eval jbuilds ~(context : Context.t) = let eval jbuilds ~(context : Context.t) =
let open Future in let open Future in
List.map jbuilds ~f:(function List.map jbuilds ~f:(function
| Literal (path, stanzas) -> | Literal x -> return x
return (path, stanzas) | Script { dir; pkgs = pkgs_ctx } ->
| Script { dir
; visible_packages
; closest_packages
} ->
let file = Path.relative dir "jbuild" in let file = Path.relative dir "jbuild" in
let generated_jbuild = let generated_jbuild =
Path.append (Path.relative generated_jbuilds_dir context.name) file Path.append (Path.relative generated_jbuilds_dir context.name) file
@ -123,7 +118,7 @@ end
Did you forgot to call [Jbuild_plugin.V*.send]?" Did you forgot to call [Jbuild_plugin.V*.send]?"
(Path.to_string file); (Path.to_string file);
let sexps = Sexp_load.many (Path.to_string generated_jbuild) in let sexps = Sexp_load.many (Path.to_string generated_jbuild) in
return (dir, Stanzas.parse sexps ~visible_packages ~closest_packages)) return (dir, pkgs_ctx, Stanzas.parse pkgs_ctx sexps))
|> Future.all |> Future.all
end end
@ -136,15 +131,12 @@ type conf =
let load ~dir ~visible_packages ~closest_packages = let load ~dir ~visible_packages ~closest_packages =
let file = Path.relative dir "jbuild" in let file = Path.relative dir "jbuild" in
let pkgs = { Pkgs. visible_packages; closest_packages } in
match Sexp_load.many_or_ocaml_script (Path.to_string file) with match Sexp_load.many_or_ocaml_script (Path.to_string file) with
| Sexps sexps -> | Sexps sexps ->
Jbuilds.Literal (dir, Stanzas.parse sexps ~visible_packages ~closest_packages) Jbuilds.Literal (dir, pkgs, Stanzas.parse pkgs sexps)
| Ocaml_script -> | Ocaml_script ->
Script Script { dir; pkgs }
{ dir
; visible_packages
; closest_packages
}
let load ?(extra_ignored_subtrees=Path.Set.empty) () = let load ?(extra_ignored_subtrees=Path.Set.empty) () =
let ftree = File_tree.load Path.root in let ftree = File_tree.load Path.root in

View File

@ -1,9 +1,10 @@
open Import open Import
open Jbuild_types
module Jbuilds : sig module Jbuilds : sig
type t type t
val eval : t -> context:Context.t -> (Path.t * Jbuild_types.Stanzas.t) list Future.t val eval : t -> context:Context.t -> (Path.t * Pkgs.t * Stanzas.t) list Future.t
end end
type conf = type conf =

View File

@ -862,22 +862,12 @@ module Stanza = struct
let select : Jbuild_version.t -> Pkgs.t -> t list Sexp.Of_sexp.t = function let select : Jbuild_version.t -> Pkgs.t -> t list Sexp.Of_sexp.t = function
| V1 -> v1 | V1 -> v1
| Vjs -> v1 | Vjs -> v1
let lib_names ts =
List.fold_left ts ~init:String_set.empty ~f:(fun acc (_, stanzas) ->
List.fold_left stanzas ~init:acc ~f:(fun acc -> function
| Library lib ->
String_set.add lib.name
(match lib.public with
| None -> acc
| Some { name; _ } -> String_set.add name acc)
| _ -> acc))
end end
module Stanzas = struct module Stanzas = struct
type t = Stanza.t list type t = Stanza.t list
let parse sexps ~visible_packages ~closest_packages = let parse pkgs sexps =
let versions, sexps = let versions, sexps =
List.partition_map sexps ~f:(function List.partition_map sexps ~f:(function
| List (loc, [Atom (_, "jbuild_version"); ver]) -> | List (loc, [Atom (_, "jbuild_version"); ver]) ->
@ -891,6 +881,15 @@ module Stanzas = struct
| _ :: (_, loc) :: _ -> | _ :: (_, loc) :: _ ->
Loc.fail loc "jbuild_version specified too many times" Loc.fail loc "jbuild_version specified too many times"
in in
let pkgs = { Pkgs. visible_packages; closest_packages } in
List.concat_map sexps ~f:(Stanza.select version pkgs) List.concat_map sexps ~f:(Stanza.select version pkgs)
let lib_names ts =
List.fold_left ts ~init:String_set.empty ~f:(fun acc (_, _, stanzas) ->
List.fold_left stanzas ~init:acc ~f:(fun acc -> function
| Stanza.Library lib ->
String_set.add lib.name
(match lib.public with
| None -> acc
| Some { name; _ } -> String_set.add name acc)
| _ -> acc))
end end

View File

@ -3,7 +3,7 @@ open Future
type setup = type setup =
{ build_system : Build_system.t { build_system : Build_system.t
; stanzas : (Path.t * Jbuild_types.Stanzas.t) list String_map.t ; stanzas : (Path.t * Jbuild_types.Pkgs.t * Jbuild_types.Stanzas.t) list String_map.t
; contexts : Context.t list ; contexts : Context.t list
; packages : Package.t String_map.t ; packages : Package.t String_map.t
} }
@ -69,7 +69,7 @@ let external_lib_deps ?log ~packages () =
match String_map.find "default" setup.stanzas with match String_map.find "default" setup.stanzas with
| None -> die "You need to set a default context to use external-lib-deps" | None -> die "You need to set a default context to use external-lib-deps"
| Some stanzas -> | Some stanzas ->
let internals = Jbuild_types.Stanza.lib_names stanzas in let internals = Jbuild_types.Stanzas.lib_names stanzas in
Path.Map.map Path.Map.map
(Build_system.all_lib_deps setup.build_system install_files) (Build_system.all_lib_deps setup.build_system install_files)
~f:(String_map.filter ~f:(fun name _ -> ~f:(String_map.filter ~f:(fun name _ ->

View File

@ -1,9 +1,10 @@
open! Import open! Import
open Jbuild_types
type setup = type setup =
{ build_system : Build_system.t { build_system : Build_system.t
; (* Evaluated jbuilds per context names *) ; (* Evaluated jbuilds per context names *)
stanzas : (Path.t * Jbuild_types.Stanzas.t) list String_map.t stanzas : (Path.t * Pkgs.t * Stanzas.t) list String_map.t
; contexts : Context.t list ; contexts : Context.t list
; packages : Package.t String_map.t ; packages : Package.t String_map.t
} }

View File

@ -6,6 +6,7 @@ module Dir_with_jbuild = struct
{ src_dir : Path.t { src_dir : Path.t
; ctx_dir : Path.t ; ctx_dir : Path.t
; stanzas : Stanzas.t ; stanzas : Stanzas.t
; pkgs : Pkgs.t
} }
end end
@ -60,11 +61,12 @@ let create
= =
let stanzas = let stanzas =
List.map stanzas List.map stanzas
~f:(fun (dir, stanzas) -> ~f:(fun (dir, pkgs, stanzas) ->
{ Dir_with_jbuild. { Dir_with_jbuild.
src_dir = dir src_dir = dir
; ctx_dir = Path.append context.build_dir dir ; ctx_dir = Path.append context.build_dir dir
; stanzas ; stanzas
; pkgs
}) })
in in
let internal_libraries = let internal_libraries =

View File

@ -14,6 +14,7 @@ module Dir_with_jbuild : sig
{ src_dir : Path.t { src_dir : Path.t
; ctx_dir : Path.t (** [_build/context-name/src_dir] *) ; ctx_dir : Path.t (** [_build/context-name/src_dir] *)
; stanzas : Stanzas.t ; stanzas : Stanzas.t
; pkgs : Pkgs.t
} }
end end
@ -25,7 +26,7 @@ val create
-> dirs_with_dot_opam_files:Path.Set.t -> dirs_with_dot_opam_files:Path.Set.t
-> file_tree:File_tree.t -> file_tree:File_tree.t
-> packages:Package.t String_map.t -> packages:Package.t String_map.t
-> stanzas:(Path.t * Stanzas.t) list -> stanzas:(Path.t * Pkgs.t * Stanzas.t) list
-> filter_out_optional_stanzas_with_missing_deps:bool -> filter_out_optional_stanzas_with_missing_deps:bool
-> t -> t