Commit fffe8a71 authored by Jun Furuse's avatar Jun Furuse

Fixed the way to specify the scaml library directory

parent 72e8b080
......@@ -82,3 +82,15 @@ Boo
Note that the values must be constants. Constructors and types can refer to types
defined in other modules, as far as they are already compiled to `.cmi` files.
## Where to find "SCamlib" module
To compile smart contracts, you need to use `SCaml` module which declares the primitives for them. The module `SCaml` is seeked in directories in the following order:
* In the current directory.
* Directories specified by `-I <dir>` option.
* If `--scaml-noscamlib` is not specified:
* Directory specified by the environment variable `SCAMLIB`.
* If `SCAMLIB` is not speicified, directory `` `opam config var prefix`/lib/scaml``.
......@@ -18,26 +18,40 @@ open Tools
module M = Michelson
let init () =
if not !Flags.flags.scaml_noscamlib then begin
(* If --scaml-noscamlib is specified, None.
If SCAMLLIB is specified, SCAMLLIB is chosen.
Otherwise, `opam config var prefix`/lib/scaml is used.
If `opam config var prefix` does not print a directory nor crashes,
scamlc prints out a warning and continues with None
*)
let scamllib =
if !Flags.flags.scaml_noscamlib then None
else
match Sys.getenv "SCAMLIB" with
| dir -> Some dir
| exception Not_found ->
(* exec opam config var prefix *)
let dir = match
match
let open Command in
exec ["opam"; "config"; "var"; "prefix"]
|> stdout
|> wait
|> must_exit_with 0
with
| dir::_ -> String.chop_eols dir ^/ "lib/scaml"
| dir::_ -> Some (String.chop_eols dir ^/ "lib/scaml")
| [] ->
internal_error ~loc:Location.none "Command 'opam config var prefix' answered nothing"
Format.eprintf "Warning: Command 'opam config var prefix' answered [email protected]"; None
| exception (Failure s) ->
internal_error ~loc:Location.none "Command 'opam config var prefix' has failed: %s" s
Format.eprintf "Warning: Command 'opam config var prefix' has failed: %s" s; None
| exception e ->
internal_error ~loc:Location.none "Command 'opam config var prefix' raised an exception: %s" (Printexc.to_string e)
Format.eprintf "Warning: Command 'opam config var prefix' raised an exception: %s" (Printexc.to_string e); None
in
Clflags.include_dirs := !Clflags.include_dirs @ [dir];
(* List.iter (fun s -> prerr_endline @@ "Include: " ^ s) !Clflags.include_dirs *)
end
match scamllib with
| None -> ()
| Some dir -> Clflags.include_dirs := !Clflags.include_dirs @ [dir]
let implementation sourcefile outputprefix _modulename (str, _coercion) =
let parameter, storage, t = Translate.implementation sourcefile str in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment