2019-09-02 14:29:19 +03:00
|
|
|
defmodule Plausible do
|
|
|
|
@moduledoc """
|
2023-11-20 14:52:20 +03:00
|
|
|
Build-related macros
|
2019-09-02 14:29:19 +03:00
|
|
|
"""
|
2023-11-20 14:52:20 +03:00
|
|
|
|
2023-11-29 13:04:54 +03:00
|
|
|
@small_builds [:small, :small_test, :small_dev]
|
2023-11-20 14:52:20 +03:00
|
|
|
|
|
|
|
defmacro __using__(_) do
|
|
|
|
quote do
|
|
|
|
require Plausible
|
|
|
|
import Plausible
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-22 17:34:47 +03:00
|
|
|
defmacro on_full_build(clauses) do
|
|
|
|
do_on_full_build(clauses)
|
2023-11-20 14:52:20 +03:00
|
|
|
end
|
|
|
|
|
2023-11-22 17:34:47 +03:00
|
|
|
def do_on_full_build(do: block) do
|
|
|
|
do_on_full_build(do: block, else: nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
def do_on_full_build(do: do_block, else: else_block) do
|
2023-11-20 14:52:20 +03:00
|
|
|
if Mix.env() not in @small_builds do
|
|
|
|
quote do
|
2023-11-22 17:34:47 +03:00
|
|
|
unquote(do_block)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
quote do
|
|
|
|
unquote(else_block)
|
2023-11-20 14:52:20 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmacro full_build?() do
|
|
|
|
full_build? = Mix.env() not in @small_builds
|
|
|
|
|
2023-11-22 17:34:47 +03:00
|
|
|
# Tricking dialyzer as per:
|
|
|
|
# https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778
|
2023-11-20 14:52:20 +03:00
|
|
|
quote do
|
2023-11-22 17:34:47 +03:00
|
|
|
:erlang.phash2(1, 1) == 0 and unquote(full_build?)
|
2023-11-20 14:52:20 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defmacro small_build?() do
|
|
|
|
small_build? = Mix.env() in @small_builds
|
|
|
|
|
|
|
|
quote do
|
|
|
|
unquote(small_build?)
|
|
|
|
end
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|