Setup elixir make for prod
parent
3370e84761
commit
a7776a6e8c
|
@ -22,6 +22,8 @@ auth_secret.exs
|
|||
# Farmbot argifacts
|
||||
tmp/
|
||||
test_tmp/
|
||||
priv/build_calendar.so
|
||||
*.o
|
||||
|
||||
# Generated on crash by the VM
|
||||
erl_crash.dump
|
||||
|
@ -29,7 +31,6 @@ erl_crash.dump
|
|||
# From other branches
|
||||
/cache
|
||||
*.js
|
||||
Makefile
|
||||
/release-*
|
||||
node_modules
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
ifeq ($(ERTS_DIR),)
|
||||
ERTS_DIR = $(shell erl -eval "io:format(\"~s/erts-~s~n\", [code:root_dir(), erlang:system_info(version)])" -s init stop -noshell)
|
||||
ifeq ($(ERTS_DIR),)
|
||||
$(error Could not find the Erlang installation. Check to see that 'erl' is in your PATH)
|
||||
endif
|
||||
endif
|
||||
|
||||
CFLAGS = -fPIC -Wl,-undefined -Wl,dynamic_lookup -shared
|
||||
ERL_FLAGS = -I$(ERTS_DIR)/include
|
||||
CC ?= $(CROSSCOMPILER)cc
|
||||
|
||||
all:
|
||||
$(CC) $(ERL_FLAGS) $(CFLAGS) -o priv/build_calendar.so c_src/build_calendar.c
|
||||
|
||||
clean:
|
||||
$(RM) build_calendar.* priv/build_calendar.*
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include <erl_nif.h>
|
||||
|
||||
#define MAX_GENERATED 1000
|
||||
#define MAX_GENERATED 60
|
||||
|
||||
static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
|
||||
{
|
||||
|
@ -40,17 +40,17 @@ static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TE
|
|||
// if this event (i) is after the grace period, add it to the array.
|
||||
if(i > gracePeriodSeconds) {
|
||||
events[j] = i;
|
||||
events[j] -= (events[j] % MAX_GENERATED);
|
||||
events[j] -= (events[j] % 60);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// Count up our total generated events
|
||||
for(i = 0, j=0; j<MAX_GENERATED; j++) { if(events[j] > 0) { i++; } }
|
||||
for(i=0, j=0; j<MAX_GENERATED; j++) { if(events[j] > 0) { i++; } }
|
||||
|
||||
// Build the array to be returned.
|
||||
ERL_NIF_TERM retArr [i];
|
||||
for(j=0; j <i ; j++)
|
||||
for(j=0; j<i ; j++)
|
||||
retArr[j] = enif_make_long(env, events[j]);
|
||||
|
||||
// we survived.
|
||||
|
|
|
@ -7,10 +7,16 @@ defmodule Farmbot.Repo.FarmEvent do
|
|||
* A Sequence will execute.
|
||||
"""
|
||||
|
||||
@on_load :load_nifs
|
||||
@on_load :load_nif
|
||||
|
||||
def load_nifs do
|
||||
:erlang.load_nif('./build_calendar', 0)
|
||||
def load_nif do
|
||||
require Logger
|
||||
nif_file = '#{:code.priv_dir(:farmbot)}/build_calendar'
|
||||
case :erlang.load_nif(nif_file, 0) do
|
||||
:ok -> :ok
|
||||
{:error, {:reload, _}} -> :ok
|
||||
{:error, reason} -> Logger.warn "Failed to load nif: #{inspect reason}"
|
||||
end
|
||||
end
|
||||
|
||||
alias Farmbot.Repo.JSONType
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -23,6 +23,8 @@ defmodule Farmbot.Mixfile do
|
|||
app: :farmbot,
|
||||
description: "The Brains of the Farmbot Project",
|
||||
package: package(),
|
||||
compilers: [:elixir_make] ++ Mix.compilers,
|
||||
make_clean: ["clean"],
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
version: @version,
|
||||
target: @target,
|
||||
|
@ -76,6 +78,7 @@ defmodule Farmbot.Mixfile do
|
|||
defp deps do
|
||||
[
|
||||
{:nerves, "~> 0.8.3", runtime: false},
|
||||
{:elixir_make, "~> 0.4", runtime: false},
|
||||
{:gen_stage, "~> 0.12"},
|
||||
{:poison, "~> 3.0"},
|
||||
{:ex_json_schema, "~> 0.5.3"},
|
||||
|
|
Loading…
Reference in New Issue