Browse Source

重命令为 eNpc

master
SisMaker 4 years ago
parent
commit
1780cc26b6
9 changed files with 34 additions and 29 deletions
  1. +1
    -0
      .gitignore
  2. +4
    -4
      README.md
  3. +9
    -9
      bootstrap
  4. BIN
      eNpc
  5. +4
    -0
      eNpc.cmd
  6. +3
    -3
      ebin/eNpc.app
  7. +4
    -4
      src/eNpc.erl
  8. +7
    -7
      src/rebar.erl
  9. +2
    -2
      src/rebarUtils.erl

+ 1
- 0
.gitignore View File

@ -17,4 +17,5 @@ _build/
_checkouts/ _checkouts/
.idea .idea
*.iml

+ 4
- 4
README.md View File

@ -7,12 +7,12 @@
default_env default_env
1. Clone this repository 1. Clone this repository
1. Run `make` in this directory 1. Run `make` in this directory
1. Copy `erlNpc` to your project "c_src" dir and commit it
1. Copy `eNpc` to your project "c_src" dir and commit it
1. Add these (or similar) hooks to your rebar.config: 1. Add these (or similar) hooks to your rebar.config:
```erlang ```erlang
{pre_hooks, [{"", compile, "escript c_src/erlNpc compile"}]}.
{post_hooks, [{"", clean, "escript c_src/erlNpc clean"}]}.
{pre_hooks, [{"", compile, "escript c_src/eNpc compile"}]}.
{post_hooks, [{"", clean, "escript c_src/eNpc clean"}]}.
``` ```
After that erlNpc should read your old rebar.config `port\_specs` and `port\_env` settings as expected (it is rebar2's port compiler after all...).
After that eNpc should read your old rebar.config `port_specs` and `port_env` settings as expected (it is rebar2's port compiler after all...).

+ 9
- 9
bootstrap View File

@ -66,16 +66,16 @@ main(Args) ->
up_to_date -> up_to_date ->
ok; ok;
error -> error ->
io:format("Failed to compile erlNpc files!\n"),
io:format("Failed to compile eNpc files!\n"),
halt(1) halt(1)
end, end,
%% Make sure file:consult can parse the .app file %% Make sure file:consult can parse the .app file
case file:consult("ebin/erlNpc.app") of
case file:consult("ebin/eNpc.app") of
{ok, _} -> {ok, _} ->
ok; ok;
{error, Reason} -> {error, Reason} ->
io:format("Invalid syntax in ebin/erlNpc.app: ~p\n", [Reason]),
io:format("Invalid syntax in ebin/eNpc.app: ~p\n", [Reason]),
halt(1) halt(1)
end, end,
@ -93,7 +93,7 @@ main(Args) ->
%% or write out script files on win32. %% or write out script files on win32.
case os:type() of case os:type() of
{unix, _} -> {unix, _} ->
[] = os:cmd("chmod u+x erlNpc"),
[] = os:cmd("chmod u+x eNpc"),
ok; ok;
{win32, _} -> {win32, _} ->
writeWindowsScripts(), writeWindowsScripts(),
@ -104,10 +104,10 @@ main(Args) ->
%% Add a helpful message %% Add a helpful message
io:format(<<"Congratulations! You now have a self-contained script called" io:format(<<"Congratulations! You now have a self-contained script called"
" \"erlNpc\" in\n"
" \"eNpc\" in\n"
"your current working directory. " "your current working directory. "
"Place this script anywhere in your path\n" "Place this script anywhere in your path\n"
"and you can use erlNpc to build native code for Erlang\n">>).
"and you can use eNpc to build native code for Erlang\n">>).
usage() -> usage() ->
io:format(<<"Usage: bootstrap [OPTION]...~n">>), io:format(<<"Usage: bootstrap [OPTION]...~n">>),
@ -157,12 +157,12 @@ writeWindowsScripts() ->
"setlocal\r\n" "setlocal\r\n"
"set rebarscript=%~f0\r\n" "set rebarscript=%~f0\r\n"
"escript.exe \"%rebarscript:.cmd=%\" %*\r\n", "escript.exe \"%rebarscript:.cmd=%\" %*\r\n",
ok = file:write_file("erlNpc.cmd", CmdScript).
ok = file:write_file("eNpc.cmd", CmdScript).
escriptize() -> escriptize() ->
AppName = "erlNpc",
ScriptName = "erlNpc",
AppName = "eNpc",
ScriptName = "eNpc",
Files = loadEScriptFiles(AppName, "ebin", "*"), Files = loadEScriptFiles(AppName, "ebin", "*"),

BIN
eNpc View File


+ 4
- 0
eNpc.cmd View File

@ -0,0 +1,4 @@
@echo off
setlocal
set rebarscript=%~f0
escript.exe "%rebarscript:.cmd=%" %*

ebin/erlNpc.app → ebin/eNpc.app View File

@ -1,9 +1,9 @@
{application,erlNpc,
[{description,"erlNpc: Erlang Native Compiler"},
{application,eNpc,
[{description,"eNpc: Erlang Native Compiler"},
{vsn,"0.1.0"}, {vsn,"0.1.0"},
{registered,[]}, {registered,[]},
{applications,[kernel,stdlib]}, {applications,[kernel,stdlib]},
{modules,[erlNpc,rebar,rebarConfig,rebarNpCompiler,rebarUtils]},
{modules,[eNpc,rebar,rebarConfig,rebarNpCompiler,rebarUtils]},
{licenses,["Apache 2.0"]}, {licenses,["Apache 2.0"]},
{links,[]}, {links,[]},
{env,[{log_level,warn}]}]}. {env,[{log_level,warn}]}]}.

src/erlNpc.erl → src/eNpc.erl View File

@ -1,4 +1,4 @@
-module(erlNpc).
-module(eNpc).
-export([ -export([
main/1 main/1
@ -7,13 +7,13 @@
main(Args) -> main(Args) ->
file:set_cwd("c_src"), file:set_cwd("c_src"),
{ok, Dir} = file:get_cwd(), {ok, Dir} = file:get_cwd(),
io:format("erlNpc begin compile pwd:~15.p ~n", [Dir]),
io:format("eNpc begin compile pwd:~15.p ~n", [Dir]),
FunCom = FunCom =
fun(File) -> fun(File) ->
case filelib:is_dir(File) == true andalso lists:nth(1, File) =/= 46 andalso filename:basename(File) =/= "include" of case filelib:is_dir(File) == true andalso lists:nth(1, File) =/= 46 andalso filename:basename(File) =/= "include" of
true -> true ->
{ok, CurDir} = file:get_cwd(), {ok, CurDir} = file:get_cwd(),
io:format("erlNpc cur ~p: ~-18.s, cur pwd:~p ~n", [Args, File, CurDir]),
io:format("eNpc cur ~p: ~-18.s, cur pwd:~p ~n", [Args, File, CurDir]),
file:set_cwd(File), file:set_cwd(File),
rebar:main(Args), rebar:main(Args),
file:set_cwd(".."); file:set_cwd("..");
@ -25,7 +25,7 @@ main(Args) ->
{ok, Files} -> {ok, Files} ->
lists:foreach(FunCom, Files); lists:foreach(FunCom, Files);
_Err -> _Err ->
rebar:log(error, "erlNpc start compile error ~p ~n", [_Err])
rebar:log(error, "eNpc start compile error ~p ~n", [_Err])
end. end.

+ 7
- 7
src/rebar.erl View File

@ -35,7 +35,7 @@ main(Args) ->
end. end.
log(Level, Format, Args) -> log(Level, Format, Args) ->
{ok, LimitLevel} = application:get_env(erlNpc, log_level),
{ok, LimitLevel} = application:get_env(eNpc, log_level),
case levelInt(LimitLevel) >= levelInt(Level) of case levelInt(LimitLevel) >= levelInt(Level) of
true -> true ->
io:format(destination(Level), Format, Args); io:format(destination(Level), Format, Args);
@ -68,10 +68,10 @@ run(RawArgs) ->
loadRebarApp() -> loadRebarApp() ->
%% Pre-load the rebar app so that we get default configuration %% Pre-load the rebar app so that we get default configuration
case application:load(erlNpc) of
case application:load(eNpc) of
ok -> ok ->
ok; ok;
{error, {already_loaded,erlNpc}} ->
{error, {already_loaded,eNpc}} ->
ok; ok;
_ -> _ ->
rebarUtils:delayedHalt(1) rebarUtils:delayedHalt(1)
@ -82,7 +82,7 @@ help(compile) ->
help(clean) -> help(clean) ->
rebarNpCompiler:info(help, clean); rebarNpCompiler:info(help, clean);
help(Command) -> help(Command) ->
?CONSOLE("erlNpc no help available for \"~p\"~n", [Command]).
?CONSOLE("eNpc no help available for \"~p\"~n", [Command]).
parseArgs([]) -> parseArgs([]) ->
{[], []}; {[], []};
@ -110,7 +110,7 @@ parseArgs([NonOpt | Rest]) ->
{Opts, [NonOpt | NonOpts]}. {Opts, [NonOpt | NonOpts]}.
usage() -> usage() ->
?CONSOLE("erlNpc [-hv] [-c CONFIG_FILE] COMMAND [COMMAND ...]~n~n", []).
?CONSOLE("eNpc [-hv] [-c CONFIG_FILE] COMMAND [COMMAND ...]~n~n", []).
initConfig({Options, _NonOptArgs}) -> initConfig({Options, _NonOptArgs}) ->
%% If $HOME/.rebar/config exists load and use as global config %% If $HOME/.rebar/config exists load and use as global config
@ -202,8 +202,8 @@ saveOptions(Config, {Options, NonOptArgs}) ->
%% show version information and halt %% show version information and halt
version() -> version() ->
{ok, Vsn} = application:get_key(erlNpc, vsn),
?CONSOLE("erlNpc ~s ~s ~s ~s\n", [Vsn, ?OTP_INFO, ?BUILD_TIME, ?VCS_INFO]).
{ok, Vsn} = application:get_key(eNpc, vsn),
?CONSOLE("eNpc ~s ~s ~s ~s\n", [Vsn, ?OTP_INFO, ?BUILD_TIME, ?VCS_INFO]).
%% Seperate all commands (single-words) from flags (key=value) and store %% Seperate all commands (single-words) from flags (key=value) and store
%% values into the rebar_config global storage. %% values into the rebar_config global storage.

+ 2
- 2
src/rebarUtils.erl View File

@ -240,12 +240,12 @@ processingBaseDir(Config, Dir) ->
AbsDir =:= baseDir(Config). AbsDir =:= baseDir(Config).
otpRelease() -> otpRelease() ->
case application:get_env(erlNpc, memoized_otp_release) of
case application:get_env(eNpc, memoized_otp_release) of
{ok, Return} -> {ok, Return} ->
Return; Return;
undefined -> undefined ->
Return = otpRelease_1(erlang:system_info(otp_release)), Return = otpRelease_1(erlang:system_info(otp_release)),
application:set_env(erlNpc, memoized_otp_release, Return),
application:set_env(eNpc, memoized_otp_release, Return),
Return Return
end. end.

Loading…
Cancel
Save