diff --git a/.gitignore b/.gitignore index bc381226..3640055f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ ebin/*.app doc/* .local_dialyzer_plt /.rebar +_build/* +rebar.lock diff --git a/Emakefile b/Emakefile deleted file mode 100644 index 7ee92efd..00000000 --- a/Emakefile +++ /dev/null @@ -1,6 +0,0 @@ -% -*- mode: erlang -*- -{["src/*"], - [{i, "include"}, - {outdir, "ebin"}, - debug_info] -}. diff --git a/Makefile b/Makefile index 8c7e5abf..c7713b62 100644 --- a/Makefile +++ b/Makefile @@ -1,43 +1,28 @@ -ERL ?= erl -APP := webmachine +REBAR3_URL=https://s3.amazonaws.com/rebar3/rebar3 -REPO = ${shell echo `basename "$${PWD}"`} -ARTIFACTSFILE = ${shell echo ${REPO}-`date +%F_%H-%M-%S`.tgz} +# If there is a rebar in the current directory, use it +ifeq ($(wildcard rebar3),rebar3) +REBAR3 = $(CURDIR)/rebar3 +endif -.PHONY: deps +# Fallback to rebar on PATH +REBAR3 ?= $(shell which rebar3) -all: deps compile +# And finally, prep to download rebar if all else fails +ifeq ($(REBAR3),) +REBAR3 = $(CURDIR)/rebar3 +endif -compile: deps - ./rebar compile -deps: DEV_MODE - @(./rebar get-deps) +all: $(REBAR3) + @$(REBAR3) do update, clean, compile, eunit, dialyzer -clean: - @(./rebar clean) +$(REBAR3): + curl -Lo rebar3 $(REBAR3_URL) || wget $(REBAR3_URL) + chmod a+x rebar3 -# nuke deps first to avoid wasting time having rebar recurse into deps -# for clean distclean: - @rm -rf ./deps ./.rebar - @(./rebar clean) + @rm -rf ./_build edoc: - @$(ERL) -noshell -run edoc_run application '$(APP)' '"."' '[{preprocess, true},{includes, ["."]}]' -DIALYZER_APPS = kernel stdlib sasl erts ssl tools os_mon runtime_tools crypto inets \ - xmerl webtool snmp public_key mnesia eunit syntax_tools compiler -COMBO_PLT = $(HOME)/.webmachine_dialyzer_plt - -include tools.mk - -verbosetest: all - @(./rebar -v skip_deps=true eunit) - -travisupload: - tar cvfz ${ARTIFACTSFILE} --exclude '*.beam' --exclude '*.erl' test.log .eunit - travis-artifacts upload --path ${ARTIFACTSFILE} - -DEV_MODE: - @[ -d ./.rebar ] || mkdir ./.rebar - @touch ./.rebar/DEV_MODE + @$(REBAR3) edoc diff --git a/rebar b/rebar deleted file mode 100755 index a8cbf1b7..00000000 Binary files a/rebar and /dev/null differ diff --git a/rebar.config b/rebar.config index 8e5147e9..017b2e8e 100644 --- a/rebar.config +++ b/rebar.config @@ -6,10 +6,19 @@ {xref_checks, [undefined_function_calls]}. {deps, - [{mochiweb, "2.9.0.*", {git, "git://github.com/basho/mochiweb.git", {tag, "v2.9.0p2"}}} + [{mochiweb, ".*", {git, "git://github.com/martinsumner/mochiweb.git", {branch, "develop-3.0-merge29"}}} ]}. -{dev_only_deps, - [{meck, "0.8.*", {git, "git://github.com/basho/meck.git", {tag, "0.8.2"}}}, - {ibrowse, "4.0.2", {git, "git://github.com/cmullaparthi/ibrowse.git", {tag, "v4.0.2"}}} +{eunit_opts, [ + no_tty, + {report, {eunit_progress, [colored, profile]}} + ]}. + +{profiles, + [{test, + [{deps, [meck, + {ibrowse, "4.4.0"} + ]}, + {erl_opts, [debug_info]} + ]} ]}. diff --git a/rebar.config.script b/rebar.config.script deleted file mode 100644 index be5bcac1..00000000 --- a/rebar.config.script +++ /dev/null @@ -1,68 +0,0 @@ -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et -OtpVersion = erlang:system_info(otp_release), -Config1 = case hd(OtpVersion) =:= $R andalso OtpVersion =< "R15B01" of - true -> - HashDefine = [{d,old_hash}], - case lists:keysearch(erl_opts, 1, CONFIG) of - {value, {erl_opts, Opts}} -> - lists:keyreplace(erl_opts,1,CONFIG,{erl_opts,Opts++HashDefine}); - false -> - CONFIG ++ [{erl_opts, HashDefine}] - end; - false -> CONFIG - end. - -%% Merge the list values in `ToAdd' into the list found at key `Key' -%% in proplist `C'. Don't duplicate items. New Items are added to the -%% front of existing items. It is an error if the value at `Key' is -%% not a list in `C'. -MergeConfig = fun({Key, ToAdd}, C) -> - case lists:keyfind(Key, 1, C) of - false -> - lists:keystore(Key, 1, C, {Key, ToAdd}); - {Key, List} when is_list(List) -> - %% remove items in ToAdd already in List - ToAdd1 = [ I || I <- ToAdd, not lists:member(I, List) ], - lists:keystore(Key, 1, C, {Key, ToAdd1 ++ List }) - end - end. - -%% -- Add development only options if we are a top-level build -- -%% -%% If a file named `./.rebar/DEV_MODE' exists, we assume we are a -%% top-level build (not being built as a dep of another project). We -%% add the deps from dev_only_deps defined in rebar.config, add -%% concrete as a dep, and define the compiler macro DEV_ONLY. - -%% This macro can be used to conditionally enable code (e.g. tests) -%% that depend on development only dependencies. -ErlOpts = {erl_opts, [ - {d, 'DEV_ONLY'} -]}, - -%% Development only dependencies can be specified in the main -%% rebar.config. This file should not need to be edited directly. -DevOnlyDeps = case lists:keyfind(dev_only_deps, 1, CONFIG) of - false -> - []; - {dev_only_deps, DOD} -> - DOD - end, - -Deps = {deps, DevOnlyDeps}, - -ConfigPath = filename:dirname(SCRIPT), -DevMarker = filename:join([ConfigPath, ".rebar", "DEV_MODE"]), -_ = filelib:ensure_dir(DevMarker), -case filelib:is_file(DevMarker) of - true -> - lists:foldl(fun(I, C) -> MergeConfig(I, C) end, - Config1, [Deps, ErlOpts]); - false -> - %% If the ./.rebar/DEV_MODE marker is not present, this script simply - %% returns the config specified in rebar.config. This will be - %% the behavior when the project is built as a dependency of - %% another project. - Config1 -end. diff --git a/rebar3 b/rebar3 new file mode 100755 index 00000000..f0b1ba78 Binary files /dev/null and b/rebar3 differ diff --git a/src/webmachine_mochiweb.erl b/src/webmachine_mochiweb.erl index 43a864ed..046df2fa 100644 --- a/src/webmachine_mochiweb.erl +++ b/src/webmachine_mochiweb.erl @@ -30,7 +30,14 @@ -define (WM_OPTION_DEFAULTS, [{error_handler, webmachine_error_handler}]). start(Options) -> - {DispatchList, PName, DGroup, WMOptions, OtherOptions} = get_wm_options(Options), + {DispatchList, PName, DGroup, WMOptions, OtherOptions0} = get_wm_options(Options), + OtherOptions = + case application:get_env(webmachine, recbuf) of + {ok, RecBuf} -> + [{recbuf, RecBuf}|OtherOptions0]; + _ -> + OtherOptions0 + end, webmachine_router:init_routes(DGroup, DispatchList), _ = [application_set_unless_env_or_undef(K, V) || {K, V} <- WMOptions], MochiName = list_to_atom(to_list(PName) ++ "_mochiweb"), diff --git a/src/webmachine_perf_log_handler.erl b/src/webmachine_perf_log_handler.erl index 49a5ba9c..ffb50b22 100644 --- a/src/webmachine_perf_log_handler.erl +++ b/src/webmachine_perf_log_handler.erl @@ -132,15 +132,15 @@ fmt_plog(Time, Ip, Method, Path, {VM,Vm}, Status, Length, Mod, TTPD, TTPS) -> non_standard_method_test() -> LogData = #wm_log_data{resource_module=foo, - start_time=now(), + start_time=os:timestamp(), method="FOO", peer={127,0,0,1}, path="/", version={1,1}, response_code=501, response_length=1234, - end_time=now(), - finish_time=now()}, + end_time=os:timestamp(), + finish_time=os:timestamp()}, LogEntry = format_req(LogData), ?assert(is_list(LogEntry)), ok. diff --git a/src/webmachine_request.erl b/src/webmachine_request.erl index 4a5d4783..4704d8f4 100644 --- a/src/webmachine_request.erl +++ b/src/webmachine_request.erl @@ -640,7 +640,7 @@ parts_to_body(BodyList, Size, Req) when is_list(BodyList) -> {CT, _} -> CT end, - Boundary = mochihex:to_hex(crypto:rand_bytes(8)), + Boundary = mochihex:to_hex(crypto:strong_rand_bytes(8)), HeaderList = [{"Content-Type", ["multipart/byteranges; ", "boundary=", Boundary]}], diff --git a/test/decision_core_test.erl b/test/decision_core_test.erl index 44fd0ee2..7a2353d4 100644 --- a/test/decision_core_test.erl +++ b/test/decision_core_test.erl @@ -20,7 +20,7 @@ -include("wm_reqdata.hrl"). -include_lib("eunit/include/eunit.hrl"). --compile(export_all). +-compile([export_all, nowarn_export_all]). -define(RESOURCE, atom_to_list(?MODULE)). -define(RESOURCE_PATH, "/" ++ ?RESOURCE). diff --git a/test/wm_integration_test.erl b/test/wm_integration_test.erl index 9aac6413..d980bef7 100644 --- a/test/wm_integration_test.erl +++ b/test/wm_integration_test.erl @@ -17,7 +17,7 @@ -include_lib("eunit/include/eunit.hrl"). -include("webmachine.hrl"). --compile([export_all]). +-compile([export_all, nowarn_export_all]). integration_test_() -> {foreach, diff --git a/tools.mk b/tools.mk deleted file mode 100644 index 8e0e1b9a..00000000 --- a/tools.mk +++ /dev/null @@ -1,48 +0,0 @@ -test: compile - ./rebar eunit skip_deps=true - -docs: - ./rebar doc skip_deps=true - -xref: compile - ./rebar xref skip_deps=true - -PLT ?= $(HOME)/.riak_combo_dialyzer_plt -LOCAL_PLT = .local_dialyzer_plt -DIALYZER_FLAGS ?= -Wunmatched_returns - -${PLT}: compile -ifneq (,$(wildcard $(PLT))) - dialyzer --check_plt --plt $(PLT) --apps $(DIALYZER_APPS) && \ - dialyzer --add_to_plt --plt $(PLT) --output_plt $(PLT) --apps $(DIALYZER_APPS) ; test $$? -ne 1 -else - dialyzer --build_plt --output_plt $(PLT) --apps $(DIALYZER_APPS); test $$? -ne 1 -endif - -${LOCAL_PLT}: compile -ifneq (,$(wildcard deps/*)) -ifneq (,$(wildcard $(LOCAL_PLT))) - dialyzer --check_plt --plt $(LOCAL_PLT) deps/*/ebin && \ - dialyzer --add_to_plt --plt $(LOCAL_PLT) --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1 -else - dialyzer --build_plt --output_plt $(LOCAL_PLT) deps/*/ebin ; test $$? -ne 1 -endif -endif - -dialyzer: ${PLT} ${LOCAL_PLT} - @echo "==> $(shell basename $(shell pwd)) (dialyzer)" - @if [ -f $(LOCAL_PLT) ]; then \ - dialyzer $(DIALYZER_FLAGS) --plts $(PLT) $(LOCAL_PLT) -c ebin; \ - else \ - dialyzer $(DIALYZER_FLAGS) --plts $(PLT) -c ebin; \ - fi - -cleanplt: - @echo - @echo "Are you sure? It takes several minutes to re-build." - @echo Deleting $(PLT) and $(LOCAL_PLT) in 5 seconds. - @echo - sleep 5 - rm $(PLT) - rm $(LOCAL_PLT) -