Add a VERSION file at the top level and go from there
This commit is contained in:
parent
4d9d3077ad
commit
f266c5eed8
@ -15,7 +15,7 @@ returns the compiled module in a map which can then be loaded.
|
||||
``` erlang
|
||||
contract_string() = string() | binary()
|
||||
contract_map() = #{bytecode => binary(),
|
||||
compiler_version => string(),
|
||||
compiler_version => binary(),
|
||||
contract_souce => string(),
|
||||
type_info => type_info()}
|
||||
type_info()
|
||||
@ -75,12 +75,12 @@ Types
|
||||
|
||||
Get the type representation of a type declaration.
|
||||
|
||||
#### version() -> Version
|
||||
#### version() -> {ok, Version} | {error, term()}
|
||||
|
||||
Types
|
||||
|
||||
``` erlang
|
||||
Version = integer()
|
||||
Version = binary()
|
||||
```
|
||||
|
||||
Get the current version of the Sophia compiler.
|
||||
|
@ -39,14 +39,24 @@
|
||||
, options/0
|
||||
]).
|
||||
|
||||
-define(COMPILER_VERSION_1, 1).
|
||||
-define(COMPILER_VERSION_2, 2).
|
||||
|
||||
-define(COMPILER_VERSION, ?COMPILER_VERSION_2).
|
||||
|
||||
-spec version() -> pos_integer().
|
||||
-spec version() -> {ok, binary()} | {error, term()}.
|
||||
version() ->
|
||||
?COMPILER_VERSION.
|
||||
case lists:keyfind(aesophia, 1, application:loaded_applications()) of
|
||||
false ->
|
||||
case application:load(aesophia) of
|
||||
ok ->
|
||||
case application:get_key(aesophia, vsn) of
|
||||
{ok, VsnString} ->
|
||||
{ok, list_to_binary(VsnString)};
|
||||
undefined ->
|
||||
{error, failed_to_load_aesophia}
|
||||
end;
|
||||
Err = {error, _} ->
|
||||
Err
|
||||
end;
|
||||
{_App, _Des, VsnString} ->
|
||||
{ok, list_to_binary(VsnString)}
|
||||
end.
|
||||
|
||||
-spec file(string()) -> {ok, map()} | {error, binary()}.
|
||||
file(Filename) ->
|
||||
@ -75,8 +85,9 @@ from_string(ContractString, Options) ->
|
||||
ByteCodeList = to_bytecode(Assembler, Options),
|
||||
ByteCode = << << B:8 >> || B <- ByteCodeList >>,
|
||||
pp_bytecode(ByteCode, Options),
|
||||
{ok, Version} = version(),
|
||||
{ok, #{byte_code => ByteCode,
|
||||
compiler_version => version(),
|
||||
compiler_version => Version,
|
||||
contract_source => ContractString,
|
||||
type_info => TypeInfo
|
||||
}}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{application, aesophia,
|
||||
[{description, "Contract Language for Aethernity"},
|
||||
{vsn, "1.2.0"},
|
||||
{vsn, {cmd, "cat VERSION | tr -d '[:space:]'"}},
|
||||
{registered, []},
|
||||
{applications,
|
||||
[kernel,
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
-define(OPT_SPEC,
|
||||
[ {src_file, undefined, undefined, string, "Sophia source code file"}
|
||||
, {version, $V, "version", undefined, "Print compiler version"}
|
||||
, {verbose, $v, "verbose", undefined, "Verbose output"}
|
||||
, {help, $h, "help", undefined, "Show this message"}
|
||||
, {outfile, $o, "out", string, "Output file (experimental)"} ]).
|
||||
@ -14,11 +15,13 @@ usage() ->
|
||||
main(Args) ->
|
||||
case getopt:parse(?OPT_SPEC, Args) of
|
||||
{ok, {Opts, []}} ->
|
||||
case proplists:get_value(help, Opts, false) of
|
||||
false ->
|
||||
compile(Opts);
|
||||
true ->
|
||||
usage()
|
||||
case Opts of
|
||||
[version] ->
|
||||
print_vsn();
|
||||
[help] ->
|
||||
usage();
|
||||
_ ->
|
||||
compile(Opts)
|
||||
end;
|
||||
|
||||
{ok, {_, NonOpts}} ->
|
||||
@ -69,3 +72,7 @@ write_outfile(Out, ResMap) ->
|
||||
%% Lazy approach
|
||||
file:write_file(Out, term_to_binary(ResMap)),
|
||||
io:format("Output written to: ~s\n", [Out]).
|
||||
|
||||
print_vsn() ->
|
||||
{ok, Vsn} = aeso_compiler:version(),
|
||||
io:format("Compiler version: ~s\n", [Vsn]).
|
||||
|
Loading…
x
Reference in New Issue
Block a user