Skip to content

Commit

Permalink
[Perl] Generated Languages.pm as part of the build process (#176)
Browse files Browse the repository at this point in the history
The Languages.pm file is now generated upon building the release
artifacts or when running the test suite.

Fixes: #32

Co-authored-by: M.P. Korstanje <[email protected]>
  • Loading branch information
ehuelsmann and mpkorstanje authored Feb 9, 2025
1 parent 40b4cec commit a14e79a
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 26 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/test-perl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ jobs:
working-directory: perl

- name: run tests
run: |
prove -l
AUTHOR_TESTS=1 prove -l
run: make test
working-directory: perl

- name: run acceptance tests
Expand Down
1 change: 1 addition & 0 deletions perl/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ perl5/
.cpanfile_dependencies
cpanfile.snapshot
CHANGELOG.md
lib/Gherkin/Generated/Languages.pm
36 changes: 24 additions & 12 deletions perl/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
SHELL := /usr/bin/env bash

GHERKIN_PARSER = lib/Gherkin/Generated/Parser.pm
GHERKIN_LANGUAGES = lib/Generated/Languages.pm
GHERKIN_RAZOR = gherkin-perl.razor
SOURCE_FILES = $(shell find . -name "*.pm" | grep -v $(GHERKIN_PARSER))
SOURCE_FILES = $(shell find lib -name "*.pm" | grep -v $(GHERKIN_PARSER) | grep -v $(GHERKIN_LANGUAGES) )

GHERKIN = bin/gherkin
GHERKIN_GENERATE_TOKENS = bin/gherkin-generate-tokens
Expand All @@ -17,6 +18,11 @@ SOURCES = $(patsubst ../testdata/%,acceptance/testdata/%.source.ndjson,$(GO
ERRORS = $(patsubst ../testdata/%,acceptance/testdata/%.errors.ndjson,$(BAD_FEATURE_FILES))

.DEFAULT_GOAL = help

ARTIFACT_DIR = Gherkin-latest
ARTIFACT_DIR_VERSIONED = Gherkin-$(shell cat VERSION)
ARTIFACT_TAR_GZ = Gherkin-$(shell cat VERSION).tar.gz

PERL5LIB = $$PWD/perl5/lib/perl5
GHERKIN = PERL5LIB=${PERL5LIB} bin/gherkin
GHERKIN_GENERATE_TOKENS = PERL5LIB=${PERL5LIB} bin/gherkin-generate-tokens
Expand All @@ -29,30 +35,36 @@ generate: $(GHERKIN_PARSER) ## Generate gherkin parser files
clean-generate: ## Remove generated Gherkin parser files ## Generate gherkin parser files
rm -f $(GHERKIN_PARSER)

copy-gherkin-languages: # lib/Gherkin/Generated/Languages.pm ## Copy gherkin-languages.json and/or generate derived files
echo "TODO: Depends on perl, this task should only depend on jq"
copy-gherkin-languages:
echo "Nothing to do"

clean-gherkin-languages: ## Remove gherkin-languages.json and any derived files
# rm -f lib/Gherkin/Generated/Languages.pm
echo "TODO: Depends on perl, this task should only depend on jq"
echo "Nothing to do"

clean: ## Remove all build artifacts and files generated by the acceptance tests
rm -f .built
rm -rf $(ARTIFACT_DIR_VERSIONED)
rm -rf $(ARTIFACT_DIR)
rm -f $(ARTIFACT_TAR_GZ)
rm -rf acceptance
rm -rf perl5

.DELETE_ON_ERROR:

acceptance: .built $(TOKENS) $(ASTS) $(PICKLES) $(SOURCES) $(ERRORS) ## Build acceptance test dir and compare results with reference
.PHONY: test
test: perl5 ## Runs dzil test
PATH=$$PATH:perl5/bin PERL5LIB=${PERL5LIB} dzil test

acceptance: $(ARTIFACT_DIR) $(TOKENS) $(ASTS) $(PICKLES) $(ERRORS) $(SOURCES) ## Build acceptance test dir and compare results with reference

.built: perl5 $(SOURCE_FILES)
touch $@
$(ARTIFACT_DIR): $(ARTIFACT_DIR_VERSIONED)
cp -r $(ARTIFACT_DIR_VERSIONED) $@

$(ARTIFACT_DIR_VERSIONED): perl5 $(SOURCE_FILES)
PATH=$$PATH:perl5/bin PERL5LIB=${PERL5LIB} dzil build

perl5:
cpanm --notest --local-lib ./perl5 --installdeps --with-develop .

lib/Gherkin/Generated/Languages.pm:
perl helper-scripts/build_languages.pl > $@
PATH=$$PATH:perl5/bin PERL5LIB=${PERL5LIB} dzil authordeps --missing | cpanm --notest --local-lib ./perl5

$(GHERKIN_PARSER): $(GHERKIN_RAZOR) ../gherkin.berp
berp -g ../gherkin.berp -t $< -o $@ --noBOM
Expand Down
2 changes: 1 addition & 1 deletion perl/bin/gherkin
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use lib 'lib';
use lib 'Gherkin-latest/lib';

use App::gherkin;

Expand Down
2 changes: 1 addition & 1 deletion perl/bin/gherkin-generate-tokens
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use lib 'lib';
use lib 'Gherkin-latest/lib';

use Gherkin::Parser;
use Gherkin::TokenFormatterBuilder;
Expand Down
2 changes: 1 addition & 1 deletion perl/cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ on 'test' => sub {
};

on 'develop' => sub {
# there are no specific development dependencies...
requires "Dist::Zilla";
};
8 changes: 7 additions & 1 deletion perl/dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ exclude_filename=gherkin-perl.razor
exclude_filename=Makefile
exclude_filename=VERSION

[GatherFile]
[GatherFile / CHANGELOG.md]
; explicitly add unversioned files
root=../
filename=CHANGELOG.md

[GatherFile / GeneratedLanguages]
filename=lib/Gherkin/Generated/Languages.pm

[Hook::VersionProvider]
. = my $v = `cat ./VERSION`; chomp( $v ); $v;

[Run::BeforeBuild]
run = helper-scripts/build_languages.pl >lib/Gherkin/Generated/Languages.pm
7 changes: 0 additions & 7 deletions perl/lib/Gherkin/Generated/Languages.pm

This file was deleted.

0 comments on commit a14e79a

Please sign in to comment.