-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
Copy pathnext-version.php
executable file
·100 lines (87 loc) · 3.21 KB
/
next-version.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
#!/usr/bin/env php
<?php
class Version
{
public $major;
public $minor;
public $release;
public $extra;
public $api;
const REGX_MAJOR = '#define\s+SWOOLE_MAJOR_VERSION\s+(\d+)#';
const REGX_MINOR = '#define\s+SWOOLE_MINOR_VERSION\s+(\d+)#';
const REGX_RELEASE = '#define\s+SWOOLE_RELEASE_VERSION\s+(\d+)#';
const REGX_EXTRA = '#define\s+SWOOLE_EXTRA_VERSION\s+"(\w*)"#';
const REGX_API = '#define\s+SWOOLE_API_VERSION_ID\s+(0x[0-9a-f]*)#';
function getVersion()
{
$version = implode('.', [$this->major, $this->minor, $this->release]);
if ($this->extra) {
$version .= '-' . $this->extra;
}
return $version;
}
function getVersionId()
{
return intval(sprintf('%d%02d%02d', $this->major, $this->minor, $this->release));
}
function match($versionInfo) {
preg_match(Version::REGX_MAJOR, $versionInfo, $match_major) or die('no match MAJOR_VERSION');
preg_match(Version::REGX_MINOR, $versionInfo, $match_minor) or die('no match MAJOR_MINOR');;
preg_match(Version::REGX_RELEASE, $versionInfo,
$match_release) or die('no match RELEASE_VERSION');;
preg_match(Version::REGX_EXTRA, $versionInfo, $match_extra) or die('no match EXTRA_VERSION');
preg_match(Version::REGX_API, $versionInfo, $match_api) or die('no match API_VERSION_ID');
$this->major = intval($match_major[1]);
$this->minor = intval($match_minor[1]);
$this->release = intval($match_release[1]);
$this->extra = trim($match_extra[1]);
$this->api = trim($match_api[1]);
}
}
$type = empty($argv[1]) ? 'release' : trim($argv[1]);
$kernel_version_file = dirname(__DIR__) . '/include/swoole_version.h';
$cmake_file = dirname(__DIR__) . '/CMakeLists.txt';
$package_file = dirname(__DIR__) . '/package.xml';
$current = new Version;
$current->match(file_get_contents($kernel_version_file));
$next = clone $current;
if ($type == 'release') {
if ($current->extra == '') {
$next->release++;
$next->extra = 'dev';
} else {
$next->extra = '';
}
} elseif ($type == 'minor') {
$next->minor++;
$next->release = 0;
$next->extra = 'dev';
} elseif ($type == 'major') {
$next->major++;
$next->minor = 0;
$next->release = 0;
$next->extra = 'dev';
} elseif ($type == 'api') {
$date = substr($current->api, 2, strlen($current->api) - 3);
if ($date == date('Ym')) {
$c = substr($current->api, -1, 1);
if ($c == 'f') {
throw new RuntimeException("maximum exceeded[$current->api]");
}
$next->api = '0x' . $date . chr(ord($c) + 1);
} else {
$next->api = '0x' . date('Ym') . 'a';
}
} else {
exit("wrong version type");
}
if (empty($next->extra)) {
$doc = file_get_contents($package_file);
file_put_contents($package_file, str_replace($current->getVersion(), $next->getVersion(), $doc));
}
ob_start();
include __DIR__ . '/templates/version.tpl.h';
file_put_contents($kernel_version_file, ob_get_clean());
file_put_contents($cmake_file,
preg_replace('#set\(SWOOLE_VERSION\s+[0-9\.\-a-z]+\)#i', 'set(SWOOLE_VERSION ' . $next->getVersion() . ')',
file_get_contents($cmake_file)));