Skip to content

Commit

Permalink
Replace meta language by ocaml
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiedimino committed Feb 26, 2017
1 parent 8d52cba commit 38421d7
Show file tree
Hide file tree
Showing 24 changed files with 263 additions and 347 deletions.
57 changes: 32 additions & 25 deletions doc/jbuild
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
(use_meta_lang)
(* -*- tuareg -*- *)

open StdLabels

let commands =
[ "build"
; "build-package"
; "external-lib-deps"
; "install"
; "installed-libraries"
; "runtest"
; "uninstall"
]

let jbuild =
String.concat ~sep:""
({|
(jbuild_version 1)

(install
((section doc)
(files (manual.org))))

(:let :commands
(build
build-package
external-lib-deps
install
installed-libraries
runtest
uninstall))

(:let-macro (:man-file :cmd)
(:concat "" (jbuilder- (:cmd) .1)))

(rule
((targets (jbuilder.1))
(action (with-stdout-to ${@}
(run ${bin:jbuilder} --help=groff)))))

(:foreach :cmd (:commands)
(rule
((targets ((:man-file (:cmd))))
(action (with-stdout-to ${@}
(run ${bin:jbuilder} (:cmd) --help=groff))))))

|} :: List.map commands ~f:(fun cmd ->
Printf.sprintf {|
(rule
((targets (jbuilder-%s.1))
(action (with-stdout-to ${@}
(run ${bin:jbuilder} %s --help=groff)))))
|} cmd cmd)
@ [ Printf.sprintf {|
(install
((section man)
(files (
jbuilder.1
(:foreach :cmd (:commands) (:man-file (:cmd)))
%s
))))
|} (String.concat ~sep:"\n "
(List.map commands ~f:(Printf.sprintf "jbuilder-%s.1")))
])

(alias
((name runtest)
(deps (jbuild))
(action (run ${bin:cinaps} ${<}))))
let () =
Jbuild_plugin.V1.send jbuild
14 changes: 5 additions & 9 deletions doc/manual.org
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,8 @@ publication of Jane Street packages easier.

Except for the special =jane_street= version, there is currently only
one version available, but to be future proof, you should still
specify it in your toplevel =jbuild= file. If no version is specified,
the latest one will be used. Specifying a version in a =jbuild= file
will affect the current file as well as the sub-tree where it is
defined. As a result it is recommended to specify the version in the
toplevel jbuild file of your project.
specify it in your =jbuild= files. If no version is specified, the
latest one will be used.

** Metadata format

Expand Down Expand Up @@ -208,11 +205,10 @@ everything Jbuilder needs to know about.
The following sections describe the available stanzas and their
meaning.

**** jbuilder_version
**** jbuid_verrsion

=(jbuilder_version 1)= specifies that we are using the version 1 of
the Jbuilder metadata format in this =jbuild= file and the sub-tree
starting from this directory.
=(jbuild_version 1)= specifies that we are using the version 1 of the
Jbuilder metadata format in this =jbuild= file.

**** library

Expand Down
1 change: 0 additions & 1 deletion jbuild

This file was deleted.

17 changes: 17 additions & 0 deletions plugin/jbuild_plugin.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
(** API for jbuild plugins *)

module V1 : sig
(** Current build context *)
val context : string

(** OCaml version for the current buid context. It might not be the
same as [Sys.ocaml_version] *)
val ocaml_version : string

(** Output of [ocamlc -config] for this context *)
val ocamlc_config : (string * string) list

(** [send s] send [s] to jbuilder. [s] should be the contents of a
jbuild file following the specification described in the manual. *)
val send : string -> unit
end
2 changes: 2 additions & 0 deletions src/context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type t =
; findlib_path : Path.t list
; arch_sixtyfour : bool
; opam_var_cache : (string, string) Hashtbl.t
; ocamlc_config : (string * string) list
; version : string
; stdlib_dir : Path.t
; ccomp_type : string
Expand Down Expand Up @@ -187,6 +188,7 @@ let create ~(kind : Kind.t) ~path ~env ~name =
; opam_var_cache

; stdlib_dir
; ocamlc_config = String_map.bindings ocamlc_config
; version = get "version"
; ccomp_type = get "ccomp_type"
; bytecomp_c_compiler = get "bytecomp_c_compiler"
Expand Down
3 changes: 2 additions & 1 deletion src/context.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ type t =
; opam_var_cache : (string, string) Hashtbl.t

; (** Output of [ocamlc -config] *)
version : string
ocamlc_config : (string * string) list
; version : string
; stdlib_dir : Path.t
; ccomp_type : string
; bytecomp_c_compiler : string
Expand Down
35 changes: 18 additions & 17 deletions src/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1779,23 +1779,24 @@ module Gen(P : Params) = struct
end

let gen ~contexts ?(filter_out_optional_stanzas_with_missing_deps=true) conf =
let open Future in
let { Jbuild_load. file_tree; tree; jbuilds; packages } = conf in
let alias_store = Alias.Store.create () in
let rules =
List.concat_map contexts ~f:(fun context ->
let stanzas = List.map jbuilds ~f:(Jbuild_load.Jbuild.eval ~context) in
let module M =
Gen(struct
let context = context
let file_tree = file_tree
let stanzas = stanzas
let packages = packages
let filter_out_optional_stanzas_with_missing_deps =
filter_out_optional_stanzas_with_missing_deps
let alias_store = alias_store
end)
in
!M.all_rules)
in
List.map contexts ~f:(fun context ->
Jbuild_load.Jbuilds.eval ~context jbuilds >>| fun stanzas ->
let module M =
Gen(struct
let context = context
let file_tree = file_tree
let stanzas = stanzas
let packages = packages
let filter_out_optional_stanzas_with_missing_deps =
filter_out_optional_stanzas_with_missing_deps
let alias_store = alias_store
end)
in
!M.all_rules)
|> Future.all
>>| fun rules ->
Alias.rules alias_store ~prefixes:(Path.root :: List.map contexts ~f:(fun c -> c.Context.build_dir)) ~tree
@ rules
@ List.concat rules
2 changes: 1 addition & 1 deletion src/gen_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ val gen
: contexts:Context.t list
-> ?filter_out_optional_stanzas_with_missing_deps:bool (** default: true *)
-> Jbuild_load.conf
-> Build_interpret.Rule.t list
-> Build_interpret.Rule.t list Future.t
10 changes: 10 additions & 0 deletions src/import.ml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ module Hashtbl = struct
match find t key with
| exception Not_found -> None
| x -> Some x

let find_or_add t key ~f =
match find t key with
| Some x -> x
| None ->
let x = f () in
add t ~key ~data:x;
x
end

module Map = struct
Expand Down Expand Up @@ -314,6 +322,8 @@ let read_file fn =

let lines_of_file fn = with_file_in fn ~f:input_lines

let write_file fn data = with_file_out fn ~f:(fun oc -> output_string oc data)

exception Fatal_error of string
let die fmt = ksprintf (fun msg -> raise (Fatal_error msg)) fmt

Expand Down
7 changes: 3 additions & 4 deletions src/jbuild
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
;; This program must have no dependencies outside of the compiler
;; distribution as it is used to build all of Jane Street packages
(jbuild_version 1)

(library
((name jbuilder)
(public_name jbuilder)
(libraries (unix jbuilder_re))
(preprocess no_preprocessing)))
(libraries (unix jbuilder_re))))

(ocamllex (sexp_lexer meta_lexer rewrite_generated_file glob_lexer))
Loading

0 comments on commit 38421d7

Please sign in to comment.