Commit Graph

245 Commits

Author SHA1 Message Date
Jon Parise
91ab2b66d1 Write the full path in verbose output mode (#221) 2017-02-09 13:45:40 -08:00
Jon Parise
31d12fd6f4 Generalize the set of Parser.opts (#223)
The introduction of include_paths made me realize that adding more
parser options (e.g. namespace configuration) would become unwieldy.

This change generalizes parser options as a keyword list with formal
type definitions for supported values. At the moment, :include_paths is
the only option, but it's now much more obvious how to add new ones.
2017-02-09 11:27:23 -08:00
Dan Swain
014b854b8d Merge pull request #202 from dantswain/file_of_consts
Generate constants
2017-02-09 11:35:48 -05:00
Dan Swain
dca9da4be3 Merge branch 'thrift_tng' into file_of_consts 2017-02-09 11:27:23 -05:00
Jon Parise
2132b89a72 Support additional include paths (#219)
We previously only supported including other Thrift files whose
pathnames were relative to the current file. This change allows a list
of additional include (search) paths to be specified as part of the
project configuration (`thrift.include_paths`) or via a command line
option (`--include dir`).
2017-02-08 15:00:13 -08:00
Jon Parise
e68e55a1b6 Use a more complete set of .thrift test files (#218)
We now use ThriftTest.thrift file from the Apache Thrift distribution
(original license retained) as a fully representative test file.

We also include StressTest.thrift as an simpler additional test file for
those test cases that work on multiple input files.

Lastly, our tests now clean up generated files `on_exit`. Otherwise,
the last test would always leave its generated files.
2017-02-08 13:25:21 -08:00
Jon Parise
5b51510043 Use more idiomatic list prepend operations (#215)
This is nicer and more efficient than building a temporary single
element list to concatenate with the existing list.
2017-02-08 08:30:10 -08:00
Jon Parise
7867135db6 Reorganize the test directory hierarchy (#216)
This change introduces an intermediate thrift/ directory into the test
script hierarchy. This matches the lib/thrift/ layout and makes it
clearer which top-level test/ entries are for test support versus test
scripts.
2017-02-08 08:29:58 -08:00
Jon Parise
30575a3706 Fix the "consistency" warnings flagged by Credo (#217)
Also, only lint our test/support/ code and not all of our test scripts
for now.
2017-02-08 08:29:43 -08:00
Jon Parise
8b050d8dd6 Update some ProtocolHandler @spec's (#213)
start_link/5's @spec wasn't updated when it signature was last changed.
Also add a @spec to init/6 and mark some internal functions as private.

We only support :ranch_tcp at the moment, so that's explicitly enforced
in both the typespecs as well as the init/6 function head.
2017-02-07 12:11:03 -08:00
Dan Swain
36d5e4863e Add spec for ConstantGenerator.generate/3 2017-02-07 13:19:22 -05:00
Dan Swain
ec3f67d576 Add spec to quote_value/3
Can't get much more specific with the first two args
2017-02-07 13:13:16 -05:00
Dan Swain
32c00b31dd Merge branch 'thrift_tng' into file_of_consts 2017-02-07 13:04:34 -05:00
Dan Swain
51437669f3 Use Constant module instead of dummy value 2017-02-07 13:03:58 -05:00
Jon Parise
13b3b74773 Add typespecs to various utility functions (#211) 2017-02-07 10:00:29 -08:00
Dan Swain
cbb1e81595 Add values/0 to generated enum module (#189)
* Add `values/0` to generated enum module

This came up with one of my use cases.  Seems a reasonable counterpoint
to `names/0`.

* Change values/names to use meta, add enum functions
2017-02-07 09:59:47 -08:00
Dan Swain
642a7ff794 Merge branch 'thrift_tng' into file_of_consts 2017-02-07 12:59:02 -05:00
Jon Parise
adc9b9ddd9 Introduce a 'serializable' type (#210)
This also lets us address a dialyzer warning because we previously
weren't allowing the :application_exception atom to be serialized.
2017-02-06 17:20:07 -08:00
Jon Parise
ed90a1f6f3 Disable Credo's NoParenthesesWhenZeroArity check (#212)
This appears to crash on some of our code. We'll need to investigation
that separately.
2017-02-06 09:04:48 -08:00
Jon Parise
6b7b518119 Annotate model structs with @enforce_keys (#207)
This provides a simple compile-type guarantee that any required keys
have been specified when constructing these structs.
2017-02-06 05:39:38 -08:00
Jon Parise
b7fb68cd08 Handle unknown (invalid) compiler task options (#209)
We were still using OptionParser.parse!/1 in the compiler task from back
when we also supported interactive usage. Unfortunately, that function
throws an exception when it encounters an unknown (invalid) option.

Instead, we use OptionParser.parse/1, which allows us to safely discard
invalid options.
2017-02-06 05:37:23 -08:00
Dan Swain
1fdcef33b6 Generate constants in a module defined by the file
Instead of in a .Constants module
2017-02-05 21:14:35 -05:00
Dan Swain
9716f44b0d Generate constants as macros 2017-02-04 20:35:09 -05:00
Jon Parise
8a7eafb6aa Upgrade to Credo 0.6.1 (#205)
This lets us restore the specs checker.
2017-02-03 14:32:49 -08:00
Dan Swain
059d3d0587 Generate a t type for structs/unions/exceptions (#204)
It's fairly common to have follow a defstruct with a `@type t`.  This is
useful for dialyzer analysis and writing specs that convey useful
information.
2017-02-01 16:36:05 -08:00
Dan Swain
75aa56acfb Merge branch 'thrift_tng' into file_of_consts 2017-01-30 14:58:04 -06:00
Dan Swain
49c18f545b Alphabeticalize 2017-01-27 10:00:49 -05:00
Preston Guillory
8f1df5f6d5 Allow enum fields to have no default value (#198)
* Allow enum fields to have no default value

* Allow enum fields to have a default value

* Minor refactor
2017-01-26 17:42:09 -08:00
Dan Swain
d9d3dfdaf2 Add test file with only constants defined 2017-01-26 20:22:31 -05:00
Dan Swain
0f7e543a16 Add constant test cases, handle map constant 2017-01-26 20:16:13 -05:00
Dan Swain
6a162a4f05 Generate constants in a <base>.Constants module 2017-01-26 19:26:13 -05:00
Dan Swain
870de631e7 Rename/move default_value to quoted_value
Since it's now used in more than one place.  I'm not convinced that
Utils is the perfect spot for it but nothing else made sence either.
2017-01-26 18:30:03 -05:00
Dan Swain
fe58a6dda6 Merge branch 'thrift_tng' into file_of_consts 2017-01-26 17:18:34 -05:00
Preston Guillory
a0e0a1d9d2 Allow lists to serialize into maps/sets (#199) 2017-01-26 09:39:15 -08:00
Jon Parise
a34861c4b2 Upgrade Credo to version 0.6.0 (#200)
This also disables the "Readability.Specs" check because it appears to
crash Credo when it encounters some of our macro-ized code. That can be
investigated separately.
2017-01-26 08:43:47 -08:00
Jon Parise
b98d2ca4c6 Group compiler options under a :thrift key (#197)
This change moves all compiler options under a single top-level `thrift`
configuration key that contains a Keyword list of individual options.
`thrift_files` and `thrift_output` are now just `files` and `output_path`
within this sub-list.

The goal of this change is to tidy up the top-level configuration space
and provide for further expansion of our compiler option set.
2017-01-26 02:00:01 -08:00
Dan Swain
dabe15fab9 Generate constants modules 2017-01-25 21:04:24 -05:00
Preston Guillory
9a0e20338d Catch name collisions within type (#184)
* Catch name collisions within type

If two names of the same type (for example, two structs) exist in the same
file, one of them will be discarded silently at parse time. This causes it to
raise an exception.

* Clean up exception message
2017-01-23 10:40:05 -08:00
Jon Parise
9d2ce55620 Reintroduce the 'thrift.generate' mix task (#186)
My previous attempt to consolidate these two mix tasks into one was
unsuccessful due to the way mix tasks receive their command line
arguments. Specifically, we don't have a good way to differentiate
between e.g. a `mix test` command line containing test script filenames
and a `mix compile.thrift` command line naming Thrift schema files. When
the `:thrift` compiler is included, it will also run in the `mix test`
task flow and get confused about its inputs.

We now have two distinct and purpose-built mix tasks:

 - `compile.thrift` - intended for use in the Mix.compilers list
 - `thrift.generate` - intended for interactive command-line use
2017-01-17 14:18:58 -08:00
Preston Guillory
4aab8763d2 Convert resolver from process to function (#183)
Previously the resolver was a separate process that just maintained a map. This
had the drawback that it was difficult to catch errors raised during the
resolution process. We'd to be able to raise such an error on name collisions.
2017-01-13 17:47:08 -08:00
Preston Guillory
151fd0c6f1 Support binary default values (#182)
* Support binary default values

* Check binary default value
2017-01-13 15:39:36 -08:00
Jon Parise
aa07d24c5a Consolidate binary protocol field type constants (#180)
We previously defined nearly identical sets of constants representing
the binary protocol's field types as attributes in each module that
required them. This duplication isn't great for long-term maintenance.

This approach defines a single set of type constants as macros in a
new Thrift.Protocol.Binary.Type module. Using macros lets us preserve
all of the compile-time benefits we were getting from the previous
approach while still supporting code sharing.
2017-01-13 13:30:44 -08:00
Jon Parise
39882a2957 Force coveralls.travis to run in the 'test' env (#178) 2017-01-12 10:20:56 -08:00
Preston Guillory
6b4a15f60f Make generated server opts optional (#176) 2017-01-11 13:39:05 -08:00
Steve Cohen
1f78c31055 Timeout / Retry refactor (#167)
* Timeout / Retry refactor

Servers now support read timeouts

Additionally, I changed how we handle retries due to some idiosyncracies
with how erlang responds to server failures.

When the server closes the connection, the client's `:gen_tcp.send`
operation will always succeed, failing instead on the corresponding
`:gen_tcp.recv` command. This is problematic, because we can't know for
sure that a message has been sent, and if we retry, we might resend a
message accidentally.

Furthermore, we can _never_ really know if a oneway message has been
sent or not.

Admittedly, the window for this is pretty narrow, the server would have
to sever the connection between the send and recv calls. The next case
is more troublesome.

Since we have backoff behavior, imagine if the user has set a retry
count of `:infinity` and made a call to a dead server. Now the client is
backing off and the `GenServer` call will timeout after 5 seconds. The
client is now stuck in a loop, reconnecting forever.

In light of these issues, I've removed repeated reconnects from the
client and have implemented a one-shot reconnect. We can still send a
message twice, but the window is sufficiently small to make me not worry
so much. This also has the effect of improving UX in the light of a
server that disconnects clients after a short timeout. If you send a
message on a disconnected client, it remembers it, reconnects and sends
it.

That seems reasonable.
2017-01-11 13:25:15 -08:00
Preston Guillory
c2a1f51475 Wrap long lines in generated output (#175)
Generated module names can be quite long, so this pattern produces very long
lines because Macro.to_string does not wrap pipe operators to the next line.

  serialized_var = %Big.Generated.Module{} |> Big.Generated.Module.serialize()

This change just replaces it with a slightly more readable:

  var = %Big.Generated.Module{}
  Big.GeneratedModule.serialize(var)
2017-01-11 11:47:05 -08:00
Jon Parise
658bf9f878 Use the latest .Client and .Server namespaces (#174)
Fixes #171
2017-01-11 09:08:29 -08:00
Ali Altaf
5d955839f7 Fixed incorrect code in README (#173) 2017-01-10 16:48:44 -08:00
Dan Swain
204254e4f6 Merge pull request #165 from dantswain/field_of_snakes
Ensure field names are valid elixir function names
2017-01-10 11:24:50 -05:00
Steve Cohen
592ff37c5b We moved the behaviour, example now reflects that (#169) 2017-01-09 17:31:47 -08:00