Skip to content

Commit

Permalink
Merge pull request #241 from mochi/rebar3
Browse files Browse the repository at this point in the history
Start on rebar3 support
  • Loading branch information
etrepum authored May 10, 2022
2 parents 53114ba + 8936dcd commit 845803a
Show file tree
Hide file tree
Showing 26 changed files with 162 additions and 164 deletions.
30 changes: 10 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,24 @@ on:
pull_request:
jobs:
test:
name: test
name: test ${{matrix.otp}} on ${{matrix.os}}
runs-on: ${{matrix.os}}
container:
image: erlang:${{matrix.otp}}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
otp:
- "24.3.3"
- "23.3.4.5"
- "22.3.4.9"
- "21.3.8.17"
- "24.3.4.0"
- "23.3.4.14"
- "22.3.4.26"
- "21.3.8.24"
- "20.3.8.26"
include:
- os: ubuntu-18.04
otp: "19.3.6.13"
- os: ubuntu-18.04
otp: "18.3.4.11"
- "19.3.6.13"
- "18.3.4.11"
steps:
- uses: actions/[email protected]
- run: |
VERSION=${{matrix.otp}}
RELEASE=$(lsb_release -cs)
DIR=$(mktemp -d)
pushd $DIR
FILE=esl-erlang_$VERSION-1~ubuntu~$RELEASE\_amd64.deb
wget https://packages.erlang-solutions.com/erlang/debian/pool/$FILE
sudo dpkg -i $FILE
popd
rm -r $DIR
- run: make test
- run: REBAR=rebar make test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
*.beam
*.dump
rebar.lock
/_build
/rebar3.crashdump
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Version 3.0.0 released 2022-XX-XX
Version 3.0.0 released 2022-05-09

* rebar3 is now the preferred build tool (finally)
https://github.com/mochi/mochiweb/pull/241
https://github.com/mochi/mochiweb/pull/243
* Minimum OTP version is now 18, which
allows us to remove a number of backwards
compatibility hacks while still supporting
Expand All @@ -14,6 +17,7 @@ Version 3.0.0 released 2022-XX-XX
that expression might have to be updated to
handle the `{shutdown, Error}` error reason.
https://github.com/mochi/mochiweb/pull/238
https://github.com/mochi/mochiweb/pull/242

Version 2.22.0 released 2021-08-23

Expand Down
26 changes: 10 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
PREFIX:=../
DEST:=$(PREFIX)$(PROJECT)
REBAR?=rebar3

REBAR=./rebar
.PHONY: all edoc test clean build

.PHONY: all edoc test clean build_plt dialyzer app
all: build

all:
@$(REBAR) prepare-deps
build:
@$(REBAR) get-deps # rebar2 compatibility, it's no-op on rebar3
@$(REBAR) compile

edoc: all
@$(REBAR) doc

test:
@rm -rf .eunit
@mkdir -p .eunit
test: build
@$(REBAR) eunit

edoc: build
@$(REBAR) edoc

clean:
@$(REBAR) clean

app:
@[ -z "$(PROJECT)" ] && echo "ERROR: required variable PROJECT missing" 1>&2 && exit 1 || true
@$(REBAR) -r create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ The mailing list for MochiWeb is at https://groups.google.com/group/mochiweb/

Erlang OTP is required for setting up the MochiWeb environment and is available at https://www.erlang.org/

To create a new mochiweb using project:
make app PROJECT=project_name
To create a new mochiweb using project see the `example_project` in the `examples/` folder.

To create a new mochiweb using project in a specific directory:
make app PROJECT=project_name PREFIX=$HOME/projects/

Information about Rebar (Erlang build tool) is available at https://github.com/rebar/rebar
Information about Rebar (Erlang build tool) is available at https://github.com/erlang/rebar3

MochiWeb is currently tested with Erlang/OTP 18.3 through 24.0,
versions older than 3.0.0 may still be compatible back to R15B-03.
Expand Down
14 changes: 14 additions & 0 deletions examples/example_project/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/ebin
/doc
/_test
/.eunit
/docs
.DS_Store
/TEST-*.xml
/deps
/.rebar
*.swp
*.beam
*.dump
_build/
rebar.lock
16 changes: 16 additions & 0 deletions examples/example_project/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
REBAR?=rebar3

.PHONY: all edoc test clean app

build:
@$(REBAR) get-deps # rebar2 compatibility, it's no-op on rebar3
@$(REBAR) compile

test:
@$(REBAR) eunit

edoc:
@$(REBAR) edoc

clean:
@$(REBAR) clean
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

