Skip to content

(messages) better class splitting in PHP version #1894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion messages/java/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ JSONSCHEMAS = $(shell find ../jsonschema -name "*.json")
.codegen: $(JSONSCHEMAS) ../jsonschema/scripts/codegen.rb ../jsonschema/scripts/templates/java.java.erb ../jsonschema/scripts/templates/java.enum.java.erb
ruby ../jsonschema/scripts/codegen.rb Java ../jsonschema java.java.erb > Generated.java.tmp
ruby ../jsonschema/scripts/codegen.rb Java ../jsonschema java.enum.java.erb >> Generated.java.tmp
csplit --quiet --prefix=Generated --suffix-format=%02d.java.tmp --elide-empty-files Generated.java.tmp /^.*.java$$/ {*}
csplit --quiet --prefix=Generated --suffix-format=%02d.java.tmp --elide-empty-files Generated.java.tmp /^.*[.]java$$/ {*}
rm Generated.java.tmp
rm -rf src/generated/java/io/cucumber/messages/types
mkdir --parents src/generated/java/io/cucumber/messages/types
Expand Down
8 changes: 7 additions & 1 deletion messages/jsonschema/scripts/templates/php.enum.php.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<% @enums.each do |enum| -%>
<%= enum[:name].split('\\').join('/') %>.php
<?php declare(strict_types=1);

/**
* This code was auto-generated by {this script}[https://github.com/cucumber/common/blob/main/messages/jsonschema/scripts/codegen.rb]
*/

<%- namespaces = enum[:name].split('\\') -%>
namespace Cucumber\Messages\<%= namespaces.slice(0,1)[0] %>;

// CLASS_START <%= enum[:name].split('\\').join('/') %>.php
enum <%= namespaces[-1] %> : string
{
<%- enum[:values].each_with_index do |value, index| -%>
Expand Down
4 changes: 2 additions & 2 deletions messages/jsonschema/scripts/templates/php.php.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%- @schemas.sort.each do |key, schema| -%>
<%= class_name(key) %>.php
<?php

declare(strict_types=1);
Expand All @@ -10,8 +12,6 @@ namespace Cucumber\Messages;

use JsonSerializable;
use Cucumber\Messages\DecodingException\SchemaViolationException;
<%- @schemas.sort.each do |key, schema| -%>
// CLASS_START <%= class_name(key) %>.php
/**
* Represents the <%= class_name(key) %> message in Cucumber's message protocol
* @see https://github.com/cucumber/common/tree/main/messages#readme
Expand Down
17 changes: 9 additions & 8 deletions messages/php/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ JSONSCHEMAS = $(shell find ../jsonschema -name "*.json")

clean: clean-build

.codegen: build/messages.php
.codegen: $(JSONSCHEMAS) ../jsonschema/scripts/codegen.rb ../jsonschema/scripts/templates/php.php.erb
ruby ../jsonschema/scripts/codegen.rb Php ../jsonschema php.php.erb > build/messages.php
ruby ../jsonschema/scripts/codegen.rb Php ../jsonschema php.enum.php.erb >> build/messages.php
csplit --quiet --prefix=build/Generated --suffix-format=%02d.php.tmp --elide-empty-files build/messages.php /^.*[.]php$$/ {*}
rm build/messages.php
rm -rf src-generated/*
for file in build/Generated**; do mkdir -p src-generated/$$(head -n 1 $$file | sed 's/[^/]*.php$$//'); done
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is required to make the subfolders - the sed ends up trying to make src-generated/ a bunch of times but I think it's harmless

for file in build/Generated**; do tail -n +2 $$file > src-generated/$$(head -n 1 $$file); rm $$file; done
vendor/bin/php-cs-fixer --diff fix src-generated

clean-build:
rm -rf build/messages.php
rm -rf src-generated/*

build/messages.php: $(JSONSCHEMAS) ../jsonschema/scripts/codegen.rb ../jsonschema/scripts/templates/php.php.erb
ruby ../jsonschema/scripts/codegen.rb Php ../jsonschema php.php.erb > $@
ruby ../jsonschema/scripts/codegen.rb Php ../jsonschema php.enum.php.erb >> $@
rm -rf src-generated/*
php split_classes.php
vendor/bin/php-cs-fixer --diff fix src-generated

.tested: .cs-fixer

.cs-fixer:
Expand Down
40 changes: 0 additions & 40 deletions messages/php/split_classes.php

This file was deleted.