Page MenuHomePhorge

No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..822caf1
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,23 @@
+# The directory Mix will write compiled artifacts to.
+_build/*
+
+# If you run "mix test --cover", coverage assets end up here.
+cover/*
+
+# The directory Mix downloads your dependencies sources to.
+deps/*
+
+# Where 3rd-party dependencies like ExDoc output generated docs.
+doc/*
+
+# Ignore .fetch files in case you like to edit your project deps locally.
+.fetch/*
+
+# If the VM crashes, it generates a dump, let's ignore it too.
+erl_crash.dump
+
+# Also ignore archive artifacts (built via "mix archive.build").
+*.ez
+priv/*
+bench/snapshots/*
+
diff --git a/Makefile b/Makefile
index c6aa9f2..6180bf0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,46 +1,59 @@
MIX = mix
-CFLAGS = -g -O3 -std=c99 -pedantic -Wcomment -Wall -Wextra
+MYHTMLEX_CFLAGS = -g -O3 -std=c99 -pedantic -Wcomment -Wall
+# we need to compile position independent code
+MYHTMLEX_CFLAGS += -fpic -DPIC
+# myhtmlex is using stpcpy, as defined in gnu string.h
+# MYHTMLEX_CFLAGS += -D_GNU_SOURCE
+# base on the same posix c source as myhtml
+# MYHTMLEX_CFLAGS += -D_POSIX_C_SOURCE=199309
# turn warnings into errors
-CFLAGS += -Werror
+# MYHTMLEX_CFLAGS += -Werror
# ignore unused variables
-CFLAGS += -Wno-unused-variable
+# MYHTMLEX_CFLAGS += -Wno-unused-variable
# ignore unused parameter warnings
-CFLAGS += -Wno-unused-parameter
-# ignore missing field initializers warning (because of `static ErlNifFunc funcs[]`)
-CFLAGS += -Wno-missing-field-initializers
+MYHTMLEX_CFLAGS += -Wno-unused-parameter
# set erlang include path
ERLANG_PATH = $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
-CFLAGS += -I$(ERLANG_PATH)
-
-# either we have not fetched myhtml, assume its in a sibling directory
-ifeq ($(wildcard deps/myhtml),)
- MYHTML_PATH = ../myhtml
-# or we fetched it as a mix dependency
-else
- MYHTML_PATH = deps/myhtml
-endif
+MYHTMLEX_CFLAGS += -I$(ERLANG_PATH)
+
+# expecting myhtml fetched as a mix dependency
+MYHTML_PATH = deps/myhtml
+MYHTML_STATIC = $(MYHTML_PATH)/lib/libmyhtml_static.a
+MYHTMLEX_CFLAGS += -I$(MYHTML_PATH)/include
-CFLAGS += -I$(MYHTML_PATH)/source
+# that would be used for a dynamically linked build
+# MYHTMLEX_CFLAGS += -L$(MYHTML_PATH)/lib
-# I have no idea yet what this does, something for macOS presuambly
-ifeq ($(shell uname),Darwin)
- LDFLAGS += -dynamiclib -undefined dynamic_lookup
+MYHTMLEX_LDFLAGS = -shared
+
+# platform specific
+UNAME = $(shell uname -s)
+ifeq ($(wilcard Makefile.$(UNAME)),)
+ include Makefile.$(UNAME)
endif
-.PHONY: all myhtml clear
+.PHONY: all myhtmlex
-all: myhtml
+all: myhtmlex
-myhtml:
+myhtmlex: priv/myhtmlex.so
$(MIX) compile
-priv/myhtmlex.so: src/myhtmlex.c
+deps/myhtml:
+ $(MIX) deps.get
+
+$(MYHTML_STATIC): deps/myhtml
$(MAKE) -C $(MYHTML_PATH) library
- $(CC) $(CFLAGS) -shared $(LDFLAGS) -o $@ src/myhtmlex.c $(MYHTML_PATH)/lib/libmyhtml_static.a
+
+priv/myhtmlex.so: src/myhtmlex.c $(MYHTML_STATIC)
+ test -d priv || mkdir priv
+ $(CC) $(MYHTMLEX_CFLAGS) $(MYHTMLEX_LDFLAGS) -o $@ $< $(MYHTML_STATIC)
clean:
$(MIX) clean
- $(MAKE) -C $(MYHTML_PATH) clean
$(RM) priv/myhtmlex.so
+clean-myhtml:
+ $(MAKE) -C $(MYHTML_PATH) clean
+
diff --git a/Makefile.Darwin b/Makefile.Darwin
new file mode 100644
index 0000000..df72ad9
--- /dev/null
+++ b/Makefile.Darwin
@@ -0,0 +1 @@
+MYHTMLEX_LDFLAGS += -dynamiclib -undefined dynamic_lookup
diff --git a/Makefile.Linux b/Makefile.Linux
new file mode 100644
index 0000000..f8c1115
--- /dev/null
+++ b/Makefile.Linux
@@ -0,0 +1,4 @@
+# myhtmlex is using stpcpy, as defined in gnu string.h
+MYHTMLEX_CFLAGS += -D_GNU_SOURCE
+# base on the same posix c source as myhtml
+# MYHTMLEX_CFLAGS += -D_POSIX_C_SOURCE=199309
diff --git a/build-test/ubuntu-16.04.dockerfile b/build-test/ubuntu-16.04.dockerfile
new file mode 100644
index 0000000..ce83b7c
--- /dev/null
+++ b/build-test/ubuntu-16.04.dockerfile
@@ -0,0 +1,27 @@
+FROM ubuntu:xenial
+
+RUN mkdir myhtmlex
+WORKDIR myhtmlex
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+RUN apt-get update \
+ && apt-get install -y curl \
+ && curl -LO https://packages.erlang-solutions.com/erlang-solutions_1.0_all.deb \
+ && dpkg -i erlang-solutions_1.0_all.deb \
+ && apt-get update \
+ && apt-get install -y \
+ git \
+ esl-erlang \
+ elixir \
+ build-essential \
+ && mix local.hex --force \
+ && echo 'LANG=en_US.UTF-8' > /etc/default/locale \
+ && echo 'LANGUAGE=en_US' >> /etc/default/locale
+
+COPY . ./
+
+RUN make \
+ && mix test \
+ && mix bench
+
diff --git a/src/myhtmlex.h b/src/myhtmlex.h
index 26fc48e..044dc3c 100644
--- a/src/myhtmlex.h
+++ b/src/myhtmlex.h
@@ -1,47 +1,48 @@
#ifndef MYHTMLEX_H
#define MYHTMLEX_H
#include <stdlib.h>
#include <ctype.h>
+#include <string.h>
#include "erl_nif.h"
#include <myhtml/myhtml.h>
#include <myhtml/mynamespace.h>
char*
lowercase(char* c);
// myhtmlex.c
ERL_NIF_TERM
make_atom(ErlNifEnv* env, const char* name);
ERL_NIF_TERM
nif_decode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM
nif_decode_tree(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM
nif_open(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]);
ERL_NIF_TERM
build_node_attrs(ErlNifEnv* env, myhtml_tree_t* tree, myhtml_tree_node_t* node);
ERL_NIF_TERM
build_tree(ErlNifEnv* env, myhtml_tree_t* tree, myhtml_tree_node_t* node);
ERL_NIF_TERM
build_node_children(ErlNifEnv* env, myhtml_tree_t* tree, myhtml_tree_node_t* node);
void
nif_cleanup_myhtml_tree(ErlNifEnv* env, void* obj);
// consts
ERL_NIF_TERM ATOM_NIL;
ERL_NIF_TERM ATOM_COMMENT;
ERL_NIF_TERM EMPTY_LIST;
typedef struct {
myhtml_t* myhtml;
myhtml_tree_t* tree;
ErlNifResourceType* myhtml_tree_rt;
} myhtmlex_state_t;
typedef struct {
myhtml_tree_t* tree;
myhtml_tree_node_t *root;
} myhtmlex_ref_t;
#endif // included myhtmlex.h

File Metadata

Mime Type
text/x-diff
Expires
Thu, Oct 29, 4:30 AM (4 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1796622
Default Alt Text
(5 KB)

Event Timeline