Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use erlang term format instead of ascii #13

Open
wants to merge 24 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 15 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
# Apprentice binary

CC = gcc
CFLAGS = -std=c99 -g -Wall -Wextra -Werror
LDFLAGS = -lm -lmagic
HEADER_FILES = src
C_SOURCE_FILES = src/apprentice.c
OBJECT_FILES = $(C_SOURCE_FILES:.c=.o)
EXECUTABLE_DIRECTORY = priv
EXECUTABLE = $(EXECUTABLE_DIRECTORY)/apprentice
ERL_EI_INCLUDE:=$(shell erl -eval 'io:format("~s", [code:lib_dir(erl_interface, include)])' -s init stop -noshell | head -1)
ERL_EI_LIB:=$(shell erl -eval 'io:format("~s", [code:lib_dir(erl_interface, lib)])' -s init stop -noshell | head -1)
CFLAGS = -std=c99 -g -Wall -Werror
CPPFLAGS = -I$(ERL_EI_INCLUDE)
LDFLAGS = -L$(ERL_EI_LIB)
LDLIBS = -lpthread -lei -lm -lmagic
PRIV = priv/
RM = rm -Rf

# Unit test custom magic file
all: priv/apprentice

MAGIC = file
TEST_DIRECTORY = test
TARGET_MAGIC = $(TEST_DIRECTORY)/elixir.mgc
SOURCE_MAGIC = $(TEST_DIRECTORY)/elixir

# Target

all: $(EXECUTABLE) $(TARGET_MAGIC)

# Compile

$(EXECUTABLE): $(OBJECT_FILES) $(EXECUTABLE_DIRECTORY)
$(CC) $(OBJECT_FILES) -o $@ $(LDFLAGS)

$(EXECUTABLE_DIRECTORY):
mkdir -p $(EXECUTABLE_DIRECTORY)

.o:
$(CC) $(CFLAGS) $< -o $@

# Test case

$(TARGET_MAGIC): $(SOURCE_MAGIC)
cd $(TEST_DIRECTORY); $(MAGIC) -C -m elixir
priv/apprentice: src/apprentice.c
mkdir -p priv
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@

clean:
rm -f $(EXECUTABLE) $(OBJECT_FILES) $(BEAM_FILES)
$(RM) $(PRIV)

.PHONY: clean
17 changes: 2 additions & 15 deletions lib/gen_magic/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,13 @@ defmodule GenMagic.Config do
@startup_timeout 1_000
@process_timeout 30_000
@recycle_threshold :infinity
@database_patterns [:default]

def get_port_name do
{:spawn_executable, to_charlist(get_executable_name())}
end

def get_port_options(options) do
arguments = [:use_stdio, :stderr_to_stdout, :binary, :exit_status]

case get_executable_arguments(options) do
[] -> arguments
list -> [{:args, list} | arguments]
end
def get_port_options(_options) do
[:use_stdio, :binary, :exit_status, {:packet, 2}]
end

def get_startup_timeout(options) do
Expand All @@ -36,13 +30,6 @@ defmodule GenMagic.Config do
Path.join(:code.priv_dir(@otp_app), @executable_name)
end

defp get_executable_arguments(options) do
Enum.flat_map(List.wrap(get(options, :database_patterns, @database_patterns)), fn
:default -> ["--database-default"]
pattern -> pattern |> Path.wildcard() |> Enum.flat_map(&["--database-file", &1])
end)
end

defp get(options, key, default) do
Keyword.get(options, key, default)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/gen_magic/helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ defmodule GenMagic.Helpers do

alias GenMagic.Result
alias GenMagic.Server
@spec perform_once(Path.t(), [Server.option()]) :: {:ok, Result.t()} | {:error, term()}

@spec perform_once(Path.t() | {:bytes, binary}, [Server.option()]) ::
{:ok, Result.t()} | {:error, term()}

@doc """
Runs a one-shot process without supervision.
Expand Down
Loading