diff --git a/include/zx_logger.hrl b/include/zx_logger.hrl new file mode 100644 index 0000000..763af58 --- /dev/null +++ b/include/zx_logger.hrl @@ -0,0 +1,34 @@ +-export([log/2, log/3]). + + +-spec log(Level, Format) -> ok + when Level :: info + | warning + | error, + Format :: string(). +%% @private +%% @equiv log(Level, Format, []) + +log(Level, Format) -> + log(Level, Format, []). + + +-spec log(Level, Format, Args) -> ok + when Level :: info + | warning + | error, + Format :: string(), + Args :: [term()]. +%% @private +%% A logging abstraction to hide whatever logging back end is actually in use. +%% Format must adhere to Erlang format string rules, and the arity of Args must match +%% the provided format. + +log(Level, Format, Args) -> + Tag = + case Level of + info -> "[INFO]"; + warning -> "[WARNING]"; + error -> "[ERROR]" + end, + io:format("~s ~p: " ++ Format ++ "~n", [Tag, self() | Args]). diff --git a/zmake b/zmake new file mode 100755 index 0000000..75f3a21 --- /dev/null +++ b/zmake @@ -0,0 +1,48 @@ +#! /usr/bin/env escript + +-mode(compile). + +main(Args) -> + ok = make(), + ok = lists:foreach(fun dispatch/1, Args), + halt(0). + + +dispatch("edoc") -> + ok = edoc(); +dispatch("dialyze") -> + ok = dialyze(); +dispatch("test") -> + ok = test(); +dispatch(Unknown) -> + ok = io:format("zmake: Unknown directive: ~tp~n", [Unknown]), + halt(1). + + +make() -> + true = code:add_patha("ebin"), + up_to_date = make:all(), + halt(0). + + +edoc() -> + ok = io:format("EDOC: Writing docs...~n"), + ok = edoc:application(zomp, ".", []), + halt(0). + + +dialyze() -> + ok = + case dialyzer:run([{from, src_code}, {files_rec, ["./src"]}]) of + [] -> + io:format("Dialyzer found no errors and returned no warnings! Yay!~n"); + Warnings -> + Messages = [dialyzer:format_warning(W) || W <- Warnings], + lists:foreach(fun io:format/1, Messages) + end, + halt(0). + + +test() -> + ok = io:format("TEST: If I only had a brain.~n"), + halt(0). diff --git a/zx.bash b/zx.bash new file mode 100755 index 0000000..fb0967f --- /dev/null +++ b/zx.bash @@ -0,0 +1,13 @@ +#! /bin/bash + +# set -x + +ZOMP_DIR="$HOME/.zomp" +ORIGIN="$(pwd)" +VERSION="$(ls $ZOMP_DIR/lib/otpr-zx/ | sort --field-separator=. --reverse | head --lines=1)" +ZX_DIR="$ZOMP_DIR/lib/otpr-zx/$VERSION" + +cd "$ZX_DIR" +./zmake +cd "$ZOMP_DIR" +erl -pa "$ZX_DIR/ebin" -run zx start $@