1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* Pickle |
5
|
|
|
* |
6
|
|
|
* |
7
|
|
|
* @license |
8
|
|
|
* |
9
|
|
|
* New BSD License |
10
|
|
|
* |
11
|
|
|
* Copyright © 2015-2015, Pickle community. All rights reserved. |
12
|
|
|
* |
13
|
|
|
* Redistribution and use in source and binary forms, with or without |
14
|
|
|
* modification, are permitted provided that the following conditions are met: |
15
|
|
|
* * Redistributions of source code must retain the above copyright |
16
|
|
|
* notice, this list of conditions and the following disclaimer. |
17
|
|
|
* * Redistributions in binary form must reproduce the above copyright |
18
|
|
|
* notice, this list of conditions and the following disclaimer in the |
19
|
|
|
* documentation and/or other materials provided with the distribution. |
20
|
|
|
* * Neither the name of the Hoa nor the names of its contributors may be |
21
|
|
|
* used to endorse or promote products derived from this software without |
22
|
|
|
* specific prior written permission. |
23
|
|
|
* |
24
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
25
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
26
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
27
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE |
28
|
|
|
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
29
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
30
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
31
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
32
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
33
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
34
|
|
|
* POSSIBILITY OF SUCH DAMAGE. |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
namespace Pickle\Base\Abstracts\Console\Command; |
38
|
|
|
|
39
|
|
|
use Exception; |
40
|
|
|
use Pickle\Base\Interfaces\Package; |
41
|
|
|
use Symfony\Component\Console\Command\Command; |
42
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
43
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
44
|
|
|
use Symfony\Component\Console\Input\InputOption; |
45
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
46
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
47
|
|
|
use Symfony\Component\Console\Question\Question; |
48
|
|
|
|
49
|
|
|
abstract class BuildCommand extends Command |
50
|
|
|
{ |
51
|
|
|
protected function configure() |
52
|
|
|
{ |
53
|
|
|
$this |
54
|
|
|
->addArgument( |
55
|
|
|
'path', |
56
|
|
|
InputArgument::OPTIONAL, |
57
|
|
|
'Path to the PECL extension root directory (default pwd), archive or extension name', |
58
|
|
|
getcwd() |
59
|
|
|
) |
60
|
|
|
->addOption( |
61
|
|
|
'no-convert', |
62
|
|
|
null, |
63
|
|
|
InputOption::VALUE_NONE, |
64
|
|
|
'Disable package conversion' |
65
|
|
|
) |
66
|
|
|
->addOption( |
67
|
|
|
'defaults', |
68
|
|
|
null, |
69
|
|
|
InputOption::VALUE_NONE, |
70
|
|
|
'Use defaults configure options values' |
71
|
|
|
)->addOption( |
72
|
|
|
'source', |
73
|
|
|
null, |
74
|
|
|
InputOption::VALUE_NONE, |
75
|
|
|
'use source package' |
76
|
|
|
)->addOption( |
77
|
|
|
'with-configure-options', |
78
|
|
|
null, |
79
|
|
|
InputOption::VALUE_REQUIRED, |
80
|
|
|
'path to the additional configure options' |
81
|
|
|
)->addOption( |
82
|
|
|
'save-logs', |
83
|
|
|
null, |
84
|
|
|
InputOption::VALUE_REQUIRED, |
85
|
|
|
'path to save the build logs' |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
protected function saveBuildLogs(InputInterface $input, $build) |
90
|
|
|
{ |
91
|
|
|
$save_log_path = $input->getOption('save-logs'); |
92
|
|
|
if ($save_log_path) { |
93
|
|
|
$build->saveLog($save_log_path); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function buildOptions(Package $package, InputInterface $input, OutputInterface $output) |
98
|
|
|
{ |
99
|
|
|
$helper = $this->getHelperSet()->get('question'); |
100
|
|
|
|
101
|
|
|
$configureOptions = $input->getOption('with-configure-options'); |
102
|
|
|
|
103
|
|
|
if ($configureOptions) { |
104
|
|
|
if (!file_exists($configureOptions) || is_dir($configureOptions) || !is_readable($configureOptions)) { |
105
|
|
|
throw new Exception("File '{$configureOptions}' is unusable"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (DIRECTORY_SEPARATOR !== '\\' && preg_match('_^/dev/fd/\d+$_', $configureOptions)) { |
109
|
|
|
// https://bugs.php.net/bug.php?id=53465 |
110
|
|
|
$configureOptions = str_replace('/dev/', 'php://', $configureOptions); |
111
|
|
|
} |
112
|
|
|
$configureOptions = preg_replace(',\\s+,', ' ', file_get_contents($configureOptions)); |
113
|
|
|
|
114
|
|
|
return [null, $configureOptions]; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$options = $package->getConfigureOptions(); |
118
|
|
|
$optionsValue = []; |
119
|
|
|
|
120
|
|
|
foreach ($options as $name => $opt) { |
121
|
|
|
/* enable/with-<extname> */ |
122
|
|
|
if ($name == $package->getName() || str_replace('-', '_', $name) == $package->getName()) { |
123
|
|
|
$optionsValue[$name] = (object) [ |
124
|
|
|
'type' => $opt->type, |
125
|
|
|
'input' => true, |
126
|
|
|
]; |
127
|
|
|
|
128
|
|
|
continue; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
if ($input->getOption('defaults')) { |
132
|
|
|
$value = $opt->default; |
133
|
|
|
} else { |
134
|
|
|
if ($opt->type == 'enable') { |
135
|
|
|
$prompt = new ConfirmationQuestion($opt->prompt . ' (default: ' . ($opt->default ? 'yes' : 'no') . '): ', $opt->default); |
136
|
|
|
} else { |
137
|
|
|
$prompt = new Question($opt->prompt . ' (default: ' . ($opt->default ?: '') . '): ', $opt->default); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
$value = $helper->ask($input, $output, $prompt); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$optionsValue[$name] = (object) [ |
144
|
|
|
'type' => $opt->type, |
145
|
|
|
'input' => $value, |
146
|
|
|
]; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
return [$optionsValue, null]; |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/* vim: set tabstop=4 shiftwidth=4 expandtab: fdm=marker */ |
154
|
|
|
|