Skip to content

Commit

Permalink
More flexible --dev / --no-dev logic (#1520)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay committed Nov 15, 2018
1 parent ee79552 commit 2afe3af
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 31 deletions.
20 changes: 11 additions & 9 deletions Library/Command/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
*
* @package Zephir\Command
*/
class BuildCommand extends ContainerAwareCommand
class BuildCommand extends ContainerAwareCommand implements DevelopmentModeAwareInterface
{
use DevelopmentModeAwareTrait;

protected function configure()
{
$this
Expand All @@ -39,7 +41,7 @@ protected function configure()
)
->addOption('dev', null, InputOption::VALUE_NONE, 'Build the extension in development mode')
->addOption('no-dev', null, InputOption::VALUE_NONE, 'Build the extension in production mode')
->setHelp($this->getBuildDevHelp());
->setHelp($this->getDevelopmentModeHelp());
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -53,21 +55,21 @@ protected function execute(InputInterface $input, OutputInterface $output)

$command = $this->getApplication()->find('install');

$devMode = (bool) $input->getOption('no-dev');
if ($devMode == false) {
$devMode = $input->getOption('dev') || PHP_DEBUG;
}

$arguments = [
'command' => 'install',
'--backend' => $input->getOption('backend'),
'--dev' => $devMode,
'--dev' => $this->isDevelopmentModeEnabled($input),
];

return $command->run(new ArrayInput($arguments), $output);
}

private function getBuildDevHelp()
/**
* {@inheritdoc}
*
* @return string
*/
public function getDevelopmentModeHelp()
{
return <<<EOT
Generates/Compiles/Installs a Zephir extension.
Expand Down
22 changes: 13 additions & 9 deletions Library/Command/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
*
* @package Zephir\Command
*/
class CompileCommand extends ContainerAwareCommand
class CompileCommand extends ContainerAwareCommand implements DevelopmentModeAwareInterface
{
use DevelopmentModeAwareTrait;

protected function configure()
{
$this
Expand All @@ -38,7 +40,7 @@ protected function configure()
)
->addOption('dev', null, InputOption::VALUE_NONE, 'Compile the extension in development mode')
->addOption('no-dev', null, InputOption::VALUE_NONE, 'Compile the extension in production mode')
->setHelp($this->getCompileDevHelp());
->setHelp($this->getDevelopmentModeHelp());
}

protected function execute(InputInterface $input, OutputInterface $output)
Expand All @@ -50,18 +52,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
-W([a-z0-9\-]+) Turns a warning off
*/

$devMode = (bool) $input->getOption('no-dev');
if ($devMode == false) {
$devMode = $input->getOption('dev') || PHP_DEBUG;
}

// TODO: Move all the stuff from the compiler
$this->compiler->compile($devMode);
$this->compiler->compile(
$this->isDevelopmentModeEnabled($input)
);

return 0;
}

private function getCompileDevHelp()
/**
* {@inheritdoc}
*
* @return string
*/
public function getDevelopmentModeHelp()
{
return <<<EOT
Compile a Zephir extension.
Expand Down
32 changes: 32 additions & 0 deletions Library/Command/DevelopmentModeAwareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zephir\Command;

use Symfony\Component\Console\Input\InputInterface;

interface DevelopmentModeAwareInterface
{
/**
* Returns the development mode for the command.
*
* @return string
*/
public function getDevelopmentModeHelp();

/**
* Checks if the development mode is enabled.
*
* @param InputInterface $input
* @return bool
*/
public function isDevelopmentModeEnabled(InputInterface $input);
}
37 changes: 37 additions & 0 deletions Library/Command/DevelopmentModeAwareTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Zephir Team <team@zephir-lang.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Zephir\Command;

use Symfony\Component\Console\Input\InputInterface;

/**
* Zephir\Command\DevelopmentModeAwareTrait
*
* @package Zephir\Command
*/
trait DevelopmentModeAwareTrait
{
/**
* {@inheritdoc}
*
* @param InputInterface $input
* @return bool
*/
public function isDevelopmentModeEnabled(InputInterface $input)
{
if ($input->getOption('no-dev') == false) {
return $input->getOption('dev') || PHP_DEBUG;
}

return false;
}
}
22 changes: 13 additions & 9 deletions Library/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,36 @@
*
* @package Zephir\Command
*/
class InstallCommand extends ContainerAwareCommand
class InstallCommand extends ContainerAwareCommand implements DevelopmentModeAwareInterface
{
use DevelopmentModeAwareTrait;

protected function configure()
{
$this
->setName('install')
->setDescription('Installs the extension in the extension directory (may require root password)')
->addOption('dev', null, InputOption::VALUE_NONE, 'Install the extension in development mode')
->addOption('no-dev', null, InputOption::VALUE_NONE, 'Install the extension in production mode')
->setHelp($this->getInstallDevHelp());
->setHelp($this->getDevelopmentModeHelp());
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$devMode = (bool) $input->getOption('no-dev');
if ($devMode == false) {
$devMode = $input->getOption('dev') || PHP_DEBUG;
}

// TODO: Move all the stuff from the compiler
$this->compiler->install($devMode);
$this->compiler->install(
$this->isDevelopmentModeEnabled($input)
);

return 0;
}

private function getInstallDevHelp()
/**
* {@inheritdoc}
*
* @return string
*/
public function getDevelopmentModeHelp()
{
return <<<EOT
Installs the extension in the extension directory.
Expand Down
17 changes: 13 additions & 4 deletions Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,12 @@ public function getGccFlags($development = false)
$gccFlags = '-O0 -g3';
}
}

return $gccFlags;
}

// TODO
return '';
}

/**
Expand All @@ -624,8 +628,13 @@ public function getGccFlags($development = false)
*/
public function getPhpIncludeDirs()
{
// TODO: Add Windows support
if (!$this->environment->isWindows()) {
$this->fileSystem->system('php-config --includes', 'stdout', Zephir::VERSION . '/php-includes');
$this->fileSystem->system(
'php-config --includes',
'stdout',
escapeshellcmd(Zephir::VERSION) . '/php-includes'
);
}

return trim($this->fileSystem->read(Zephir::VERSION . '/php-includes'));
Expand Down Expand Up @@ -656,14 +665,14 @@ public function preCompileHeaders()
'cd ext && gcc -c kernel/' . $file->getBaseName() .
' -I. ' . $phpIncludes . ' -o kernel/' . $file->getBaseName() . '.gch',
'stdout',
Zephir::VERSION . '/compile-header'
escapeshellcmd(Zephir::VERSION) . '/compile-header'
);
} elseif (filemtime($path) > filemtime($path . '.gch')) {
$this->fileSystem->system(
'cd ext && gcc -c kernel/' . $file->getBaseName() .
' -I. ' . $phpIncludes . ' -o kernel/' . $file->getBaseName() . '.gch',
'stdout',
Zephir::VERSION . '/compile-header'
escapeshellcmd(Zephir::VERSION) . '/compile-header'
);
}
}
Expand Down Expand Up @@ -2249,7 +2258,7 @@ protected function getGccVersion()
return $this->fileSystem->read(Zephir::VERSION . '/gcc-version');
}

$this->fileSystem->system('gcc -v', 'stderr', Zephir::VERSION . '/gcc-version-temp');
$this->fileSystem->system('gcc -v', 'stderr', escapeshellcmd(Zephir::VERSION) . '/gcc-version-temp');
$lines = $this->fileSystem->file(Zephir::VERSION . '/gcc-version-temp');

foreach ($lines as $line) {
Expand Down

0 comments on commit 2afe3af

Please sign in to comment.