Keep the package context after parsing
This commit is contained in:
parent
fbe0810156
commit
ef6be544a3
|
@ -450,7 +450,7 @@ let external_lib_deps =
|
|||
(Build_system.all_lib_deps_by_context setup.build_system targets)
|
||||
~f:(fun ~key:context_name ~data:lib_deps acc ->
|
||||
let internals =
|
||||
Jbuild_types.Stanza.lib_names
|
||||
Jbuild_types.Stanzas.lib_names
|
||||
(match String_map.find context_name setup.Main.stanzas with
|
||||
| None -> assert false
|
||||
| Some x -> x)
|
||||
|
|
|
@ -576,7 +576,7 @@ module Gen(P : Params) = struct
|
|||
| 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
|
||||
target table, which is needed for guessing the list of modules. *)
|
||||
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
|
||||
| None -> stanzas
|
||||
| Some pkgs ->
|
||||
List.map stanzas ~f:(fun (dir, stanzas) ->
|
||||
List.map stanzas ~f:(fun (dir, pkgs_ctx, stanzas) ->
|
||||
(dir,
|
||||
pkgs_ctx,
|
||||
List.filter stanzas ~f:(fun stanza ->
|
||||
match (stanza : Stanza.t) with
|
||||
| Library { public = Some { package; _ }; _ }
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
open! Import
|
||||
open Jbuild_types
|
||||
|
||||
val gen
|
||||
: contexts:Context.t list
|
||||
|
@ -7,4 +8,4 @@ val gen
|
|||
-> Jbuild_load.conf
|
||||
-> (Build_interpret.Rule.t list *
|
||||
(* 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
|
||||
|
|
|
@ -4,12 +4,11 @@ open Jbuild_types
|
|||
module Jbuilds = struct
|
||||
type script =
|
||||
{ dir : Path.t
|
||||
; visible_packages : Package.t String_map.t
|
||||
; closest_packages : Package.t list
|
||||
; pkgs : Pkgs.t
|
||||
}
|
||||
|
||||
type one =
|
||||
| Literal of Path.t * Stanza.t list
|
||||
| Literal of (Path.t * Pkgs.t * Stanza.t list)
|
||||
| Script of script
|
||||
|
||||
type t = one list
|
||||
|
@ -66,12 +65,8 @@ end
|
|||
let eval jbuilds ~(context : Context.t) =
|
||||
let open Future in
|
||||
List.map jbuilds ~f:(function
|
||||
| Literal (path, stanzas) ->
|
||||
return (path, stanzas)
|
||||
| Script { dir
|
||||
; visible_packages
|
||||
; closest_packages
|
||||
} ->
|
||||
| Literal x -> return x
|
||||
| Script { dir; pkgs = pkgs_ctx } ->
|
||||
let file = Path.relative dir "jbuild" in
|
||||
let generated_jbuild =
|
||||
Path.append (Path.relative generated_jbuilds_dir context.name) file
|
||||
|
@ -123,7 +118,7 @@ end
|
|||
Did you forgot to call [Jbuild_plugin.V*.send]?"
|
||||
(Path.to_string file);
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -136,15 +131,12 @@ type conf =
|
|||
|
||||
let load ~dir ~visible_packages ~closest_packages =
|
||||
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
|
||||
| Sexps sexps ->
|
||||
Jbuilds.Literal (dir, Stanzas.parse sexps ~visible_packages ~closest_packages)
|
||||
Jbuilds.Literal (dir, pkgs, Stanzas.parse pkgs sexps)
|
||||
| Ocaml_script ->
|
||||
Script
|
||||
{ dir
|
||||
; visible_packages
|
||||
; closest_packages
|
||||
}
|
||||
Script { dir; pkgs }
|
||||
|
||||
let load ?(extra_ignored_subtrees=Path.Set.empty) () =
|
||||
let ftree = File_tree.load Path.root in
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
open Import
|
||||
open Jbuild_types
|
||||
|
||||
module Jbuilds : sig
|
||||
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
|
||||
|
||||
type conf =
|
||||
|
|
|
@ -862,22 +862,12 @@ module Stanza = struct
|
|||
let select : Jbuild_version.t -> Pkgs.t -> t list Sexp.Of_sexp.t = function
|
||||
| V1 -> 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
|
||||
|
||||
module Stanzas = struct
|
||||
type t = Stanza.t list
|
||||
|
||||
let parse sexps ~visible_packages ~closest_packages =
|
||||
let parse pkgs sexps =
|
||||
let versions, sexps =
|
||||
List.partition_map sexps ~f:(function
|
||||
| List (loc, [Atom (_, "jbuild_version"); ver]) ->
|
||||
|
@ -891,6 +881,15 @@ module Stanzas = struct
|
|||
| _ :: (_, loc) :: _ ->
|
||||
Loc.fail loc "jbuild_version specified too many times"
|
||||
in
|
||||
let pkgs = { Pkgs. visible_packages; closest_packages } in
|
||||
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
|
||||
|
|
|
@ -3,7 +3,7 @@ open Future
|
|||
|
||||
type setup =
|
||||
{ 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
|
||||
; packages : Package.t String_map.t
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ let external_lib_deps ?log ~packages () =
|
|||
match String_map.find "default" setup.stanzas with
|
||||
| None -> die "You need to set a default context to use external-lib-deps"
|
||||
| Some stanzas ->
|
||||
let internals = Jbuild_types.Stanza.lib_names stanzas in
|
||||
let internals = Jbuild_types.Stanzas.lib_names stanzas in
|
||||
Path.Map.map
|
||||
(Build_system.all_lib_deps setup.build_system install_files)
|
||||
~f:(String_map.filter ~f:(fun name _ ->
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
open! Import
|
||||
open Jbuild_types
|
||||
|
||||
type setup =
|
||||
{ build_system : Build_system.t
|
||||
; (* 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
|
||||
; packages : Package.t String_map.t
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ module Dir_with_jbuild = struct
|
|||
{ src_dir : Path.t
|
||||
; ctx_dir : Path.t
|
||||
; stanzas : Stanzas.t
|
||||
; pkgs : Pkgs.t
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -60,11 +61,12 @@ let create
|
|||
=
|
||||
let stanzas =
|
||||
List.map stanzas
|
||||
~f:(fun (dir, stanzas) ->
|
||||
~f:(fun (dir, pkgs, stanzas) ->
|
||||
{ Dir_with_jbuild.
|
||||
src_dir = dir
|
||||
; ctx_dir = Path.append context.build_dir dir
|
||||
; stanzas
|
||||
; pkgs
|
||||
})
|
||||
in
|
||||
let internal_libraries =
|
||||
|
|
|
@ -14,6 +14,7 @@ module Dir_with_jbuild : sig
|
|||
{ src_dir : Path.t
|
||||
; ctx_dir : Path.t (** [_build/context-name/src_dir] *)
|
||||
; stanzas : Stanzas.t
|
||||
; pkgs : Pkgs.t
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -25,7 +26,7 @@ val create
|
|||
-> dirs_with_dot_opam_files:Path.Set.t
|
||||
-> file_tree:File_tree.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
|
||||
-> t
|
||||
|
||||
|
|
Loading…
Reference in New Issue