gherkin icon indicating copy to clipboard operation
gherkin copied to clipboard

perl: Languages.pm is not mergable

Open mpkorstanje opened this issue 3 years ago • 8 comments

🤔 What's the problem you've observed?

Currently the generated Languages.pm consists of a single line.

https://github.com/cucumber/gherkin/blob/1cc2ef0153603c5e51818b59ff6d632238491226/perl/lib/Gherkin/Generated/Languages.pm#L1-L7

As a result, when multiple contributors submit changes to gherkin-languages.json their PR's will always conflict. Because PRs are not often looked at this happens more often then you'd think.

✨ Do you have a proposal for making it better?

Consider changing build_languages.pl so it generates the file with some formatting.

mpkorstanje avatar Nov 08 '22 13:11 mpkorstanje

@ehuelsmann could you have a look at this too?

mpkorstanje avatar Nov 08 '22 13:11 mpkorstanje

Hmm. I actually chose this structure for 2 reasons: to make it as small as possible and, because it's generated, it's not the authoritative source. The other solution is to generate this file during CI and release runs instead of keeping it in the repo as a versioned resource (this is the strategy I use in other projects). Do we really have to generate these files as part of the language update? People seem to regularly submit language updates without regenerating the language files in all implementations anyway. That would kill 2 birds with one stone.

ehuelsmann avatar Nov 10 '22 22:11 ehuelsmann

Do we really have to generate these files as part of the language update?

Unfortunately it depends.

For example for Go, yes we have to because it's consumed directly from Git rather than through a package manager. But on the other hand for Java this isn't nessesary, each time the project is build a file is generated using a build step in Maven.

If Perl has hooks to execute Perl code in the build step (I think it's dzil build) we can generate Languages.pm using only Perl.

mpkorstanje avatar Nov 10 '22 22:11 mpkorstanje

I haven't tried this, but this does look promising

https://metacpan.org/pod/Dist::Zilla::Plugin::Run

mpkorstanje avatar Nov 10 '22 23:11 mpkorstanje

Yes. We could run the "build languages" script just before running anything in the Makefile and include the file in our distribution build procedure.

ehuelsmann avatar Aug 15 '23 00:08 ehuelsmann

That's not quite the right solution. Because then if you were to build the project without the make file, it wouldn't work. Using dzil build should produce a working project. Using mvn package for example does because generating the code is part of the build process in the build tool.

mpkorstanje avatar Aug 16 '23 12:08 mpkorstanje

Hmm. How does Java deal with the need to have the file around in order to run the test suite? For Perl, I can (and need to) run the test suite straight out of the repository: only the most basic tests are being run after the "build" step, because otherwise the full test data would need to be included in the distribution archive. Which is rather useless, given that they are development time tests.

ehuelsmann avatar Sep 24 '23 19:09 ehuelsmann

Maven (for Java) has a generate sources phases that executes before compiling code and running tests. We generate the classes from the languages.json in this phase.

mpkorstanje avatar Sep 25 '23 00:09 mpkorstanje