Skip to content

Commit

Permalink
Update version id
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Nov 2, 2021
1 parent 24cb6c2 commit 350946c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT(libswoole)

ENABLE_LANGUAGE(ASM)
set(SWOOLE_VERSION 4.8.1)
set(SWOOLE_VERSION 4.8.2-dev)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -g")
Expand Down
8 changes: 4 additions & 4 deletions include/swoole_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

#define SWOOLE_MAJOR_VERSION 4
#define SWOOLE_MINOR_VERSION 8
#define SWOOLE_RELEASE_VERSION 1
#define SWOOLE_EXTRA_VERSION ""
#define SWOOLE_VERSION "4.8.1"
#define SWOOLE_VERSION_ID 40801
#define SWOOLE_RELEASE_VERSION 2
#define SWOOLE_EXTRA_VERSION "dev"
#define SWOOLE_VERSION "4.8.2-dev"
#define SWOOLE_VERSION_ID 40802
#define SWOOLE_API_VERSION_ID 0x202109a

#define SWOOLE_BUG_REPORT \
Expand Down
49 changes: 31 additions & 18 deletions tools/next-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ class Version
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()
{
Expand All @@ -26,26 +28,30 @@ 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';

$versionInfo = file_get_contents($kernel_version_file);

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');

$current = new Version;
$current->major = intval($match_major[1]);
$current->minor = intval($match_minor[1]);
$current->release = intval($match_release[1]);
$current->extra = trim($match_extra[1]);
$current->match(file_get_contents($kernel_version_file));

$next = clone $current;

Expand All @@ -65,17 +71,24 @@ function getVersionId()
$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 = new DOMDocument();
$doc->load($package_file);
$versions = $doc->getElementsByTagName("version");
$versions[0]->getElementsByTagName('release')->item(0)->nodeValue = $next->getVersion();
$versions[0]->getElementsByTagName('api')->item(0)->nodeValue = $next->major . '.0';
$doc->save($package_file);
$doc = file_get_contents($package_file);
file_put_contents($package_file, str_replace($current->getVersion(), $next->getVersion(), $doc));
}

ob_start();
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/version.tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define SWOOLE_EXTRA_VERSION "<?=$next->extra ?>"
#define SWOOLE_VERSION "<?=$next->getVersion() ?>"
#define SWOOLE_VERSION_ID <?=$next->getVersionId()."\n" ?>
#define SWOOLE_API_VERSION_ID 0x202012a
#define SWOOLE_API_VERSION_ID <?=$next->api."\n" ?>

#define SWOOLE_BUG_REPORT \
"A bug occurred in Swoole-v" SWOOLE_VERSION ", please report it.\n" \
Expand Down

0 comments on commit 350946c

Please sign in to comment.