-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpantrfile.php
236 lines (214 loc) · 6.02 KB
/
pantrfile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
/*
* Copyright (c) 2010 Patrick Gotthardt
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
namespace pantr\file;
use pantr\pantr;
use pantr\ext\File;
use pantr\ext\PHPUnit;
use Pagosoft\PSpec\Spec;
use pantr\ext\Pirum;
use pantr\ext\Pearfarm\PackageSpec;
setDefault('build');
$version = trim(`git describe`);
property('pantr.version', $version);
property('pear.channel', 'pear.pagosoft.com');
// global namespace
task('clean', 'Remove unused files', function() {
silent('clean', 'Cleaning up', function() {
// get rid of .DS_Store files
rm(find('.DS_Store')->in('src'));
rm('build', true);
rm('dist', true);
});
});
/** @hidden */
task('test:init', function() {
require_once 'test/bootstrap.php';
});
/**
* Run PHPUnit tests.
* @option v:verbose display details
* @dependsOn test:init
*/
task('test:unit', function($req) {
$tests = fileset('*Test.php')->in('test/unit');
return PHPUnit::forAllTests($tests)->run(isset($req['verbose']), 'test:unit');
});
/**
* Runs PSpec tests
*
* @dependsOn test:init
*/
task('test:spec', function($req) {
$result = Spec::run('test/spec', array(
'verbose' => isset($req['verbose']),
'taskname' => 'test:spec'
));
});
/**
* Runs PSpec "integration" tests - might take a while
*
* @dependsOn test:init
*/
task('test:integration', function($req) {
return Spec::run('test/integration', array(
'verbose' => isset($req['verbose']),
'taskname' => 'test:integration'
));
});
/**
* Test all
* @dependsOn test:unit, test:spec
*/
task('test');
// config
/**
* Configures pantr to create a local pear package
*
* @needsRequest
* @hidden
*/
task('config:deploy-local',function($req) {
if(isset($req['l'])) {
writeAction('switch', 'to local pear channel');
property('pear.channel', 'pear.localhost');
property('pear.dir', __DIR__.'/../lpear');
}
});
/**
* Install/remove channels and packages
*/
task('deps', function() {
pantr::dependencies()->in('lib')
->fromChannel('pear.pagosoft.com')
->usePackage('util')
->usePackage('cli')
->usePackage('parser')
->fromChannel('pear.php-tools.net')
->usePackage('vfsstream', 'alpha')
->fromChannel('pear.symfony-project.com')
->usePackage('yaml')
->sync();
});
// build process
/**
* Create build directory
*
* @dependsOn clean
*/
task('build:init', function() {
$lib = find()
// we don't want to distribute vfsStream
->prune('vfsStream')->discard('vfsStream')
->prune('pear')->discard('pear') // or pear
->prune('data')->discard('data')
// or the IOC-documentation and tests
->prune('doc')->discard('doc')
->prune('test')->discard('test')
// and no hidden files!
->prune('.*')->discard('.*')
->not_name('.*')
->ignore_version_control()
->in('lib');
// copy source files
mkdirs('build/pantr');
mirror($lib, 'build/pantr', pantr::SILENT);
mirror(find()->in('src'), 'build/pantr', pantr::SILENT);
// and executables
mkdirs('build/bin');
copy('bin/pantr', 'build/bin/pantr');
copy('bin/pantr.bat', 'build/bin/pantr.bat');
});
/**
* Creates a PEAR package
*
* @dependsOn test, build:init
* @before config:deploy-local
*/
task('build:package', function() {
$spec = PackageSpec::in('build')
->setName('pantr')
->setChannel(property('pear.channel'))
->setSummary('pantr is a simple php build tool.')
->setDescription('pantr is a simple php build tool.')
->setNotes('n/a')
->setVersion(property('pantr.version'))
->setStability('beta')
->setLicense(PackageSpec::LICENSE_MIT)
->addMaintainer('lead', 'Patrick Gotthardt', 'pago', '[email protected]')
->setDependsOnPHPVersion('5.3.0')
->addFiles(fileset()
->ignore_version_control()
->relative()
->in('build'))
->addFiles(array('bin/pantr', 'bin/pantr.bat'))
->addExecutable('bin/pantr')
->addExecutable('bin/pantr.bat', null, PackageSpec::PLATFORM_WIN)
->createPackage('dist');
});
// compilation
File::task('build:services', 'build/pantr/pantr/core/services.yml', ':dirname/:filename.php')
->dependsOn('build:init')
->run(function($src, $target) {
// compile dependency injection layer
$sc = new \sfServiceContainerBuilder();
$loader = new \sfServiceContainerLoaderFileYaml($sc);
$loader->load($src);
$dumper = new \sfServiceContainerDumperPhp($sc);
$code = $dumper->dump(array('class' => 'pantrContainer'));
file_put_contents($target, $code);
});
/**
* Updates the version number in the pantr.php file
*
* @hidden
* @dependsOn build:init
*/
task('build:version', function() {
// update version number
replace_in('build/pantr/pantr/pantr.php', function($f, $c) {
writeAction('rewrite', $f);
return str_replace(
"const VERSION='DEV';",
"const VERSION='".property('pantr.version')."';",
$c
);
});
});
/**
* Builds the project
*
* @dependsOn build:init, build:services, build:version, build:package
*/
task('build');
// publish
/**
* Publish the pear package on pear channel
*
* @dependsOn build
* @option l deploy to local PEAR server
* @option version The release version
*/
task('deploy', function($args) {
Pirum::onChannel(property('pear.dir'))
->addLatestVersion('dist');
});