Skip to content

Commit

Permalink
Move cache and logs to the common place
Browse files Browse the repository at this point in the history
Keep per-project cache locally
  • Loading branch information
sergeyklay committed Feb 23, 2019
1 parent a3c4271 commit 4a825b8
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 109 deletions.
12 changes: 4 additions & 8 deletions .ci/build-test-ext.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,14 @@
set -eu

# This allows the configuration of the executable path as follows:
# ZEPHIR_COMPILER_BIN=zephir.phar .ci/build-test-ext.sh
# ZEPHIR_COMPILER_BIN=./zephir .ci/build-test-ext.sh
: ${ZEPHIR_COMPILER_BIN:=zephir}
# ZEPHIR_BIN=zephir.phar .ci/build-test-ext.sh
# ZEPHIR_BIN=./zephir .ci/build-test-ext.sh
: ${ZEPHIR_BIN:=zephir}

project_root=$(readlink -enq "$(dirname $0)/../")
gcov_report=${project_root}/unit-tests/output/lcov.info

alias zephir="${ZEPHIR_COMPILER_BIN}"

project_root=$(readlink -enq "$(dirname $0)/../")

gcov_report=${project_root}/unit-tests/output/lcov.info
alias zephir="${ZEPHIR_BIN}"

zephir clean 2>&1 || exit 1
zephir fullclean 2>&1 || exit 1
Expand Down
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Changed
- Moved internal cache and logs to the user's home directory.
- On macOS Zephir will use `XDG` if it is possible, otherwise `$HOME/Library`
- On Windows Zephir will use `LOCALAPPDATA` if it is possible, otherwise home dir as a base path
- In any other cases, e.g. Linux, BSD and so on, Zephir will use `XDG`if it is possible,
otherwise `$HOME/.local` and `$HOME/.cache`
- Per project cache used for temporary operations was moved to `%CWD%/.zephir/%VERSION%`
where `%CWD%` is the current working directory and `%VERSION%` is the current Zephir version e.g. `0.11.8-4495e75`

