2

I am using ruby-protobuf to generate (de)serialisers for my gem. This will essentially generate a ruby file, which is required by other files in my gem.

I have setup Rake tasks for generating this code. I do not add the generated code to git.

The problem is when I install my gem with gem/bundler, it will not include this generated file.

I would like to be able to specify that I want my code to be generated as part of the .gemspec file; in a similar way to how native extensions are built. Is this possible? It could either run the protobuf directly as a CLI command, run my Rake tasks, or run some arbitrary ruby (which could invoke the CLI command).

Thanks.

Will Sewell
  • 2,593
  • 2
  • 20
  • 39
  • Out of interest, why not add the generated code to the gem's `git` repo? I think it is possible to do what you want via `extconf.rb`, but if you do so, you have less direct control over the generated code (e.g. it could end up with a bug due to different dependencies in generator library code versions), and your tests will need to be run for all variations of `ruby-protobuf`. – Neil Slater Jun 13 '16 at 16:24
  • @NeilSlater, all the top answers to these questions [1] [2] advocate leaving them out. Maybe this a special case since this is a library? [1] http://programmers.stackexchange.com/questions/192113/do-i-check-generated-code-in-to-source-control-or-not [2] http://stackoverflow.com/questions/893913/should-i-store-generated-code-in-source-control – Will Sewell Jun 14 '16 at 08:08
  • 1
    Interesting read. I think the top answers there is suggesting you do the code generation during "build". There is a pre-release build step, when you package the gem file for publishing, which is also a `rake` task . . . that appears to follow the best practice outlined in that answer and allow you to code the build into the `Rakefile` without attempts to over-ride `extconf.rb` - it also clearly makes your serialiser-generating library a development dependency, and to me would seem cleanest solution given the best practice you want to follow. – Neil Slater Jun 14 '16 at 09:34
  • I understand how to add the generated files in general (in practice it will depend how you identify them - could you perhaps show a snippet of your generating logic - specifically the part that identifies the source and target files). Would that help as an answer? – Neil Slater Jun 14 '16 at 09:36
  • @NeilSlater, thanks for your thoughts. I've decided to just check it into source control. While it comes with some disadvantages, trying to generate it on the fly seems to be much more trouble than it's worth. – Will Sewell Jun 15 '16 at 12:30
  • 1
    OK. Someone (maybe me) might have a go at answering this in general for a Ruby gem, it is an interesting question. – Neil Slater Jun 15 '16 at 13:00

0 Answers0