diff --git a/src/trgen/templates/PHP/st.build.ps1 b/src/trgen/templates/PHP/st.build.ps1 index 04173d049..31ddfc871 100644 --- a/src/trgen/templates/PHP/st.build.ps1 +++ b/src/trgen/templates/PHP/st.build.ps1 @@ -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 + -encoding -Dlanguage=PHP } > ; $compile_exit_code = $LASTEXITCODE) | Write-Host +antlr4 -v $tool_version -encoding -Dlanguage=PHP } > +$compile_exit_code = $LASTEXITCODE if($compile_exit_code -ne 0){ exit $compile_exit_code \} + }> $(& composer install ; $compile_exit_code = $LASTEXITCODE ) | Write-Host diff --git a/src/trgen/templates/PHP/st.build.sh b/src/trgen/templates/PHP/st.build.sh index 47a1bc985..b4143ea3b 100644 --- a/src/trgen/templates/PHP/st.build.sh +++ b/src/trgen/templates/PHP/st.build.sh @@ -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 -Dlanguage=PHP } > +antlr4 -v $tool_version -encoding -Dlanguage=PHP } > }> composer install