diff --git a/bootstrap b/bootstrap index 7422f73..461d589 100644 --- a/bootstrap +++ b/bootstrap @@ -24,8 +24,8 @@ main(Args) -> true -> rm("ebin/*.beam"); false -> - case filelib:is_file("ebin/rebar.beam") of - true -> rm("ebin/rebar.beam"); + case filelib:is_file("ebin/npRMain.beam") of + true -> rm("ebin/npRMain.beam"); false -> io:fwrite("No beam files found.~n") end end, @@ -44,7 +44,7 @@ main(Args) -> %% At the same time, their counterparts dict() and digraph() are to be %% deprecated in Erlang 18. namespaced_types option is used to select %% proper type name depending on the OTP version used. - %% Extract the system info of the version of OTP we use to compile rebar + %% Extract the system info of the version of OTP we use to compile npRMain %% NamespacedTypes = %% case is_otp(OtpInfo, "^[0-9]+") of %% true -> {d, namespaced_types}; @@ -53,7 +53,7 @@ main(Args) -> %% Compile all src/*.erl to ebin %% To not accidentally try to compile files like Mac OS X resource forks, - %% we only look for rebar source files that start with a letter. + %% we only look for npRMain source files that start with a letter. Opts = [ DebugFlag, {outdir, "ebin"}, @@ -82,10 +82,10 @@ main(Args) -> %% Add ebin/ to our path true = code:add_path("ebin"), - %% Run rebar compile to do proper .app validation etc. - %% and rebar escriptize to create the rebar script + %% Run npRMain compile to do proper .app validation etc. + %% and npRMain escriptize to create the npRMain script %% RebarArgs = Args -- ["debug"], %% Avoid trying to run 'debug' command - % rebar:main(["compile"] ++ RebarArgs), + % npRMain:main(["compile"] ++ RebarArgs), escriptize(), diff --git a/eNpc b/eNpc index bab264a..61ea55e 100644 Binary files a/eNpc and b/eNpc differ diff --git a/include/rebar.hrl b/include/rebar.hrl index 1b30a11..63952cf 100644 --- a/include/rebar.hrl +++ b/include/rebar.hrl @@ -1,9 +1,9 @@ --define(FAIL, rebarUtils:abort()). --define(ABORT(Str, Args), rebarUtils:abort(Str, Args)). +-define(FAIL, npRUtils:abort()). +-define(ABORT(Str, Args), npRUtils:abort(Str, Args)). --define(INFO(Str, Args), rebar:log(info, Str, Args)). --define(WARN(Str, Args), rebar:log(warn, Str, Args)). --define(ERROR(Str, Args), rebar:log(error, Str, Args)). +-define(INFO(Str, Args), npRMain:log(info, Str, Args)). +-define(WARN(Str, Args), npRMain:log(warn, Str, Args)). +-define(ERROR(Str, Args), npRMain:log(error, Str, Args)). -define(CONSOLE(Str, Args), io:format(Str, Args)). -define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))). diff --git a/src/eNpc.erl b/src/eNpc.erl index 9b94263..1c2abe9 100644 --- a/src/eNpc.erl +++ b/src/eNpc.erl @@ -15,7 +15,7 @@ main(Args) -> {ok, CurDir} = file:get_cwd(), io:format("eNpc cur ~p: ~-18.s, cur pwd:~p ~n", [Args, File, CurDir]), file:set_cwd(File), - rebar:main(Args), + npRMain:main(Args), file:set_cwd(".."); _ -> ignore @@ -25,7 +25,7 @@ main(Args) -> {ok, Files} -> lists:foreach(FunCom, Files); _Err -> - rebar:log(error, "eNpc start compile error ~p ~n", [_Err]) + npRMain:log(error, "eNpc start compile error ~p ~n", [_Err]) end. diff --git a/src/rebarNpCompiler.erl b/src/npRCompiler.erl similarity index 94% rename from src/rebarNpCompiler.erl rename to src/npRCompiler.erl index 65cad53..b09c598 100644 --- a/src/rebarNpCompiler.erl +++ b/src/npRCompiler.erl @@ -1,4 +1,4 @@ --module(rebarNpCompiler). +-module(npRCompiler). -include("rebar.hrl"). @@ -28,7 +28,7 @@ compile(Config, AppFile) -> [] -> ok; Specs -> - SharedEnv = rebarConfig:getEnv(Config, ?MODULE), + SharedEnv = npRConfig:getEnv(Config, ?MODULE), %% Compile each of the sources NewBins = compileSources(Config, Specs, SharedEnv), @@ -52,7 +52,7 @@ compile(Config, AppFile) -> LinkTemplate = selectLinkTemplate(LinkLang, Target), Env = proplists:get_value(env, Opts, SharedEnv), Cmd = expandCommand(LinkTemplate, Env, string:join(Bins, " "), Target), - rebarUtils:sh(Cmd, [{env, Env}]); + npRUtils:sh(Cmd, [{env, Env}]); false -> ?INFO("Skipping relink of ~s\n", [Target]), ok @@ -67,9 +67,9 @@ clean(Config, AppFile) -> Specs -> lists:foreach( fun(#spec{target = Target, objects = Objects}) -> - rebarUtils:deleteEach([Target]), - rebarUtils:deleteEach(Objects), - rebarUtils:deleteEach(portDeps(Objects)) + npRUtils:deleteEach([Target]), + npRUtils:deleteEach(Objects), + npRUtils:deleteEach(portDeps(Objects)) end, Specs) end, ok. @@ -156,8 +156,8 @@ infoHelp(Description) -> %% set REBAR_DEPS_DIR and ERL_LIBS environment variables defaultEnv(Config) -> - BaseDir = rebarUtils:baseDir(Config), - DepsDir0 = rebarConfig:getXconf(Config, deps_dir, "deps"), + BaseDir = npRUtils:baseDir(Config), + DepsDir0 = npRConfig:getXconf(Config, deps_dir, "deps"), DepsDir = filename:dirname(filename:join([BaseDir, DepsDir0, "dummy"])), %% include rebar's DepsDir in ERL_LIBS @@ -185,10 +185,10 @@ setupEnv(Config, ExtraEnv) -> %% Get any port-specific envs; use port_env first and then fallback %% to port_envs for compatibility - RawPortEnv = rebarConfig:getList( + RawPortEnv = npRConfig:getList( Config, port_env, - rebarConfig:getList(Config, port_envs, [])), + npRConfig:getList(Config, port_envs, [])), PortEnv = filterEnv(RawPortEnv, []), Defines = getDefines(Config), @@ -197,7 +197,7 @@ setupEnv(Config, ExtraEnv) -> expandVarsLoop(mergeEachVar(RawEnv, [])). getDefines(Config) -> - RawDefines = rebarConfig:getXconf(Config, defines, []), + RawDefines = npRConfig:getXconf(Config, defines, []), Defines = string:join(["-D" ++ D || D <- RawDefines], " "), [{"ERL_CFLAGS", "$ERL_CFLAGS " ++ Defines}]. @@ -264,7 +264,7 @@ cdbEntry(Src, Cmd, SrcRest) -> string:tokens(Cmd, " ")), " "), - Cwd = rebarUtils:getCwd(), + Cwd = npRUtils:getCwd(), %% If there are more source files, make sure we end the CDB entry %% with a comma. Sep = case SrcRest of @@ -279,10 +279,10 @@ cdbEntry(Src, Cmd, SrcRest) -> [Src, Cwd, CDBCmd, Sep]). execCompiler(Config, Source, Cmd, ShOpts) -> - case rebarUtils:sh(Cmd, ShOpts) of + case npRUtils:sh(Cmd, ShOpts) of {error, {_RC, RawError}} -> AbsSource = - case rebarUtils:processingBaseDir(Config) of + case npRUtils:processingBaseDir(Config) of true -> Source; false -> @@ -337,7 +337,7 @@ needsLink(SoName, NewBins) -> getSpecs(Config, AppFile) -> Specs = - case rebarConfig:getLocal(Config, port_specs, []) of + case npRConfig:getLocal(Config, port_specs, []) of [] -> %% No spec provided. Construct a spec %% from old-school so_name and sources @@ -352,17 +352,17 @@ getSpecs(Config, AppFile) -> portSpecFromLegacy(Config, AppFile) -> %% Get the target from the so_name variable Target = - case rebarConfig:get(Config, so_name, undefined) of + case npRConfig:get(Config, so_name, undefined) of undefined -> %% Generate a sensible default from app file - {_, AppName} = rebarUtils:appName(Config, AppFile), + {_, AppName} = npRUtils:appName(Config, AppFile), filename:join("priv", lists:concat([AppName, "_drv.so"])); AName -> %% Old form is available -- use it filename:join("priv", AName) end, %% Get the list of source files from port_sources - Sources = portSources(rebarConfig:getList(Config, port_sources, ["c_src/*.c"])), + Sources = portSources(npRConfig:getList(Config, port_sources, ["c_src/*.c"])), #spec{ type = targetType(Target), link_lang = cc, @@ -375,9 +375,9 @@ filterPortSpecs(Specs) -> [S || S <- Specs, filterPortSpec(S)]. filterPortSpec({ArchRegex, _, _, _}) -> - rebarUtils:isArch(ArchRegex); + npRUtils:isArch(ArchRegex); filterPortSpec({ArchRegex, _, _}) -> - rebarUtils:isArch(ArchRegex); + npRUtils:isArch(ArchRegex); filterPortSpec({_, _}) -> true. @@ -459,7 +459,7 @@ applyDefaults(Vars, Defaults) -> fun(Key, VarValue, DefaultValue) -> case isExpandable(DefaultValue) of true -> - rebarUtils:expandEnvVariable(DefaultValue, + npRUtils:expandEnvVariable(DefaultValue, Key, VarValue); false -> VarValue @@ -481,10 +481,10 @@ mergeEachVar([{Key, Value} | Rest], Vars) -> error -> %% Nothing yet defined for this key/value. %% Expand any self-references as blank. - rebarUtils:expandEnvVariable(Value, Key, ""); + npRUtils:expandEnvVariable(Value, Key, ""); {ok, Value0} -> %% Use previous definition in expansion - rebarUtils:expandEnvVariable(Value, Key, Value0) + npRUtils:expandEnvVariable(Value, Key, Value0) end, mergeEachVar(Rest, orddict:store(Key, Evalue, Vars)). @@ -537,7 +537,7 @@ expandKeysInValue([Key | Rest], Value, Vars) -> NewValue = case dict:find(Key, Vars) of {ok, KValue} -> - rebarUtils:expandEnvVariable(Value, Key, KValue); + npRUtils:expandEnvVariable(Value, Key, KValue); error -> Value end, @@ -545,8 +545,8 @@ expandKeysInValue([Key | Rest], Value, Vars) -> expandCommand(TmplName, Env, InFiles, OutFile) -> Cmd0 = proplists:get_value(TmplName, Env), - Cmd1 = rebarUtils:expandEnvVariable(Cmd0, "PORT_IN_FILES", InFiles), - rebarUtils:expandEnvVariable(Cmd1, "PORT_OUT_FILE", OutFile). + Cmd1 = npRUtils:expandEnvVariable(Cmd0, "PORT_IN_FILES", InFiles), + npRUtils:expandEnvVariable(Cmd1, "PORT_OUT_FILE", OutFile). %% %% Given a string, determine if it is expandable @@ -564,7 +564,7 @@ isExpandable(InStr) -> filterEnv([], Acc) -> lists:reverse(Acc); filterEnv([{ArchRegex, Key, Value} | Rest], Acc) -> - case rebarUtils:isArch(ArchRegex) of + case npRUtils:isArch(ArchRegex) of true -> filterEnv(Rest, [{Key, Value} | Acc]); false -> @@ -671,8 +671,8 @@ defaultEnv() -> ])}, {"ERL_EI_LIBDIR", lists:concat(["\"", erlInterfaceDir(lib), "\""])}, {"ERL_LDFLAGS", " -L$ERL_EI_LIBDIR -lei"}, - {"ERLANG_ARCH", rebarUtils:wordsize()}, - {"ERLANG_TARGET", rebarUtils:getArch()}, + {"ERLANG_ARCH", npRUtils:wordsize()}, + {"ERLANG_TARGET", npRUtils:getArch()}, {"darwin", "DRV_LDFLAGS", "-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS"}, diff --git a/src/rebarConfig.erl b/src/npRConfig.erl similarity index 96% rename from src/rebarConfig.erl rename to src/npRConfig.erl index 9512880..9ccab08 100644 --- a/src/rebarConfig.erl +++ b/src/npRConfig.erl @@ -1,4 +1,4 @@ --module(rebarConfig). +-module(npRConfig). -include("rebar.hrl"). @@ -39,18 +39,18 @@ -spec baseConfig(config()) -> config(). baseConfig(GlobalConfig) -> - ConfName = rebarConfig:getGlobal(GlobalConfig, config, ?DEFAULT_NAME), + ConfName = npRConfig:getGlobal(GlobalConfig, config, ?DEFAULT_NAME), new(GlobalConfig, ConfName). -spec new() -> config(). new() -> - #config{dir = rebarUtils:getCwd()}. + #config{dir = npRUtils:getCwd()}. -spec new(file:filename() | config()) -> config(). new(ConfigFile) when is_list(ConfigFile) -> case consultFile(ConfigFile) of {ok, Opts} -> - #config{dir = rebarUtils:getCwd(), + #config{dir = npRUtils:getCwd(), opts = Opts}; Other -> ?ABORT("Failed to load ~s: ~p~n", [ConfigFile, Other]) @@ -140,7 +140,7 @@ getXconf(Config, Key, Default) -> -spec new(config(), file:filename()) -> config(). new(ParentConfig, ConfName) -> %% Load terms from rebar.config, if it exists - Dir = rebarUtils:getCwd(), + Dir = npRUtils:getCwd(), ConfigFile = filename:join([Dir, ConfName]), Opts0 = ParentConfig#config.opts, Opts = case consultFile(ConfigFile) of diff --git a/src/rebar.erl b/src/npRMain.erl similarity index 83% rename from src/rebar.erl rename to src/npRMain.erl index dc2dd20..c7ef87c 100644 --- a/src/rebar.erl +++ b/src/npRMain.erl @@ -1,4 +1,4 @@ --module(rebar). +-module(npRMain). -export([ main/1, @@ -26,12 +26,12 @@ main(Args) -> ok -> ok; rebar_abort -> - rebarUtils:delayedHalt(1); + npRUtils:delayedHalt(1); Error -> %% Nothing should percolate up from rebar_core; %% Dump this error to console io:format("Uncaught error in rebar_core: ~p\n", [Error]), - rebarUtils:delayedHalt(1) + npRUtils:delayedHalt(1) end. log(Level, Format, Args) -> @@ -74,13 +74,13 @@ loadRebarApp() -> {error, {already_loaded,eNpc}} -> ok; _ -> - rebarUtils:delayedHalt(1) + npRUtils:delayedHalt(1) end. help(compile) -> - rebarNpCompiler:info(help, compile); + npRCompiler:info(help, compile); help(clean) -> - rebarNpCompiler:info(help, clean); + npRCompiler:info(help, clean); help(Command) -> ?CONSOLE("eNpc no help available for \"~p\"~n", [Command]). @@ -89,17 +89,17 @@ parseArgs([]) -> parseArgs(["-h" | _]) -> usage(), help(compile), - rebarUtils:delayedHalt(0); + npRUtils:delayedHalt(0); parseArgs(["--help" | _]) -> usage(), help(compile), - rebarUtils:delayedHalt(0); + npRUtils:delayedHalt(0); parseArgs(["-v" | _]) -> version(), - rebarUtils:delayedHalt(0); + npRUtils:delayedHalt(0); parseArgs(["--version" | _]) -> version(), - rebarUtils:delayedHalt(0); + npRUtils:delayedHalt(0); parseArgs(["-c", FileName | Rest]) -> {Opts, NonOpts} = parseArgs(Rest), {[{config, FileName} | Opts], NonOpts}; @@ -118,9 +118,9 @@ initConfig({Options, _NonOptArgs}) -> GlobalConfig = case filelib:is_regular(GlobalConfigFile) of true -> - rebarConfig:new(GlobalConfigFile); + npRConfig:new(GlobalConfigFile); false -> - rebarConfig:new() + npRConfig:new() end, %% Set the rebar config to use @@ -129,24 +129,24 @@ initConfig({Options, _NonOptArgs}) -> undefined -> GlobalConfig; Conf -> - rebarConfig:setGlobal(GlobalConfig, config, Conf) + npRConfig:setGlobal(GlobalConfig, config, Conf) end, - BaseConfig = rebarConfig:baseConfig(GlobalConfig1), + BaseConfig = npRConfig:baseConfig(GlobalConfig1), %% Keep track of how many operations we do, so we can detect bad commands - BaseConfig1 = rebarConfig:setXconf(BaseConfig, operations, 0), + BaseConfig1 = npRConfig:setXconf(BaseConfig, operations, 0), %% Initialize vsn cache - rebarUtils:initVsnCache(BaseConfig1). + npRUtils:initVsnCache(BaseConfig1). initConfig_1(BaseConfig) -> %% Determine the location of the rebar executable; important for pulling %% resources out of the escript ScriptName = filename:absname(escript:script_name()), - BaseConfig1 = rebarConfig:setXconf(BaseConfig, escript, ScriptName), + BaseConfig1 = npRConfig:setXconf(BaseConfig, escript, ScriptName), %% Note the top-level directory for reference - AbsCwd = filename:absname(rebarUtils:getCwd()), - rebarConfig:setXconf(BaseConfig1, base_dir, AbsCwd). + AbsCwd = filename:absname(npRUtils:getCwd()), + npRConfig:setXconf(BaseConfig1, base_dir, AbsCwd). runAux(BaseConfig, Commands) -> %% Make sure crypto is running @@ -182,22 +182,22 @@ setupEnvs(Config, Modules) -> lists:foldl( fun(Module, CfgAcc) -> Env = Module:setupEnv(CfgAcc), - rebarConfig:saveEnv(CfgAcc, Module, Env) + npRConfig:saveEnv(CfgAcc, Module, Env) end, Config, Modules). processCommand(compile, Config, AppFile) -> - rebarNpCompiler:compile(Config, AppFile); + npRCompiler:compile(Config, AppFile); processCommand(clean, Config, AppFile) -> - rebarNpCompiler:clean(Config, AppFile); + npRCompiler:clean(Config, AppFile); processCommand(Other, _, _) -> ?CONSOLE("Unknown command: ~s~n", [Other]), - rebarUtils:delayedHalt(1). + npRUtils:delayedHalt(1). saveOptions(Config, {Options, NonOptArgs}) -> GlobalDefines = proplists:get_all_values(defines, Options), - Config1 = rebarConfig:setXconf(Config, defines, GlobalDefines), + Config1 = npRConfig:setXconf(Config, defines, GlobalDefines), filterFlags(Config1, NonOptArgs, []). %% show version information and halt @@ -222,7 +222,7 @@ filterFlags(Config, [Item | Rest], Commands) -> _ -> RawValue end, - Config1 = rebarConfig:setGlobal(Config, Key, Value), + Config1 = npRConfig:setGlobal(Config, Key, Value), filterFlags(Config1, Rest, Commands); Other -> ?CONSOLE("Ignoring command line argument: ~p\n", [Other]), diff --git a/src/rebarUtils.erl b/src/npRUtils.erl similarity index 97% rename from src/rebarUtils.erl rename to src/npRUtils.erl index 0e538dd..0095f2e 100644 --- a/src/rebarUtils.erl +++ b/src/npRUtils.erl @@ -1,4 +1,4 @@ --module(rebarUtils). +-module(npRUtils). -include("rebar.hrl"). @@ -49,7 +49,7 @@ get_system_arch(Arch) -> Arch. isAppDir() -> - isAppDir(rebarUtils:getCwd()). + isAppDir(npRUtils:getCwd()). isAppDir(Dir) -> SrcDir = filename:join([Dir, "src"]), @@ -91,11 +91,11 @@ appName(Config, AppFile) -> loadAppFile(Config, Filename) -> AppFile = {app_file, Filename}, - case rebarConfig:getXconf(Config, {appfile, AppFile}, undefined) of + case npRConfig:getXconf(Config, {appfile, AppFile}, undefined) of undefined -> case consultAppFile(Filename) of {ok, {application, AppName, AppData}} -> - Config1 = rebarConfig:setXconf(Config, + Config1 = npRConfig:setXconf(Config, {appfile, AppFile}, {AppName, AppData}), {ok, Config1, AppName, AppData}; @@ -114,7 +114,7 @@ consultAppFile(Filename) -> true -> file:consult(Filename); false -> - rebarConfig:consultFile(Filename) + npRConfig:consultFile(Filename) end, case Result of {ok, [Term]} -> @@ -188,11 +188,11 @@ initVsnCache(Config) -> initVsnCache(Config, os:getenv("REBAR_VSN_CACHE_FILE")). initVsnCache(Config, false) -> - rebarConfig:setXconf(Config, vsn_cache, dict:new()); + npRConfig:setXconf(Config, vsn_cache, dict:new()); initVsnCache(Config, CacheFile) -> {ok, CacheList} = file:consult(CacheFile), CacheDict = dict:from_list(CacheList), - rebarConfig:setXconf(Config, vsn_cache, CacheDict). + npRConfig:setXconf(Config, vsn_cache, CacheDict). -spec delayedHalt(integer()) -> no_return(). delayedHalt(Code) -> @@ -229,10 +229,10 @@ deleteEach([File | Rest]) -> end. baseDir(Config) -> - rebarConfig:getXconf(Config, base_dir). + npRConfig:getXconf(Config, base_dir). processingBaseDir(Config) -> - Cwd = rebarUtils:getCwd(), + Cwd = npRUtils:getCwd(), processingBaseDir(Config, Cwd). processingBaseDir(Config, Dir) ->