From d8be1aa894fe546d8f98af59831941f47583da0a Mon Sep 17 00:00:00 2001 From: Jeremie Dimino Date: Fri, 2 Jun 2017 15:00:15 +0100 Subject: [PATCH] Add jbuild.mli --- README.md | 8 +- src/jbuild.ml | 42 ++++------ src/jbuild.mli | 222 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 240 insertions(+), 32 deletions(-) create mode 100644 src/jbuild.mli diff --git a/README.md b/README.md index 93dde6e2..5c53029f 100644 --- a/README.md +++ b/README.md @@ -292,10 +292,10 @@ Lwt/Async-like monad, implemented in [src/future.mli](). #### Code flow -- [src/jbuild_types.ml]() contains the internal representation of =jbuild= +- [src/jbuild.mli]() contains the internal representation of `jbuild` files and the parsing code -- [src/jbuild_load.ml]() contains the code to scan a source tree and +- [src/jbuild_load.mli]() contains the code to scan a source tree and build the internal database by reading the =jbuild= files -- [src/gen_rules.ml]() contains all the build rules of Jbuilder -- [src/build_system.ml]() contains a trivial implementation of a Build +- [src/gen_rules.mli]() contains all the build rules of Jbuilder +- [src/build_system.mli]() contains a trivial implementation of a Build system. This is what Jenga will provide when implementing the bridge diff --git a/src/jbuild.ml b/src/jbuild.ml index aeccb240..dc8e60a7 100644 --- a/src/jbuild.ml +++ b/src/jbuild.ml @@ -133,33 +133,21 @@ module Pkgs = struct end -module Raw_string () : sig - type t = private string - val to_string : t -> string +module Pp : sig + type t val of_string : string -> t - val t : t Sexp.Of_sexp.t + val to_string : t -> string + val compare : t -> t -> int end = struct type t = string - let to_string t = t - let of_string t = t - let t = string -end - -module Pp = struct - include Raw_string () let of_string s = assert (not (String.is_prefix s ~prefix:"-")); - of_string s + s - let t sexp = - let s = string sexp in - if String.is_prefix s ~prefix:"-" then - of_sexp_error sexp "flag not allowed here" - else - of_string s + let to_string t = t - let compare : t -> t -> int = Pervasives.compare + let compare = String.compare end module Pp_or_flags = struct @@ -429,7 +417,6 @@ module Buildable = struct ; libraries : Lib_dep.t list ; preprocess : Preprocess_map.t ; preprocessor_deps : Dep_conf.t list - ; lint : Lint.t Per_file.t option ; flags : Ordered_set_lang.t ; ocamlc_flags : Ordered_set_lang.t ; ocamlopt_flags : Ordered_set_lang.t @@ -442,7 +429,7 @@ module Buildable = struct field "preprocessor_deps" (list Dep_conf.t) ~default:[] >>= fun preprocessor_deps -> field_o "lint" (Per_file.t Lint.t) - >>= fun lint -> + >>= fun _lint -> field "modules" (fun s -> Ordered_set_lang.(map (t s)) ~f:String.capitalize_ascii) ~default:Ordered_set_lang.standard >>= fun modules -> @@ -455,7 +442,6 @@ module Buildable = struct return { preprocess ; preprocessor_deps - ; lint ; modules ; libraries ; flags @@ -472,9 +458,9 @@ end module Public_lib = struct type t = - { name : string (* Full public name *) - ; package : Package.t (* Package it is part of *) - ; sub_dir : string option (* Subdirectory inside the installation directory *) + { name : string + ; package : Package.t + ; sub_dir : string option } let public_name_field pkgs = @@ -811,7 +797,7 @@ module Provides = struct ; file : string } - let v1 sexp = +(* let v1 sexp = match sexp with | Atom (_, s) -> { name = s @@ -825,7 +811,7 @@ module Provides = struct ; file } | sexp -> - of_sexp_error sexp "[] or [ (file )] expected" + of_sexp_error sexp "[] or [ (file )] expected"*) end module Alias_conf = struct @@ -923,7 +909,7 @@ module Stanza = struct ; cstr "executable" (Executables.v1_single pkgs @> nil) execs ; cstr "executables" (Executables.v1_multi pkgs @> nil) execs ; cstr "rule" (Rule.v1 @> nil) (fun x -> [Rule x]) - ; cstr "ocamllex" (list string @> nil) (fun x -> rules (Rule.ocamllex_v1 x)) + ; cstr "ocamllex" (list string @> nil) (fun x -> rules (Rule.ocamllex_v1 x)) ; cstr "ocamlyacc" (list string @> nil) (fun x -> rules (Rule.ocamlyacc_v1 x)) ; cstr "menhir" (Menhir.v1 @> nil) (fun x -> rules (Menhir.v1_to_rule x)) ; cstr "install" (Install_conf.v1 pkgs @> nil) (fun x -> [Install x]) diff --git a/src/jbuild.mli b/src/jbuild.mli new file mode 100644 index 00000000..cd749b8d --- /dev/null +++ b/src/jbuild.mli @@ -0,0 +1,222 @@ +(** Representation and parsing of jbuild files *) + +open Import + +module Jbuild_version : sig + type t = V1 + val t : t Sexp.Of_sexp.t + + val latest_stable : t +end + +(** Packages visible in a given directory *) +module Pkgs : sig + type t = + { visible_packages : Package.t String_map.t + ; closest_packages : Package.t list + } + + val empty : t + + val resolve : t -> string -> (Package.t, string) result +end + +(** Ppx preprocessors *) +module Pp : sig + type t + val of_string : string -> t + val to_string : t -> string +end + +module Preprocess : sig + type pps = + { pps : Pp.t list + ; flags : string list + } + + type t = + | No_preprocessing + | Action of Action.Unexpanded.t + | Pps of pps +end + +module Preprocess_map : sig + type t + + (** [find module_name] find the preprocessing specification for a given module *) + val find : string -> t -> Preprocess.t + + val pps : t -> Pp.t list +end + +module Js_of_ocaml : sig + type t = + { flags : Ordered_set_lang.t + ; javascript_files : string list + } +end + +module Lib_dep : sig + type choice = + { required : String_set.t + ; forbidden : String_set.t + ; file : string + } + + type select = + { result_fn : string + ; choices : choice list + ; loc : Loc.t + } + + type t = + | Direct of string + | Select of select + + val to_lib_names : t -> string list + val direct : string -> t +end + +module Lib_deps : sig + type t = Lib_dep.t list +end + +module Dep_conf : sig + type t = + | File of String_with_vars.t + | Alias of String_with_vars.t + | Glob_files of String_with_vars.t + | Files_recursively_in of String_with_vars.t + + val sexp_of_t : t -> Sexp.t +end + +module Buildable : sig + type t = + { modules : Ordered_set_lang.t + ; libraries : Lib_dep.t list + ; preprocess : Preprocess_map.t + ; preprocessor_deps : Dep_conf.t list + ; flags : Ordered_set_lang.t + ; ocamlc_flags : Ordered_set_lang.t + ; ocamlopt_flags : Ordered_set_lang.t + ; js_of_ocaml : Js_of_ocaml.t + } + + (** Preprocessing specification used by all modules or [No_preprocessing] *) + val single_preprocess : t -> Preprocess.t +end + +module Public_lib : sig + type t = + { name : string (** Full public name *) + ; package : Package.t (** Package it is part of *) + ; sub_dir : string option (** Subdirectory inside the installation directory *) + } +end + +module Library : sig + module Kind : sig + type t = + | Normal + | Ppx_deriver + | Ppx_rewriter + end + + type t = + { name : string + ; public : Public_lib.t option + ; synopsis : string option + ; install_c_headers : string list + ; ppx_runtime_libraries : string list + ; modes : Mode.Dict.Set.t + ; kind : Kind.t + ; c_flags : Ordered_set_lang.Unexpanded.t + ; c_names : string list + ; cxx_flags : Ordered_set_lang.Unexpanded.t + ; cxx_names : string list + ; includes : String_with_vars.t list + ; library_flags : String_with_vars.t list + ; c_library_flags : Ordered_set_lang.Unexpanded.t + ; self_build_stubs_archive : string option + ; virtual_deps : string list + ; wrapped : bool + ; optional : bool + ; buildable : Buildable.t + ; dynlink : bool + } + + val has_stubs : t -> bool + val stubs_archive : t -> dir:Path.t -> ext_lib:string -> Path.t + val all_lib_deps : t -> Lib_deps.t +end + +module Install_conf : sig + type file = + { src : string + ; dst : string option + } + + type t = + { section : Install.Section.t + ; files : file list + ; package : Package.t + } +end + +module Executables : sig + type t = + { names : string list + ; link_executables : bool + ; link_flags : string list + ; modes : Mode.Dict.Set.t + ; buildable : Buildable.t + } +end + +module Rule : sig + module Targets : sig + type t = + | Static of string list + | Infer + end + + type t = + { targets : Targets.t + ; deps : Dep_conf.t list + ; action : Action.Unexpanded.t + } +end + +module Provides : sig + type t = + { name : string + ; file : string + } +end + +module Alias_conf : sig + type t = + { name : string + ; deps : Dep_conf.t list + ; action : Action.Unexpanded.t option + ; package : Package.t option + } +end + +module Stanza : sig + type t = + | Library of Library.t + | Executables of Executables.t + | Rule of Rule.t + | Provides of Provides.t + | Install of Install_conf.t + | Alias of Alias_conf.t +end + +module Stanzas : sig + type t = Stanza.t list + + val parse : Pkgs.t -> Sexp.Ast.t list -> t + val lib_names : (_ * _ * t) list -> String_set.t +end