antlr / antlr-php-runtime

PHP Runtime for ANTLR4
BSD 3-Clause "New" or "Revised" License
81 stars 19 forks source link

PHP package numbers should be identical to the version for Antlr. #39

Open kaby76 opened 1 year ago

kaby76 commented 1 year ago

✨ Feature request

Right now, packagist has version 0.8.0 of the PHP runtime for Antlr. That corresponds to Antlr 4.12.0. We have a new version for Antlr 4.13.0, and there should be a new version of the PHP runtime for Antlr. But, it would be best to have antlr4-php-runtime use version numbers correspond exactly to Antlr tool version, and which are used in all the other targets, e.g., 4.13.0. Antlr programs cannot use different runtime versions with the tool.

Motivation

Dependabot in Github parses build specification files and issues update PRs when an Antlr runtime is released. But, building an Antlr program also requires the Antlr tool version to match. I can run the antlr4 tool with a -v 4.13.0 option, where the version is extracted from a PHP Composer file, but I then have to map the runtime version string there for PHP Antlr of 0.9.0 to 4.13.0. This makes Dependabot useless for PHP because I don't know what the mapping is aprori. Will 0.10.0 map to 4.14.0 or 4.13.1 or what??? I don't know the mapping until the PHP Antlr runtime is actually released.

Alternatives

Manually update the PHP Antlr version and Antlr tool version in the templates for grammars-v4, and don't let Dependabot analyse PHP Composer files.

Additional context

Templates for PHP are here. The Dependabot update for PHP is here.

kaby76 commented 1 year ago

I am planning to re-add the testing of PHP targets for grammars-v4, fixing https://github.com/antlr/grammars-v4/issues/3125

I have a workaround that finds the tool version that corresponds to the Antlr PHP runtime version in the composer.json file for a PHP driver. Not pretty, but it'll work as long as there are no major changes in how the package is published, how it is stored in the repo, and the version string in the source code.

The workaround involves a Bash script to extract the tool version from the source at https://github.com/antlr/antlr-php-runtime/blob/1ebacfd8a9761dc14509c305887d43899f1e18c5/src/RuntimeMetaData.php#L54

But, this is not easy. And, it is fragile. But, there is no other solution. Every target tested in grammars-v4 is with potentially a different version of Antlr because the runtimes are published independently of each other.

Script:

    # Find runtime version in composer.json file.
    runtime_version=`grep antlr4 composer.json | awk '{print $2}' | tr -d '\r' | tr -d '\n' | tr -d ',' | tr -d '"'`

    # Get from online sources the commit version number that corresponds to the runtime version.
    rm -rf antlr4-php-runtime
    wget "https://packagist.org/packages/antlr/antlr4-php-runtime#$runtime_version"
    commit_version=`grep BSD-3-Clause antlr4-php-runtime | awk '{print $NF}' | sed 's/<.*//'`

    # Checkout the sources from the php runtime repo.
    rm -rf antlr4-php-runtime
    git clone https://github.com/antlr/antlr-php-runtime
    cd antlr-php-runtime
    git checkout $commit_version

    # Extract the tool version this damn runtime version corresponds to.
    tool_version=`grep 'public const VERSION' src/RuntimeMetaData.php | awk '{print $NF}' | sed "s/'//g" | sed 's/;//'`

    # Run the antlr4 tool.
    # antlr4 -version $tool_version ......