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
|
``` erlang
|
||||||
contract_string() = string() | binary()
|
contract_string() = string() | binary()
|
||||||
contract_map() = #{bytecode => binary(),
|
contract_map() = #{bytecode => binary(),
|
||||||
compiler_version => string(),
|
compiler_version => binary(),
|
||||||
contract_souce => string(),
|
contract_souce => string(),
|
||||||
type_info => type_info()}
|
type_info => type_info()}
|
||||||
type_info()
|
type_info()
|
||||||
@ -75,12 +75,12 @@ Types
|
|||||||
|
|
||||||
Get the type representation of a type declaration.
|
Get the type representation of a type declaration.
|
||||||
|
|
||||||
#### version() -> Version
|
#### version() -> {ok, Version} | {error, term()}
|
||||||
|
|
||||||
Types
|
Types
|
||||||
|
|
||||||
``` erlang
|
``` erlang
|
||||||
Version = integer()
|
Version = binary()
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the current version of the Sophia compiler.
|
Get the current version of the Sophia compiler.
|
||||||
|
@ -39,14 +39,24 @@
|
|||||||
, options/0
|
, options/0
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(COMPILER_VERSION_1, 1).
|
-spec version() -> {ok, binary()} | {error, term()}.
|
||||||
-define(COMPILER_VERSION_2, 2).
|
|
||||||
|
|
||||||
-define(COMPILER_VERSION, ?COMPILER_VERSION_2).
|
|
||||||
|
|
||||||
-spec version() -> pos_integer().
|
|
||||||
version() ->
|
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()}.
|
-spec file(string()) -> {ok, map()} | {error, binary()}.
|
||||||
file(Filename) ->
|
file(Filename) ->
|
||||||
@ -75,8 +85,9 @@ from_string(ContractString, Options) ->
|
|||||||
ByteCodeList = to_bytecode(Assembler, Options),
|
ByteCodeList = to_bytecode(Assembler, Options),
|
||||||
ByteCode = << << B:8 >> || B <- ByteCodeList >>,
|
ByteCode = << << B:8 >> || B <- ByteCodeList >>,
|
||||||
pp_bytecode(ByteCode, Options),
|
pp_bytecode(ByteCode, Options),
|
||||||
|
{ok, Version} = version(),
|
||||||
{ok, #{byte_code => ByteCode,
|
{ok, #{byte_code => ByteCode,
|
||||||
compiler_version => version(),
|
compiler_version => Version,
|
||||||
contract_source => ContractString,
|
contract_source => ContractString,
|
||||||
type_info => TypeInfo
|
type_info => TypeInfo
|
||||||
}}
|
}}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{application, aesophia,
|
{application, aesophia,
|
||||||
[{description, "Contract Language for Aethernity"},
|
[{description, "Contract Language for Aethernity"},
|
||||||
{vsn, "1.2.0"},
|
{vsn, {cmd, "cat VERSION | tr -d '[:space:]'"}},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications,
|
{applications,
|
||||||
[kernel,
|
[kernel,
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
-define(OPT_SPEC,
|
-define(OPT_SPEC,
|
||||||
[ {src_file, undefined, undefined, string, "Sophia source code file"}
|
[ {src_file, undefined, undefined, string, "Sophia source code file"}
|
||||||
|
, {version, $V, "version", undefined, "Print compiler version"}
|
||||||
, {verbose, $v, "verbose", undefined, "Verbose output"}
|
, {verbose, $v, "verbose", undefined, "Verbose output"}
|
||||||
, {help, $h, "help", undefined, "Show this message"}
|
, {help, $h, "help", undefined, "Show this message"}
|
||||||
, {outfile, $o, "out", string, "Output file (experimental)"} ]).
|
, {outfile, $o, "out", string, "Output file (experimental)"} ]).
|
||||||
@ -14,11 +15,13 @@ usage() ->
|
|||||||
main(Args) ->
|
main(Args) ->
|
||||||
case getopt:parse(?OPT_SPEC, Args) of
|
case getopt:parse(?OPT_SPEC, Args) of
|
||||||
{ok, {Opts, []}} ->
|
{ok, {Opts, []}} ->
|
||||||
case proplists:get_value(help, Opts, false) of
|
case Opts of
|
||||||
false ->
|
[version] ->
|
||||||
compile(Opts);
|
print_vsn();
|
||||||
true ->
|
[help] ->
|
||||||
usage()
|
usage();
|
||||||
|
_ ->
|
||||||
|
compile(Opts)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ok, {_, NonOpts}} ->
|
{ok, {_, NonOpts}} ->
|
||||||
@ -69,3 +72,7 @@ write_outfile(Out, ResMap) ->
|
|||||||
%% Lazy approach
|
%% Lazy approach
|
||||||
file:write_file(Out, term_to_binary(ResMap)),
|
file:write_file(Out, term_to_binary(ResMap)),
|
||||||
io:format("Output written to: ~s\n", [Out]).
|
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