Jbuilder: use a jbuild template for compiling protocols

The template is located in `lib_protocol_compiler` so it is be
updated whenever the `tezos-protocol-compiler` is updated.
This commit is contained in:
Grégoire Henry 2017-12-05 15:16:34 +01:00 committed by Benjamin Canou
parent da87aaadc5
commit c7729a07f7
13 changed files with 209 additions and 284 deletions

View File

@ -50,10 +50,32 @@ let encoding =
(req "expected_env_version" env_version_encoding)
(req "components" (list component_encoding)))
let pp fmt op =
Format.pp_print_string fmt @@
let pp ppf op =
Format.pp_print_string ppf @@
Data_encoding_ezjsonm.to_string (Data_encoding.Json.construct encoding op)
let env_version_to_string = function
| V1 -> "V1"
let pp_ocaml_component ppf { name ; interface ; implementation } =
Format.fprintf ppf
"@[{@[<v 1> name = %S ;@ interface = %a ;@ implementation = %S ;@]@ }@]"
name
(fun ppf -> function
| None -> Format.fprintf ppf "None"
| Some s -> Format.fprintf ppf "Some %S" s)
interface
implementation
let pp_ocaml ppf { expected_env ; components } =
Format.fprintf ppf
"@[{@[<v 1> expected_env = %s ;@ components = [@[<v>%a@]] ;@]@ }@]"
(env_version_to_string expected_env)
(Format.pp_print_list
~pp_sep:(fun ppf () -> Format.fprintf ppf " ;@ ")
pp_ocaml_component)
components
let compare = Pervasives.compare
let equal = (=)

View File

@ -23,6 +23,8 @@ and env_version = V1
val component_encoding: component Data_encoding.t
val env_version_encoding: env_version Data_encoding.t
val pp_ocaml: Format.formatter -> t -> unit
include S.HASHABLE with type t := t
and type hash := Protocol_hash.t
val of_bytes_exn: MBytes.t -> t

View File

