diff --git a/.travis.yml b/.travis.yml index 5dae2f4..6490e13 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,7 @@ otp_release: - R14B04 - R14B03 - R14B02 -script: "make" +script: "make rebuild" branches: only: - master - - next diff --git a/Makefile b/Makefile index e05f06a..47acb32 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,49 @@ # BSD License see COPYING ERL = $(shell which erl) -ERL_VER = $(shell erl -eval 'erlang:display(erlang:system_info(otp_release)), halt().' -noshell) +ERL_VER = $(shell erl -eval 'io:format("~s", [erlang:system_info(otp_release)]), halt().' -noshell) +ERLWARE_COMMONS_PLT=$(CURDIR)/.erlware_commons_plt ERLFLAGS= -pa $(CURDIR)/.eunit -pa $(CURDIR)/ebin -pa $(CURDIR)/*/ebin +# ============================================================================= +# Verify that the programs we need to run are installed on this system +# ============================================================================= + REBAR=$(shell which rebar) ifeq ($(REBAR),) $(error "Rebar not available on this system") endif -ERLWARE_COMMONS_PLT=$(CURDIR)/.erlware_commons_plt +# ============================================================================= +# Handle version discovery +# ============================================================================= + +# We have a problem that we only have 10 minutes to build on travis +# and those travis boxes are quite small. This is ok for the fast +# dialyzer on R15 and above. However on R14 and below we have the +# problem that travis times out. The code below lets us not run +# dialyzer on R14 +OTP_VSN=$(shell erl -noshell -eval 'io:format("~p", [erlang:system_info(otp_release)]), erlang:halt(0).' | perl -lne 'print for /R(\d+).*/g') +TRAVIS_SLOW=$(shell expr $(OTP_VSN) \<= 15 ) + +ifeq ($(TRAVIS_SLOW), 0) +DIALYZER=$(shell which dialyzer) +else +DIALYZER=: not running dialyzer on R14 or R15 +endif + +# ============================================================================= +# Rules to build the system +# ============================================================================= .PHONY: all compile doc clean test shell distclean pdf get-deps rebuild dialyzer typer all: compile doc test +rebuild: distclean deps compile dialyzer test + deps: .DEV_MODE $(REBAR) get-deps compile @@ -43,29 +70,29 @@ $(ERLWARE_COMMONS_PLT).$(ERL_VER).erts: @echo Building local plt at $(ERLWARE_COMMONS_PLT).$(ERL_VER).base @echo - - dialyzer --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base --build_plt \ + - $(DIALYZER) --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).erts --build_plt \ --apps erts $(ERLWARE_COMMONS_PLT).$(ERL_VER).kernel:$(ERLWARE_COMMONS_PLT).$(ERL_VER).erts @echo Building local plt at $(ERLWARE_COMMONS_PLT).$(ERL_VER).base @echo - - dialyzer --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base --build_plt \ + - $(DIALYZER) --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).kernel --build_plt \ --apps kernel $(ERLWARE_COMMONS_PLT).$(ERL_VER).base:$(ERLWARE_COMMONS_PLT).$(ERL_VER).kernel @echo Building local plt at $(ERLWARE_COMMONS_PLT).$(ERL_VER).base @echo - - dialyzer --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base --build_plt \ + - $(DIALYZER) --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base --build_plt \ --apps stdlib $(ERLWARE_COMMONS_PLT).$(ERL_VER): $(ERLWARE_COMMONS_PLT).$(ERL_VER).base @echo Building local plt at $(ERLWARE_COMMONS_PLT).$(ERL_VER) @echo - - dialyzer --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER) --add_to_plt --plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base \ + - $(DIALYZER) --fullpath --verbose --output_plt $(ERLWARE_COMMONS_PLT).$(ERL_VER) --add_to_plt --plt $(ERLWARE_COMMONS_PLT).$(ERL_VER).base \ --apps eunit -r deps -dialyzer: $(ERLWARE_COMMONS_PLT).$(ERL_VER) - dialyzer --fullpath --plt $(ERLWARE_COMMONS_PLT).$(ERL_VER) -Wrace_conditions -r ./ebin +dialyzer: compile $(ERLWARE_COMMONS_PLT).$(ERL_VER) + $(DIALYZER) --fullpath --plt $(ERLWARE_COMMONS_PLT).$(ERL_VER) -Wrace_conditions -r ./ebin typer: $(ERLWARE_COMMONS_PLT).$(ERL_VER) typer --plt $(ERLWARE_COMMONS_PLT).$(ERL_VER) -r ./src @@ -90,5 +117,3 @@ distclean: clean rm -rf $(ERLWARE_COMMONS_PLT).$(ERL_VER) rm -rvf $(CURDIR)/deps rm -rvf .DEV_MODE - -rebuild: distclean all diff --git a/src/ec_cmd_log.erl b/src/ec_cmd_log.erl index 4038eee..42250e6 100644 --- a/src/ec_cmd_log.erl +++ b/src/ec_cmd_log.erl @@ -49,9 +49,8 @@ -define(PREFIX, "===> "). --record(state_t, {mod=?MODULE :: ec_log, - log_level=0 :: int_log_level(), - caller=api :: api | command_line}). +-record(state_t, {log_level=0 :: int_log_level(), + caller=api :: caller()}). %%============================================================================ %% types @@ -60,8 +59,11 @@ int_log_level/0, atom_log_level/0, log_level/0, + caller/0, log_fun/0]). +-type caller() :: api | command_line. + -type log_level() :: int_log_level() | atom_log_level(). -type int_log_level() :: 0..3. @@ -82,8 +84,9 @@ new(LogLevel) -> new(LogLevel, api). +-spec new(log_level(), caller()) -> t(). new(LogLevel, Caller) when LogLevel >= 0, LogLevel =< 3 -> - #state_t{mod=?MODULE, log_level=LogLevel, caller=Caller}; + #state_t{log_level=LogLevel, caller=Caller}; new(AtomLogLevel, Caller) when AtomLogLevel =:= error; AtomLogLevel =:= warn; @@ -165,7 +168,7 @@ warn(LogState, FormatString, Args) -> %% @doc Execute the fun passed in if log level is as expected. -spec log(t(), int_log_level(), log_fun()) -> ok. -log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, Fun) +log(#state_t{log_level=DetailLogLevel}, LogLevel, Fun) when DetailLogLevel >= LogLevel -> io:format("~s~n", [Fun()]); log(_, _, _) -> @@ -174,7 +177,7 @@ log(_, _, _) -> %% @doc when the module log level is less then or equal to the log level for the %% call then write the log info out. When its not then ignore the call. -spec log(t(), int_log_level(), string(), [any()]) -> ok. -log(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel, FormatString, Args) +log(#state_t{log_level=DetailLogLevel}, LogLevel, FormatString, Args) when DetailLogLevel >= LogLevel, erlang:is_list(Args) -> io:format(FormatString, Args); @@ -184,7 +187,7 @@ log(_, _, _, _) -> %% @doc return a boolean indicating if the system should log for the specified %% levelg -spec should(t(), int_log_level() | any()) -> boolean(). -should(#state_t{mod=?MODULE, log_level=DetailLogLevel}, LogLevel) +should(#state_t{log_level=DetailLogLevel}, LogLevel) when DetailLogLevel >= LogLevel -> true; should(_, _) -> @@ -192,18 +195,18 @@ should(_, _) -> %% @doc get the current log level as an integer -spec log_level(t()) -> int_log_level(). -log_level(#state_t{mod=?MODULE, log_level=DetailLogLevel}) -> +log_level(#state_t{log_level=DetailLogLevel}) -> DetailLogLevel. %% @doc get the current log level as an atom -spec atom_log_level(t()) -> atom_log_level(). -atom_log_level(#state_t{mod=?MODULE, log_level=?EC_ERROR}) -> +atom_log_level(#state_t{log_level=?EC_ERROR}) -> error; -atom_log_level(#state_t{mod=?MODULE, log_level=?EC_WARN}) -> +atom_log_level(#state_t{log_level=?EC_WARN}) -> warn; -atom_log_level(#state_t{mod=?MODULE, log_level=?EC_INFO}) -> +atom_log_level(#state_t{log_level=?EC_INFO}) -> info; -atom_log_level(#state_t{mod=?MODULE, log_level=?EC_DEBUG}) -> +atom_log_level(#state_t{log_level=?EC_DEBUG}) -> debug. -spec format(t()) -> iolist(). diff --git a/src/ec_file.erl b/src/ec_file.erl index 499a406..3f94bc2 100644 --- a/src/ec_file.erl +++ b/src/ec_file.erl @@ -175,7 +175,7 @@ mkdir_path(Path) -> %% @doc read a file from the file system. Provide UEX exeption on failure. --spec read(FilePath::file:filename()) -> binary() | {error, Reason::term()}. +-spec read(FilePath::file:filename()) -> {ok, binary()} | {error, Reason::term()}. read(FilePath) -> %% Now that we are moving away from exceptions again this becomes %% a bit redundant but we want to be backwards compatible as much @@ -373,9 +373,9 @@ find_test() -> {BaseDir, _SourceDir, {Name1, Name2, Name3, _NoName}} = setup_base_and_target(), Result = find(BaseDir, "file[a-z]+\$"), ?assertMatch(3, erlang:length(Result)), - ?assert(lists:member(Name1, Result)), - ?assert(lists:member(Name2, Result)), - ?assert(lists:member(Name3, Result)), + ?assertEqual(true, lists:member(Name1, Result)), + ?assertEqual(true, lists:member(Name2, Result)), + ?assertEqual(true, lists:member(Name3, Result)), remove(BaseDir, [recursive]). -endif.