### Fixed
- Array of object as return type is reported to PHP as type, not array
[#1779](https://github.com/phalcon/zephir/issues/1779)
- Use namespace as a prefix for ini name [#1604](https://github.com/phalcon/zephir/issues/1604)
- Fixed calling anonymous functions by resolving context [#1751](https://github.com/phalcon/zephir/issues/1751)
- Fixed a bug when accessing super-global variables that do not exist (for PHP >= 7.0 )
- Fixed a bug when accessing super-global variables that do not exist (only for PHP >= 7.0 )
[#1775](https://github.com/phalcon/zephir/issues/1775)
- Fixed incorrect behavior during work with ArrayAccess [1061](https://github.com/phalcon/zephir/issues/1061),
[1400](https://github.com/phalcon/zephir/issues/1400)

## [0.11.9] - 2019-01-15
- Fixed `zend_closure` declaration to reflect PHP 7.3 changes
Expand Down
72 changes: 32 additions & 40 deletions Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,37 @@ final class Compiler
public $functionDefinitions = [];

/** @var CompilerFile[] */
protected $files = [];
private $files = [];

/** @var string[] */
protected $anonymousFiles = [];
private $anonymousFiles = [];

/**
* Additional initializer code.
* Used for static property initialization.
*
* @var array
*/
protected $internalInitializers = [];
private $internalInitializers = [];

/** @var ClassDefinition[] */
protected $definitions = [];
private $definitions = [];

/** @var string[] */
protected $compiledFiles = [];
private $compiledFiles = [];

protected $constants = [];
private $constants = [];

protected $globals = [];
private $globals = [];

protected $externalDependencies = [];
private $externalDependencies = [];

/** @var ClassDefinition[] */
protected static $internalDefinitions = [];
private static $internalDefinitions = [];

protected static $loadedPrototypes = false;
private static $loadedPrototypes = false;

protected $extraFiles = [];
private $extraFiles = [];

/** @var Config */
private $config;
Expand Down Expand Up @@ -254,9 +254,7 @@ public function loadExternalClass($className, $location)
/**
* Fix the class name.
*/
$className = implode('\\', array_map(function ($i) {
return ucfirst($i);
}, explode('\\', $className)));
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));

if (isset($this->files[$className])) {
return true;
Expand Down Expand Up @@ -287,10 +285,8 @@ public function loadExternalClass($className, $location)
public function isClass($className)
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className)) {
if ('class' == $value->getType()) {
return true;
}
if (!strcasecmp($key, $className) && 'class' === $value->getType()) {
return true;
}
}

Expand Down Expand Up @@ -322,10 +318,8 @@ public function isClass($className)
public function isInterface($className)
{
foreach ($this->definitions as $key => $value) {
if (!strcasecmp($key, $className)) {
if ('interface' == $value->getType()) {
return true;
}
if (!strcasecmp($key, $className) && 'interface' === $value->getType()) {
return true;
}
}

Expand Down Expand Up @@ -491,7 +485,7 @@ public function getGccFlags($development = false)
$gccFlags = getenv('CFLAGS');

if (!\is_string($gccFlags)) {
if (false == $development) {
if (false === $development) {
$gccVersion = $this->getGccVersion();
if (version_compare($gccVersion, '4.6.0', '>=')) {
$gccFlags = '-O2 -fvisibility=hidden -Wparentheses -flto -DZEPHIR_RELEASE=1';
Expand Down Expand Up @@ -833,7 +827,7 @@ public function compile($development = false)
$extensionName = $namespace;
}

$needConfigure = $this->generate(false);
$needConfigure = $this->generate();

if ($needConfigure) {
if (is_windows()) {
Expand Down Expand Up @@ -1033,7 +1027,7 @@ public function install($development = false)
exec($command, $output, $exit);
$fileName = $this->config->get('extension-name') ?: $namespace;

if (false == file_exists("{$currentDir}/ext/modules/{$fileName}.so")) {
if (false === file_exists("{$currentDir}/ext/modules/{$fileName}.so")) {
throw new CompilerException(
'Internal extension compilation failed. Check compile-errors.log for more information.'
);
Expand Down Expand Up @@ -1966,7 +1960,7 @@ public function generatePackageDependenciesM4($contentM4)
*
* @throws IllegalStateException
*/
protected function preCompile($filePath)
private function preCompile($filePath)
{
if (!$this->parserManager->isAvailable()) {
throw new IllegalStateException($this->parserManager->requirements());
Expand All @@ -1976,9 +1970,7 @@ protected function preCompile($filePath)
$className = str_replace(\DIRECTORY_SEPARATOR, '\\', $filePath);
$className = preg_replace('#.zep$#', '', $className);

$className = implode('\\', array_map(function ($i) {
return ucfirst($i);
}, explode('\\', $className)));
$className = implode('\\', array_map('ucfirst', explode('\\', $className)));

$compilerFile = $this->compilerFileFactory->create($className, $filePath);
$compilerFile->preCompile($this);
Expand All @@ -1996,7 +1988,7 @@ protected function preCompile($filePath)
* @throws IllegalStateException
* @throws InvalidArgumentException
*/
protected function recursivePreCompile($path)
private function recursivePreCompile($path)
{
if (!is_dir($path)) {
throw new InvalidArgumentException(
Expand Down Expand Up @@ -2044,7 +2036,7 @@ protected function recursivePreCompile($path)
*
* @return bool
*/
protected function recursiveProcess($src, $dest, $pattern = null, $callback = 'copy')
private function recursiveProcess($src, $dest, $pattern = null, $callback = 'copy')
{
$success = true;
$iterator = new \DirectoryIterator($src);
Expand Down Expand Up @@ -2081,7 +2073,7 @@ protected function recursiveProcess($src, $dest, $pattern = null, $callback = 'c
* @param string $path Directory to deletes files
* @param string $mask Regular expression to deletes files
*/
protected function recursiveDeletePath($path, $mask)
private function recursiveDeletePath($path, $mask)
{
if (!file_exists($path) || !is_dir($path) || !is_readable($path)) {
$this->logger->warning("Directory '{$path}' is not readable. Skip...");
Expand All @@ -2108,7 +2100,7 @@ protected function recursiveDeletePath($path, $mask)
*
* @throws Exception
*/
protected function loadConstantsSources($constantsSources)
private function loadConstantsSources($constantsSources)
{
foreach ($constantsSources as $constantsSource) {
if (!file_exists($constantsSource)) {
Expand All @@ -2135,7 +2127,7 @@ protected function loadConstantsSources($constantsSources)
*
* @return array
*/
protected function processAddSources($sources, $project)
private function processAddSources($sources, $project)
{
$groupSources = [];
foreach ($sources as $source) {
Expand All @@ -2159,7 +2151,7 @@ protected function processAddSources($sources, $project)
*
* @throws RuntimeException
*/
protected function assertRequiredExtensionsIsPresent()
private function assertRequiredExtensionsIsPresent()
{
$extensionRequires = $this->config->get('extensions', 'requires');
if (true === empty($extensionRequires)) {
Expand Down Expand Up @@ -2191,7 +2183,7 @@ protected function assertRequiredExtensionsIsPresent()
*
* @return bool
*/
protected function checkKernelFile($src, $dst)
private function checkKernelFile($src, $dst)
{
if (preg_match('#kernels/ZendEngine[2-9]/concat\.#', $src)) {
return true;
Expand All @@ -2211,7 +2203,7 @@ protected function checkKernelFile($src, $dst)
*
* @return bool
*/
protected function checkKernelFiles()
private function checkKernelFiles()
{
$kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel';

Expand Down Expand Up @@ -2251,7 +2243,7 @@ protected function checkKernelFiles()
*
* @return string
*/
protected function checkDirectory()
private function checkDirectory()
{
$namespace = $this->config->get('namespace');
if (!$namespace) {
Expand Down Expand Up @@ -2286,7 +2278,7 @@ protected function checkDirectory()
*
* @return string
*/
protected function getGccVersion()
private function getGccVersion()
{
if (is_windows()) {
return '0.0.0';
Expand All @@ -2301,7 +2293,7 @@ protected function getGccVersion()
$lines = array_filter($lines);

$lastLine = $lines[\count($lines) - 1];
if (preg_match('/[0-9]+\.[0-9]+\.[0-9]+/', $lastLine, $matches)) {
if (preg_match('/\d+\.\d+\.\d+/', $lastLine, $matches)) {
return $matches[0];
}

Expand Down
6 changes: 3 additions & 3 deletions Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* (c) Zephir Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Zephir;
Expand Down Expand Up @@ -787,7 +787,7 @@ public function checkDependencies(Compiler $compiler)
public function compile(Compiler $compiler, StringsManager $stringsManager)
{
if (!$this->ir) {
throw new CompilerException('IR related to compiled file is missing');
throw new CompilerException('Unable to locate the intermediate representation of the compiled file');
}

/*
Expand Down
18 changes: 14 additions & 4 deletions Library/Console/Command/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Zephir\Compiler;
use Zephir\Exception\CompilerException;

/**
* Zephir\Console\Command\CompileCommand.
Expand Down Expand Up @@ -50,10 +52,18 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
// TODO: Move all the stuff from the compiler
$this->compiler->compile(
$this->isDevelopmentModeEnabled($input)
);
$io = new SymfonyStyle($input, $output);

try {
// TODO: Move all the stuff from the compiler
$this->compiler->compile(
$this->isDevelopmentModeEnabled($input)
);
} catch (CompilerException $e) {
$io->error($e->getMessage());

return 1;
}

return 0;
}
Expand Down
Loading

0 comments on commit 4a825b8

Please sign in to comment.