Skip to content
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

#2284 - Review Zephir parser installation process #2285

Merged
merged 5 commits into from
Sep 18, 2021
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
37 changes: 0 additions & 37 deletions .ci/install-zephir-parser.sh

This file was deleted.

18 changes: 2 additions & 16 deletions .github/workflows/build-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- development

env:
ZEPHIR_PARSER_VERSION: v1.3.8
ZEPHIR_PARSER_VERSION: 1.4.1

jobs:
linux:
Expand Down Expand Up @@ -47,7 +47,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: gmp, pdo_sqlite, psr, zip
extensions: gmp, pdo_sqlite, psr, zip, zephir_parser-${{ env.ZEPHIR_PARSER_VERSION }}
tools: phpize, php-config
coverage: xdebug
# variables_order: https://github.com/zephir-lang/zephir/pull/1537
Expand Down Expand Up @@ -100,20 +100,6 @@ jobs:
sudo apt-get update --quiet --yes 1>/dev/null
sudo apt-get install --no-install-recommends -q -y re2c

- name: Get Zephir Parser Cache Key
id: pcache
run: echo ::set-output name=key::$(echo -n ${ZEPHIR_PARSER_VERSION}_${CPUHASH})

- name: Cache Zephir Parser
uses: actions/cache@v1
with:
path: ~/php-zephir-parser
key: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-${{ steps.pcache.outputs.key }}
restore-keys: ${{ runner.os }}-${{ matrix.php }}-zephir-parser-

- name: Install Zephir Parser
run: .ci/install-zephir-parser.sh

- name: Get Composer Cache Directory
id: composer-cache
run: echo ::set-output name=dir::$(composer config cache-files-dir)
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- development

env:
PARSER_VERSION: 1.3.8
PARSER_VERSION: 1.4.1
PARSER_RELEASE: 559
PHP_SDK_VERSION: 2.2.0
PHP_DEVPACK: C:\tools\php-devpack
Expand Down Expand Up @@ -120,10 +120,10 @@ jobs:
InstallZephirParser

- name: Enable Zephir Parser
run: Enable-PhpExtension -Extension 'Zephir Parser' -Path "${env:PHPROOT}"
run: Enable-PhpExtension -Extension zephir_parser -Path "${env:PHPROOT}"

- name: Minimal Zephir Parser Load Test
run: php --ri 'Zephir Parser'
run: php --ri zephir_parser

- name: "Setup Visual Studio Command Line for PHP SDK ${{ matrix.arch }}"
run: .ci\vsenv.bat -arch=${{ matrix.arch }} -host_arch=${{ matrix.arch }}
Expand Down
18 changes: 11 additions & 7 deletions Library/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,50 @@
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Zephir\Parser;

use Zephir\Exception\IllegalStateException;
use Zephir\Exception\InvalidArgumentException;
use Zephir\Exception\ParseException;

use function function_exists;

class Parser
{
/**
* Check if Zephir Parser available.
*
* @return bool
*/
public function isAvailable()
public function isAvailable(): bool
{
return \function_exists('zephir_parse_file');
return function_exists('zephir_parse_file');
}

/**
* Gets Zephir Parser version.
*
* @return string|null
*/
public function getVersion()
public function getVersion(): ?string
{
return phpversion('Zephir Parser') ?: null;
return phpversion('zephir_parser') ?: null;
}

/**
* Parses a file and returning an intermediate representation (IR).
*
* @param string $filePath Absolute path to the *.zep file
*
* @throws IllegalStateException
* @return array
* @throws InvalidArgumentException
* @throws ParseException
*
* @return array
* @throws IllegalStateException
*/
public function parse($filePath)
public function parse(string $filePath): array
{
if (!$this->isAvailable()) {
throw new IllegalStateException("Zephir Parser extension couldn't be loaded.");
Expand Down
22 changes: 3 additions & 19 deletions docker/7.4/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.0.8 as composer
FROM composer:latest as composer
FROM php:7.4-fpm

RUN CPU_CORES="$(getconf _NPROCESSORS_ONLN)";
Expand All @@ -13,26 +13,10 @@ RUN apt update -y && apt install -y \
libicu-dev \
libgmp-dev \
libzip-dev && \
pecl install psr
pecl install psr zephir_parser

RUN docker-php-ext-install zip gmp intl mysqli && \
docker-php-ext-enable psr

# Install Zephir parser
RUN PHP_INI_DIR="$(dirname "$(php -i | grep /.+/conf.d/.+.ini -oE | head -n 1)")" && \
cd /opt && \
git clone -b "development" \
--depth 1 \
-q https://github.com/phalcon/php-zephir-parser \
php-zephir-parser && \
cd php-zephir-parser || exit 1 && \
phpize && \
./configure --with-php-config="$(command -v php-config)" --enable-zephir_parser && \
make -j"$(getconf _NPROCESSORS_ONLN)" && \
sudo make install && \
echo 'extension="zephir_parser.so"' |\
sudo tee "$PHP_INI_DIR/zephir_parser.ini" && \
php --ri "Zephir Parser"
docker-php-ext-enable psr zephir_parser

COPY --from=composer /usr/bin/composer /usr/local/bin/composer

Expand Down
22 changes: 3 additions & 19 deletions docker/8.0/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.0.8 as composer
FROM composer:latest as composer
FROM php:8.0-fpm

RUN CPU_CORES="$(getconf _NPROCESSORS_ONLN)";
Expand All @@ -13,26 +13,10 @@ RUN apt update -y && apt install -y \
libicu-dev \
libgmp-dev \
libzip-dev && \
pecl install psr
pecl install psr zephir_parser

RUN docker-php-ext-install zip gmp intl mysqli && \
docker-php-ext-enable psr

# Install Zephir parser
RUN PHP_INI_DIR="$(dirname "$(php -i | grep /.+/conf.d/.+.ini -oE | head -n 1)")" && \
cd /opt && \
git clone -b "development" \
--depth 1 \
-q https://github.com/phalcon/php-zephir-parser \
php-zephir-parser && \
cd php-zephir-parser || exit 1 && \
phpize && \
./configure --with-php-config="$(command -v php-config)" --enable-zephir_parser && \
make -j"$(getconf _NPROCESSORS_ONLN)" && \
sudo make install && \
echo 'extension="zephir_parser.so"' |\
sudo tee "$PHP_INI_DIR/zephir_parser.ini" && \
php --ri "Zephir Parser"
docker-php-ext-enable psr zephir_parser

COPY --from=composer /usr/bin/composer /usr/local/bin/composer

Expand Down