@ -1,40 +0,0 @@
(jbuild_version 1)
;; Build a functorized version of the protocol with the `tezos-protocol-compiler`
;; This is bit hackish...
;;
;; AFAIK the current version of jbuilder (1.0+beta16) does not allow to compile
;; with a custom `rule` the `(modules)` of a library.
;;
;; A trick is to provide the `.cmx` through the `(library_flags)` and to generate
;; a empty `.ml` to correctly handle the dependencies...
(rule
((targets (tezos_protocol_alpha.o
tezos_protocol_alpha.cmx
tezos_protocol_alpha.cmi
tezos_protocol_alpha_dummy.ml))
(deps ((glob_files src/*.ml)
(glob_files src/*.mli)
src/TEZOS_PROTOCOL))
(action (with-stdout-to ${path-no-dep:tezos_protocol_alpha_dummy.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_alpha} ${path-no-dep:src}))))))
(library
((name tezos_protocol_alpha)
(public_name tezos-protocol-alpha)
(library_flags (:standard -linkall
lib_embedded_protocol_alpha/tezos_protocol_alpha.cmx))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_alpha_dummy))))
(alias
((name runtest_sandbox)
(deps (tezos_protocol_alpha.cmx))))
(alias
((name runtest_indent)
(deps ((glob_files src/*.ml) (glob_files src/*.mli)))
(action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${<}))))

View File

@ -0,0 +1 @@
../lib_protocol_compiler/jbuild_protocol_template

View File

@ -1,53 +0,0 @@
(jbuild_version 1)
(rule
((targets (environment.ml))
(action
(write-file ${@}
"include Tezos_node_updater.Tezos_protocol_environment.Make(struct let name = \"alpha\" end)()"))))
(rule
((targets (registerer.ml))
(action
(write-file ${@}
"
let () =
let module Ignored = Tezos_node_shell.State.Register_embedded_protocol
(Tezos_embedded_protocol_environment_alpha.Environment)
(Tezos_embedded_raw_protocol_alpha.Main)
(struct
let hash =
Some (Tezos_crypto.Protocol_hash.of_b58check_exn
\"ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK\")
let sources = Tezos_base.Protocol.{
expected_env = V1 ;
components = [(* FIXME ?? *)] ;
} end) in ()"))))
(library
((name tezos_embedded_protocol_environment_alpha)
(public_name tezos-embedded-protocol-alpha.environment)
(library_flags (:standard -linkall))
(libraries (tezos-node-updater))
(modules (Environment))))
(library
((name tezos_embedded_raw_protocol_alpha)
(public_name tezos-embedded-protocol-alpha.raw)
(libraries (tezos_embedded_protocol_environment_alpha))
(library_flags (:standard -linkall))
(flags (:standard -nopervasives -nostdlib -safe-string
-w +a-4-6-7-9-29-32-40..42-44-45-48
-warn-error -a+8
-open Tezos_embedded_protocol_environment_alpha__Environment
-open Error_monad
-open Hash
-open Tezos_data))
(modules (:standard \ Environment Registerer))))
(library
((name tezos_embedded_protocol_alpha)
(public_name tezos-embedded-protocol-alpha)
(library_flags (:standard -linkall))
(libraries (tezos_embedded_raw_protocol_alpha tezos-node-shell))
(modules (Registerer))))

View File

@ -0,0 +1 @@
../../lib_protocol_compiler/jbuild_embedded_protocol_template

View File

@ -1,40 +0,0 @@
(jbuild_version 1)
;; Build a functorized version of the protocol with the `tezos-protocol-compiler`
;; This is bit hackish...
;;
;; AFAIK the current version of jbuilder (1.0+beta16) does not allow to compile
;; with a custom `rule` the `(modules)` of a library.
;;
;; A trick is to provide the `.cmx` through the `(library_flags)` and to generate
;; a empty `.ml` to correctly handle the dependencies...
(rule
((targets (tezos_protocol_demo.o
tezos_protocol_demo.cmx
tezos_protocol_demo.cmi
tezos_protocol_demo_dummy.ml))
(deps ((glob_files src/*.ml)
(glob_files src/*.mli)
src/TEZOS_PROTOCOL))
(action (with-stdout-to ${path-no-dep:tezos_protocol_demo_dummy.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_demo} ${path-no-dep:src}))))))
(library
((name tezos_protocol_demo)
(public_name tezos-protocol-demo)
(library_flags (:standard -linkall
lib_embedded_protocol_demo/tezos_protocol_demo.cmx))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_demo_dummy))))
(alias
((name runtest_sandbox)
(deps (tezos_protocol_demo.cmx))))
(alias
((name runtest_indent)
(deps ((glob_files src/*.ml) (glob_files src/*.mli)))
(action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${<}))))

View File

@ -0,0 +1 @@
../lib_protocol_compiler/jbuild_protocol_template

View File

@ -1,53 +0,0 @@
(jbuild_version 1)
(rule
((targets (environment.ml))
(action
(write-file ${@}
"include Tezos_node_updater.Tezos_protocol_environment.Make(struct let name = \"demo\" end)()"))))
(rule
((targets (registerer.ml))
(action
(write-file ${@}
"
let () =
let module Ignored = Tezos_node_shell.State.Register_embedded_protocol
(Tezos_embedded_protocol_environment_demo.Environment)
(Tezos_embedded_raw_protocol_demo.Main)
(struct
let hash =
Some (Tezos_crypto.Protocol_hash.of_b58check_exn
\"ProtoDemoDemoDemoDemoDemoDemoDemoDemoDemoDemoD3c8k9\")
let sources = Tezos_base.Protocol.{
expected_env = V1 ;
components = [(* FIXME ?? *)] ;
} end) in ()"))))
(library
((name tezos_embedded_protocol_environment_demo)
(public_name tezos-embedded-protocol-demo.environment)
(library_flags (:standard -linkall))
(libraries (tezos-node-updater))
(modules (Environment))))
(library
((name tezos_embedded_raw_protocol_demo)
(public_name tezos-embedded-protocol-demo.raw)
(libraries (tezos_embedded_protocol_environment_demo))
(library_flags (:standard -linkall))
(flags (:standard -nopervasives -nostdlib -safe-string
-w +a-4-6-7-9-29-32-40..42-44-45-48
-warn-error -a+8
-open Tezos_embedded_protocol_environment_demo__Environment
-open Error_monad
-open Hash
-open Tezos_data))
(modules (:standard \ Environment Registerer))))
(library
((name tezos_embedded_protocol_demo)
(public_name tezos-embedded-protocol-demo)
(library_flags (:standard -linkall))
(libraries (tezos_embedded_raw_protocol_demo tezos-node-shell))
(modules (Registerer))))

View File

@ -0,0 +1 @@
../../lib_protocol_compiler/jbuild_embedded_protocol_template

View File

@ -1,40 +0,0 @@
(jbuild_version 1)
;; Build a functorized version of the protocol with the `tezos-protocol-compiler`
;; This is bit hackish...
;;
;; AFAIK the current version of jbuilder (1.0+beta16) does not allow to compile
;; with a custom `rule` the `(modules)` of a library.
;;
;; A trick is to provide the `.cmx` through the `(library_flags)` and to generate
;; a empty `.ml` to correctly handle the dependencies...
(rule
((targets (tezos_protocol_genesis.o
tezos_protocol_genesis.cmx
tezos_protocol_genesis.cmi
tezos_protocol_genesis_dummy.ml))
(deps ((glob_files src/*.ml)
(glob_files src/*.mli)
src/TEZOS_PROTOCOL))
(action (with-stdout-to ${path-no-dep:tezos_protocol_genesis_dummy.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_genesis} ${path-no-dep:src}))))))
(library
((name tezos_protocol_genesis)
(public_name tezos-protocol-genesis)
(library_flags (:standard -linkall
lib_embedded_protocol_genesis/tezos_protocol_genesis.cmx))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_genesis_dummy))))
(alias
((name runtest_sandbox)
(deps (tezos_protocol_genesis.cmx))))
(alias
((name runtest_indent)
(deps ((glob_files src/*.ml) (glob_files src/*.mli)))
(action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${<}))))

View File

@ -0,0 +1 @@
../lib_protocol_compiler/jbuild_protocol_template

View File

@ -1,53 +0,0 @@
(jbuild_version 1)
(rule
((targets (environment.ml))
(action
(write-file ${@}
"include Tezos_node_updater.Tezos_protocol_environment.Make(struct let name = \"genesis\" end)()"))))
(rule
((targets (registerer.ml))
(action
(write-file ${@}
"
let () =
let module Ignored = Tezos_node_shell.State.Register_embedded_protocol
(Tezos_embedded_protocol_environment_genesis.Environment)
(Tezos_embedded_raw_protocol_genesis.Main)
(struct
let hash =
Some (Tezos_crypto.Protocol_hash.of_b58check_exn
\"ProtoGenesisGenesisGenesisGenesisGenesisGenesk612im\")
let sources = Tezos_base.Protocol.{
expected_env = V1 ;
components = [(* FIXME ?? *)] ;
} end) in ()"))))
(library
((name tezos_embedded_protocol_environment_genesis)
(public_name tezos-embedded-protocol-genesis.environment)
(library_flags (:standard -linkall))
(libraries (tezos-node-updater))
(modules (Environment))))
(library
((name tezos_embedded_raw_protocol_genesis)
(public_name tezos-embedded-protocol-genesis.raw)
(libraries (tezos_embedded_protocol_environment_genesis))
(library_flags (:standard -linkall))
(flags (:standard -nopervasives -nostdlib -safe-string
-w +a-4-6-7-9-29-32-40..42-44-45-48
-warn-error -a+8
-open Tezos_embedded_protocol_environment_genesis__Environment
-open Error_monad
-open Hash
-open Tezos_data))
(modules (:standard \ Environment Registerer))))
(library
((name tezos_embedded_protocol_genesis)
(public_name tezos-embedded-protocol-genesis)
(library_flags (:standard -linkall))
(libraries (tezos_embedded_raw_protocol_genesis tezos-node-shell))
(modules (Registerer))))

View File

@ -0,0 +1 @@
../../lib_protocol_compiler/jbuild_embedded_protocol_template

View File

@ -24,17 +24,30 @@
-safe-string
-opaque
-open Tezos_base__TzPervasives))
(modules (:standard \ Main))))
(modules (:standard \ Main Main_embedded_packer))))
(executable
((name main)
(public_name tezos-protocol-compiler)
(package tezos-protocol-compiler)
(modes (native))
(libraries (tezos-protocol-compiler))
(libraries (tezos_protocol_compiler))
(flags (:standard -linkall))
(modules (Main))))
(executable
((name main_embedded_packer)
(public_name tezos-embedded-protocol-packer)
(modes (native))
(libraries (tezos-base))
(flags (:standard -linkall
-open Tezos_base__TzPervasives))
(modules (Main_embedded_packer))))
(install
((section share)
(files (jbuild_protocol_template
jbuild_embedded_protocol_template))))
(alias
((name runtest_indent)
(deps ((glob_files *.ml) (glob_files *.mli)))

View File

@ -0,0 +1,58 @@
(* -*- tuareg -*- *)
let prefix = "lib_embedded_protocol_"
let dirname = Filename.basename @@ Filename.dirname @@ Sys.getcwd ()
let version =
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
let () = Format.kasprintf Jbuild_plugin.V1.send {|
(jbuild_version 1)
(rule
((targets (environment.ml))
(action
(write-file ${@@}
"include Tezos_node_updater.Tezos_protocol_environment.Make(struct let name = \"%s\" end)()"))))
(rule
((targets (registerer.ml))
(deps (tezos_embedded_protocol_environment_%s.cmxa TEZOS_PROTOCOL))
(action
(with-stdout-to ${@@}
(chdir ${ROOT} (run ${bin:tezos-embedded-protocol-packer} ${path-no-dep:.} "%s"))))))
(library
((name tezos_embedded_protocol_environment_%s)
(public_name tezos-embedded-protocol-%s.environment)
(library_flags (:standard -linkall))
(libraries (tezos-node-updater))
(modules (Environment))))
(library
((name tezos_embedded_raw_protocol_%s)
(public_name tezos-embedded-protocol-%s.raw)
(libraries (tezos_embedded_protocol_environment_%s))
(library_flags (:standard -linkall))
(flags (:standard -nopervasives -nostdlib -safe-string
-w +a-4-6-7-9-29-32-40..42-44-45-48
-warn-error -a+8
-open Tezos_embedded_protocol_environment_%s__Environment
-open Error_monad
-open Hash
-open Tezos_data))
(modules (:standard \ Environment Registerer))))
(library
((name tezos_embedded_protocol_%s)
(public_name tezos-embedded-protocol-%s)
(library_flags (:standard -linkall))
(libraries (tezos_embedded_raw_protocol_%s tezos-node-shell))
(modules (Registerer))))
|}
version version version version version version version version
version version version version

View File

@ -0,0 +1,58 @@
(* -*- tuareg -*- *)
(* Build a functorized version of the protocol with the
`tezos-protocol-compiler` This is bit hackish...
AFAIK the current version of jbuilder (1.0+beta16) does not allow
to compile with a custom `rule` the `(modules)` of a library.
A trick is to provide the `.cmx` through the `(library_flags)` and
to generate a empty `.ml` to correctly handle the dependencies... *)
let prefix = "lib_embedded_protocol_"
let dirname = Filename.basename @@ Sys.getcwd ()
let version =
let x = String.length prefix in
let n = String.length dirname in
if not (n >= x && String.sub dirname 0 x = prefix) then
failwith "unexpected directory name" ;
String.sub dirname x (n - x)
let () = Format.kasprintf Jbuild_plugin.V1.send {|
(jbuild_version 1)
(rule
((targets (tezos_protocol_%s.o
tezos_protocol_%s.cmx
tezos_protocol_%s.cmi
tezos_protocol_%s_dummy.ml))
(deps ((glob_files src/*.ml)
(glob_files src/*.mli)
src/TEZOS_PROTOCOL))
(action (with-stdout-to ${path-no-dep:tezos_protocol_%s_dummy.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler} -static ${path-no-dep:tezos_protocol_%s} ${path-no-dep:src}))))))
(library
((name tezos_protocol_%s)
(public_name tezos-protocol-%s)
(library_flags (:standard -linkall
lib_embedded_protocol_%s/tezos_protocol_%s.cmx))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_%s_dummy))))
(alias
((name runtest_sandbox)
(deps (tezos_protocol_%s.cmx))))
(alias
((name runtest_indent)
(deps ((glob_files src/*.ml) (glob_files src/*.mli)))
(action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${<}))))
|}
version version version version version version version version
version version version version

View File

@ -0,0 +1,35 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2017. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
let srcdir = Sys.argv.(1)
let version = Sys.argv.(2)
let hash, sources = Protocol.read_dir srcdir
let () =
Format.printf {|
module Source = struct
let hash =
Some (Tezos_crypto.Protocol_hash.of_b58check_exn %S)
let sources = Tezos_base.Protocol.%a
end
@.|}
(Protocol_hash.to_b58check hash)
Protocol.pp_ocaml sources
let () =
Format.printf {|
let () =
let module Ignored = Tezos_node_shell.State.Register_embedded_protocol
(Tezos_embedded_protocol_environment_%s.Environment)
(Tezos_embedded_raw_protocol_%s.Main)
(Source) in
()
@.|}
version version

View File

@ -0,0 +1,10 @@
(**************************************************************************)
(* *)
(* Copyright (c) 2014 - 2017. *)
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
(* *)
(* All rights reserved. No warranty, explicit or implicit, provided. *)
(* *)
(**************************************************************************)
(* empty *)