|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the SVN-Buddy library. |
|
4
|
|
|
* For the full copyright and license information, please view |
|
5
|
|
|
* the LICENSE file that was distributed with this source code. |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
|
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Command\Dev; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Command\AbstractCommand; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
use Symfony\Component\Process\ProcessBuilder; |
|
19
|
|
|
|
|
20
|
|
|
class PharCreateCommand extends AbstractCommand |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
$this |
|
29
|
|
|
->setName('dev:phar-create') |
|
30
|
|
|
->setDescription( |
|
31
|
|
|
'Creates PHAR for new release' |
|
32
|
|
|
) |
|
33
|
|
|
->addOption( |
|
34
|
|
|
'build-dir', |
|
35
|
|
|
null, |
|
36
|
|
|
InputOption::VALUE_REQUIRED, |
|
37
|
|
|
'Directory, where build results would be stored', |
|
38
|
|
|
'build' |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
parent::configure(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
48
|
|
|
{ |
|
49
|
|
|
$build_dir = realpath($this->io->getOption('build-dir')); |
|
50
|
|
|
$repository_path = realpath(__DIR__ . '/../../../../'); |
|
51
|
|
|
|
|
52
|
|
|
$phar_file = $build_dir . '/svn-buddy.phar'; |
|
53
|
|
|
$signature_file = $phar_file . '.sig'; |
|
54
|
|
|
|
|
55
|
|
|
$box_config = json_decode(file_get_contents($repository_path . '/box.json.dist'), true); |
|
56
|
|
|
$box_config['output'] = $phar_file; |
|
57
|
|
|
|
|
58
|
|
|
file_put_contents( |
|
59
|
|
|
$repository_path . '/box.json', |
|
60
|
|
|
json_encode($box_config, defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
$box_cli = trim($this->_shellCommand('which', array('box'))); |
|
64
|
|
|
$this->_shellCommand('php', array('-d', 'phar.readonly=0', $box_cli, 'build'), $repository_path); |
|
65
|
|
|
|
|
66
|
|
|
file_put_contents( |
|
67
|
|
|
$signature_file, |
|
68
|
|
|
$this->_shellCommand('sha1sum', array(basename($phar_file)), dirname($phar_file)) |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$this->io->writeln('Phar created successfully.'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Runs command. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $command Command. |
|
78
|
|
|
* @param array $arguments Arguments. |
|
79
|
|
|
* @param string|null $working_directory Working directory. |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
|
|
private function _shellCommand($command, array $arguments = array(), $working_directory = null) |
|
84
|
|
|
{ |
|
85
|
|
|
$final_arguments = array_merge(array($command), $arguments); |
|
86
|
|
|
|
|
87
|
|
|
$process = ProcessBuilder::create($final_arguments) |
|
88
|
|
|
->setWorkingDirectory($working_directory) |
|
89
|
|
|
->getProcess(); |
|
90
|
|
|
|
|
91
|
|
|
return $process->mustRun()->getOutput(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
} |
|
95
|
|
|
|