# workaround for rebar mustache template bug
DEFAULT_PORT={{port}}
DEFAULT_PORT=8080
HOST=${HOST:-127.0.0.1}
PORT=${PORT:-${DEFAULT_PORT}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<title>It Worked</title>
</head>
<body>
{{appid}} running.
example_project running.
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{erl_opts, [debug_info]}.
{deps, [
{mochiweb, ".*",
{git, "git://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
{git, "https://github.com/mochi/mochiweb.git", {branch, "main"}}}]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
9 changes: 9 additions & 0 deletions examples/example_project/src/example_project.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
%% -*- erlang -*-
{application, example_project,
[{description, "example_project"},
{vsn, "0.1"},
{modules, []},
{registered, []},
{mod, {'example_project_app', []}},
{env, []},
{applications, [kernel, stdlib, crypto]}]}.
30 changes: 30 additions & 0 deletions examples/example_project/src/example_project.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% @author Mochi Media <[email protected]>
%% @copyright 2010 Mochi Media <[email protected]>

%% @doc example_project.

-module(example_project).
-author("Mochi Media <[email protected]>").
-export([start/0, stop/0]).

ensure_started(App) ->
case application:start(App) of
ok ->
ok;
{error, {already_started, App}} ->
ok
end.


%% @spec start() -> ok
%% @doc Start the example_project server.
start() ->
example_project_deps:ensure(),
ensure_started(crypto),
application:start(example_project).


%% @spec stop() -> ok
%% @doc Stop the example_project server.
stop() ->
application:stop(example_project).
22 changes: 22 additions & 0 deletions examples/example_project/src/example_project_app.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
%% @author Mochi Media <[email protected]>
%% @copyright example_project Mochi Media <[email protected]>

%% @doc Callbacks for the example_project application.

-module(example_project_app).
-author("Mochi Media <[email protected]>").

-behaviour(application).
-export([start/2,stop/1]).


%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for example_project.
start(_Type, _StartArgs) ->
example_project_deps:ensure(),
example_project_sup:start_link().

%% @spec stop(_State) -> ServerRet
%% @doc application stop callback for example_project.
stop(_State) ->
ok.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <[email protected]>
%% @copyright 2010 Mochi Media <[email protected]>

%% @doc Ensure that the relatively-installed dependencies are on the code
%% loading path, and locate resources relative
%% to this application's path.

-module({{appid}}_deps).
-author("{{author}}").
-module(example_project_deps).
-author("Mochi Media <[email protected]>").

-export([ensure/0, ensure/1]).
-export([get_base_dir/0, get_base_dir/1]).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <[email protected]>
%% @copyright 2010 Mochi Media <[email protected]>

%% @doc Supervisor for the {{appid}} application.
%% @doc Supervisor for the example_project application.

-module({{appid}}_sup).
-author("{{author}}").
-module(example_project_sup).
-author("Mochi Media <[email protected]>").

-behaviour(supervisor).

Expand Down Expand Up @@ -41,7 +41,7 @@ upgrade() ->
%% @spec init([]) -> SupervisorTree
%% @doc supervisor callback.
init([]) ->
Web = web_specs({{appid}}_web, {{port}}),
Web = web_specs(example_project_web, 8080),
Processes = [Web],
Strategy = {one_for_one, 10, 10},
{ok,
Expand All @@ -50,7 +50,7 @@ init([]) ->
web_specs(Mod, Port) ->
WebConfig = [{ip, {0,0,0,0}},
{port, Port},
{docroot, {{appid}}_deps:local_path(["priv", "www"])}],
{docroot, example_project_deps:local_path(["priv", "www"])}],
{Mod,
{Mod, start, [WebConfig]},
permanent, 5000, worker, dynamic}.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
%% @author {{author}}
%% @copyright {{year}} {{author}}
%% @author Mochi Media <[email protected]>
%% @copyright 2010 Mochi Media <[email protected]>

%% @doc Web server for {{appid}}.
%% @doc Web server for example_project.

-module('{{appid}}_web').
-module('example_project_web').

-author("{{author}}").
-author("Mochi Media <[email protected]>").

-export([loop/2, start/1, stop/0]).

Expand Down
9 changes: 9 additions & 0 deletions examples/example_project/start-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
exec erl \
-pa _build/default/lib/example_project/ebin \
-pa _build/default/lib/mochiweb/ebin \
-pa ebin deps/*/ebin \
-boot start_sasl \
-sname example_project_dev \
-s example_project \
-s reloader
Binary file removed rebar
Binary file not shown.
10 changes: 7 additions & 3 deletions src/mochiweb_multipart.erl
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,13 @@ find_boundary(Prefix, Data) ->
-include_lib("eunit/include/eunit.hrl").

ssl_cert_opts() ->
EbinDir = filename:dirname(code:which(?MODULE)),
CertDir = filename:join([EbinDir, "..", "support",
"test-materials"]),
{ok, Cwd} = file:get_cwd(),
CertDir = filename:join(
case filename:basename(Cwd) of
%% rebar2 compatibility
".eunit" -> [".."];
_ -> []
end ++ ["support", "test-materials"]),
CertFile = filename:join(CertDir, "test_ssl_cert.pem"),
KeyFile = filename:join(CertDir, "test_ssl_key.pem"),
[{certfile, CertFile}, {keyfile, KeyFile}].
Expand Down
5 changes: 0 additions & 5 deletions support/templates/.gitignore

This file was deleted.

24 changes: 0 additions & 24 deletions support/templates/mochiwebapp.template

This file was deleted.

9 changes: 0 additions & 9 deletions support/templates/mochiwebapp_skel/src/mochiapp.app.src

This file was deleted.

Loading

0 comments on commit 845803a

Please sign in to comment.