Skip to content

Commit

Permalink
Update with code to extract runtime and tool version.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaby76 committed Sep 7, 2023
1 parent d46012f commit 4d79eb3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/trgen/templates/PHP/st.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,33 @@ if (Test-Path -Path transformGrammar.py -PathType Leaf) {
$(& python3 transformGrammar.py ) 2>&1 | Write-Host
}

# Find runtime version in composer.json file.
$runtime_version = (Get-Content -Path composer.json | Select-String 'antlr4').ToString().Split(':')[1].Trim(' ",\r\n')

# Get from online sources the commit version number that corresponds to the runtime version.
Remove-Item -Recurse -Force antlr4-php-runtime -ErrorAction SilentlyContinue
Invoke-WebRequest -Uri "https://packagist.org/packages/antlr/antlr4-php-runtime#$runtime_version" -OutFile antlr4-php-runtime
$commit_version = (Get-Content -Path antlr4-php-runtime | Select-String 'BSD-3-Clause').ToString().Split()[-1] -replace '\<.*', ''

# Checkout the sources from the php runtime repo.
Remove-Item -Recurse -Force antlr-php-runtime -ErrorAction SilentlyContinue
git clone https://github.com/antlr/antlr-php-runtime
Set-Location -Path antlr-php-runtime
git checkout $commit_version

# Extract the tool version this damn runtime version corresponds to.
$tool_version = (Get-Content -Path src/RuntimeMetaData.php | Select-String 'public const VERSION').ToString().Split()[-1].Trim("';")

Set-Location ..
Remove-Item -Recurse -Force antlr-php-runtime -ErrorAction SilentlyContinue

<tool_grammar_tuples:{x |
$(& java -jar <antlr_tool_path> <x.GrammarFileName> -encoding <antlr_encoding> -Dlanguage=PHP <x.AntlrArgs> <antlr_tool_args:{y | <y> } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host
antlr4 -v $tool_version -encoding <antlr_encoding> -Dlanguage=PHP <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
$compile_exit_code = $LASTEXITCODE
if($compile_exit_code -ne 0){
exit $compile_exit_code
\}

}>

$(& composer install ; $compile_exit_code = $LASTEXITCODE ) | Write-Host
Expand Down
25 changes: 23 additions & 2 deletions src/trgen/templates/PHP/st.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,31 @@ if [ -f transformGrammar.py ]; then python3 transformGrammar.py ; fi
# to manually look at the version in pubspec.yaml and extract the
# version number. We can then use this with antlr4 to generate the
# parser and lexer.
version=4.13.0; runtime_version=0.9.0

# This table lookup is caused because the PHP does not
# use the same version number as the tool.

# 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/;//'`
cd ..
rm -rf antlr4-php-runtime

<tool_grammar_tuples:{x |
antlr4 -v $version -encoding <antlr_encoding> -Dlanguage=PHP <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
antlr4 -v $tool_version -encoding <antlr_encoding> -Dlanguage=PHP <x.AntlrArgs> <antlr_tool_args:{y | <y> } > <x.GrammarFileName>
}>

composer install
Expand Down

0 comments on commit 4d79eb3

Please sign in to comment.