Initial attempt of autogenerated mochiweb_mime.erl #46

Closed
wants to merge 9 commits into from

2 participants

@lemenkov
Mochi Media, Inc. member

I think that we should regenerate mochiweb_mime.erl from FD.o shared-mime-info instead of manually maintaining it.

This is a proof-of-concept I made recently. It still has at least one issue (several generated functions mask next ones - see compile log) so it can't be merged as is. I'll try to fix it soon.

@lemenkov lemenkov Initial attempt of autogenerated mochiweb_mime.erl
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
960d3bb
@etrepum
Mochi Media, Inc. member

I don't want to put Python dependencies in mochiweb. If we convert this to an escript it might be usable.

lemenkov added some commits Apr 23, 2011
@lemenkov lemenkov Initial attempt to handle dupes
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
9eeb394
@lemenkov lemenkov Use escript and xmerl instead of python-lxml
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
15b4843
@lemenkov lemenkov Last minute fix
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
174635d
@lemenkov lemenkov Cleanups
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
63ce1a2
@lemenkov lemenkov Fix regexp in escript
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
17c1223
@lemenkov lemenkov Cleanups
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
19a23dc
@lemenkov
Mochi Media, Inc. member

I don't want to put Python dependencies in mochiweb. If we convert this to an escript it might be usable.

Added escript.

Unsurprisingly, it takes about 5 seconds to process XML instead of 1 second in case of python-lxml (which is basically a binding to libxml). Also it was much simpler to process XML with python-lxml than with xmerl. Hope that Erlang/OTP will include a decent and fast XML parser someday.

@etrepum
Mochi Media, Inc. member

It doesn't work for me out of the box. I also don't think this feature is worth adding 5 seconds to every compile... maybe if we could make it only produce a new erl if the xml or escript has changed then it would be usable.

$ ./rebar compile
==> mochiweb (compile)
sh: /Users/bob/src/mochiweb/support/parse_mime.escript: /usr/bin/escript: bad interpreter: No such file or directory
sh: /Users/bob/src/mochiweb/support/parse_mime.escript: Unknown error: 0
ERROR: ./support/parse_mime.escript  ./support/freedesktop.org.xml > ./src/mochiweb_mime.erl failed with error: 1
lemenkov added some commits May 8, 2011
@lemenkov lemenkov Use env instead of full path to the escript
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
dd23b5c
@lemenkov lemenkov Add src/mochiweb_mime.erl back to repo and disable autogenerating on …
…each build

Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
329d138
@dreid dreid commented on the diff May 27, 2011
support/parse_mime.escript
+ lists:map(fun ({Desc,Ext}) -> [$* | BareExt ] = Ext, io:format("from_extension(\"~s\") ->~n \"~s\";~n", [BareExt, Desc]) end, List),
+
+ io:format("from_extension(_) ->\n undefined.\n"),
+ io:format(
+ "%%\n"
+ "%% Tests\n"
+ "%%\n\n"
+ "-ifdef(TEST).\n"
+ "-include_lib(\"eunit/include/eunit.hrl\").\n\n"
+ "exhaustive_from_extension_test() ->\n"
+ " T = mochiweb_cover:clause_lookup_table(?MODULE, from_extension),\n"
+ " [?assertEqual(V, from_extension(K)) || {K, V} <- T].\n\n"
+ "from_extension_test() ->\n"
+ ),
+
+ lists:map(fun ({Desc,Ext}) -> [$* | BareExt ] = Ext, io:format(" ?assertEqual(\"~s\",~n from_extension(\"~s\")),~n", [Desc, BareExt]) end, List),
@dreid
Mochi Media, Inc. member
dreid added a note May 27, 2011

This is redundant in the presence of the exhaustive_from_extension_tests(), which uses mochiweb_cover to inspect the from_extension clause's AST and generate a set of assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@etrepum etrepum closed this Jul 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment