ligo/src/lib_protocol_compiler/jbuild_protocol_template

123 lines
3.5 KiB
Plaintext
Raw Normal View History

(* -*- 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... *)
2018-01-27 14:21:41 +04:00
#require "unix"
let prefix = "proto_"
let dirname = Filename.basename @@ Filename.dirname @@ Sys.getcwd ()
let predefined_version = None (* to be substituted in opam packages *)
let version =
match predefined_version with
| Some version -> version
| None ->
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 path =
match predefined_version with
| None -> "src/proto_" ^ version ^ "/lib_protocol"
| Some _ -> "."
2018-01-27 14:21:41 +04:00
let sources =
let d = Unix.opendir "src" in
let rec loop acc =
match Unix.readdir d with
| exception End_of_file ->
Unix.closedir d ;
acc
| file ->
let acc =
if Filename.check_suffix file ".mli"
|| Filename.check_suffix file ".ml" then
("src/" ^ file) :: acc
else
acc
in
loop acc in
loop []
let () = Format.kasprintf Jbuild_plugin.V1.send {|
(jbuild_version 1)
2018-01-30 19:30:22 +04:00
(rule
((targets (tezos_protocol_%s.cmo
2018-02-22 10:01:30 +04:00
tezos_protocol_%s.cmi
2018-01-30 19:30:22 +04:00
tezos_protocol_%s_dummy_byte.ml))
(deps ((glob_files src/*.ml*)
2018-01-30 19:30:22 +04:00
src/TEZOS_PROTOCOL))
2018-02-22 10:01:30 +04:00
(locks (tezos_protocol_%s.cmi))
2018-01-30 19:30:22 +04:00
(action (with-stdout-to ${path-no-dep:tezos_protocol_%s_dummy_byte.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler-byte} -static -output-dep ${path-no-dep:tezos_protocol_%s} ${path-no-dep:src}))))))
2018-01-30 19:30:22 +04:00
(rule
((targets (tezos_protocol_%s.o
tezos_protocol_%s.cmx
tezos_protocol_%s_dummy.ml))
(deps ((glob_files src/*.ml)
(glob_files src/*.mli)
src/TEZOS_PROTOCOL))
2018-02-22 10:01:30 +04:00
(locks (tezos_protocol_%s.cmi))
(action (with-stdout-to ${path-no-dep:tezos_protocol_%s_dummy.ml}
(chdir ${ROOT}
(run ${bin:tezos-protocol-compiler} -static -output-dep ${path-no-dep:tezos_protocol_%s} ${path-no-dep:src}))))))
(library
((name tezos_protocol_%s)
(public_name tezos-protocol-%s)
(library_flags (:standard -linkall %s/tezos_protocol_%s.cmx))
2017-12-11 19:36:24 +04:00
(flags (:standard -safe-string))
(wrapped false)
(modes (native))
(modules (Tezos_protocol_%s_dummy))))
2018-01-30 19:30:22 +04:00
(library
((name tezos_protocol_%s_byte)
(public_name tezos-protocol-%s.byte)
(library_flags (:standard -linkall %s/tezos_protocol_%s.cmo))
(flags (:standard -safe-string))
(wrapped false)
(modes (byte))
(modules (Tezos_protocol_%s_dummy_byte))))
(install
((section lib)
(files ("tezos_protocol_%s.cmx" "tezos_protocol_%s.cmi"))
(package tezos-protocol-%s)))
(alias
((name runtest_sandbox)
(deps (tezos_protocol_%s.cmx))))
(alias
((name runtest_indent)
2018-01-27 14:21:41 +04:00
(deps (@[<v>%a@]))
(action (run bash ${libexec:tezos-stdlib:test-ocp-indent.sh} ${^}))))
|}
2018-01-30 19:30:22 +04:00
version version version version
version version version version
version version version version
2018-02-22 10:01:30 +04:00
version version
2018-01-30 19:30:22 +04:00
path version
version version version
path version
version version version
version version
2018-01-27 14:21:41 +04:00
Format.(pp_print_list (fun ppf -> Format.fprintf ppf "%S"))
sources