Skip to content

Commit 1fcf30c

Browse files
committed
Generate package.xml and release archive
1 parent fe6bcec commit 1fcf30c

File tree

3 files changed

+278
-2
lines changed

3 files changed

+278
-2
lines changed

Makefile.frag

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: coverage testclean
1+
.PHONY: coverage testclean ChangeLog RELEASE package.xml
22

33
DATE=`date +%Y-%m-%d--%H-%M-%S`
44

@@ -31,6 +31,9 @@ testclean:
3131

3232
phongodep:
3333

34+
release: ChangeLog RELEASE package.xml
35+
pecl package package.xml
36+
3437
patch:
3538
@if ! test -e $(top_srcdir)/.patched; then \
3639
for file in `/bin/ls -1 $(top_srcdir)/patches/*.patch | sort -n`; do \
@@ -46,6 +49,12 @@ patch:
4649
touch $(top_srcdir)/.patched; \
4750
fi
4851

52+
package.xml:
53+
php bin/prep-release.php 0.1.0-devel
54+
55+
RELEASE:
56+
@git log --pretty=format:"%ad %an <%ae>%n%x09* %s%n" --date short > RELEASE-X.Y.Z
57+
4958
ChangeLog:
50-
@git log --pretty=format:"%ad %an <%ae>%n%x09* %s%n" --date short > ChangeLog-0.1.0
59+
@git log --pretty=format:"%ad %an <%ae>%n%x09* %s%n" --date short > ChangeLog
5160

bin/package.xml.in

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package version="2.1" xmlns="http://pear.php.net/dtd/package-2.1" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0 http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.1 http://pear.php.net/dtd/package-2.1.xsd">
3+
<name>phongo</name>
4+
<channel>pecl.php.net</channel>
5+
<summary>PHongo (PHP MongoDB driver)</summary>
6+
<description>
7+
The purpose of this driver is to provide exceptionally thin glue between MongoDB
8+
and PHP, implementing only fundemental and performance-critical components
9+
necessary to build a fully-functional MongoDB driver.
10+
</description>
11+
<lead>
12+
<name>Hannes Magnusson</name>
13+
<user>bjori</user>
14+
<email>bjori@mongodb.com</email>
15+
<active>yes</active>
16+
</lead>
17+
<developer>
18+
<name>Jeremy Mikola</name>
19+
<user>jmikola</user>
20+
<email>jmikola@mongodb.com</email>
21+
<active>yes</active>
22+
</developer>
23+
<date>%RELEASE_DATE%</date>
24+
<time>%RELEASE_TIME%</time>
25+
<version>
26+
<release>%RELEASE_VERSION%</release>
27+
<api>%RELEASE_VERSION%</api>
28+
</version>
29+
<stability>
30+
<release>%RELEASE_STABILITY%</release>
31+
<api>%RELEASE_STABILITY%</api>
32+
</stability>
33+
<license uri="http://www.opensource.org/licenses/bsd-license.php">New BSD License</license>
34+
<notes>
35+
%RELEASE_NOTES%
36+
</notes>
37+
<contents>
38+
%RELEASE_FILES%
39+
</contents>
40+
<dependencies>
41+
<required>
42+
<php>
43+
<min>5.2.0</min>
44+
</php>
45+
<pearinstaller>
46+
<min>1.4.8</min>
47+
</pearinstaller>
48+
</required>
49+
</dependencies>
50+
<providesextension>phongo</providesextension>
51+
<extsrcrelease/>
52+
</package>

bin/prep-release.php

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
function verify_stability($stability) {
3+
$stabilities = array(
4+
"snapshot",
5+
"devel",
6+
"alpha",
7+
"beta",
8+
"stable",
9+
);
10+
11+
if (!in_array($stability, $stabilities)) {
12+
echo "Invalid stability: $stability\n";
13+
echo "Must be one of: ", join(", ", $stabilities), "\n";
14+
usage();
15+
}
16+
}
17+
function verify_version($version, $stability) {
18+
if (3 != sscanf($version, "%d.%d.%d", $major, $minor, $patch)) {
19+
var_dump($major, $minor, $patch);
20+
echo "Invalid version schema, expected 'major.minor.patch' (1.2.3), got $version\n";
21+
usage();
22+
}
23+
24+
if ($major < 0 && $stability == "stable") {
25+
echo "Invalid stability for major version $major ($stability)\n";
26+
echo "Major versions before 1.0.0 cannot be marked as stable\n";
27+
usage();
28+
}
29+
}
30+
function verify_changelog($filename) {
31+
if (!file_exists($filename)) {
32+
echo "Missing ChangeLog file!\n";
33+
echo "Need pre-populated $filename\n";
34+
echo "Did you forget to run $ make ChangeLog ?\n";
35+
usage();
36+
}
37+
}
38+
function get_role($file) {
39+
switch(pathinfo($file, PATHINFO_EXTENSION)) {
40+
case "defs":
41+
case "def":
42+
case "m4":
43+
case "c":
44+
case "h":
45+
return "src";
46+
47+
case "phpt":
48+
case "php":
49+
case "inc":
50+
return "test";
51+
52+
default:
53+
return "doc";
54+
}
55+
}
56+
57+
function get_files() {
58+
$dirs = array(
59+
"php_*.{h,c}",
60+
"config.m4",
61+
"Makefile.frag",
62+
"README*",
63+
"ChangeLog*",
64+
"src/*.{c,h}",
65+
"src/MongoDB/*.{c,h}",
66+
"src/BSON/*.{c,h}",
67+
"src/libbson/build/autotools/*.{m4}",
68+
"src/libbson/build/autotools/m4/*.{m4}",
69+
"src/libbson/src/bson/*.{c,h}",
70+
"src/libbson/src/yajl/*.{c,h}",
71+
"src/libmongoc/build/autotools/*.{m4}",
72+
"src/libmongoc/build/autotools/m4/*.{m4}",
73+
"src/libmongoc/src/mongoc/*.{c,h,def,defs}",
74+
"tests/batch/*.{phpt}",
75+
"tests/bson/*.{phpt}",
76+
"tests/functional/*.{phpt}",
77+
"tests/generic/*.{phpt}",
78+
"tests/readPreference/*.{phpt}",
79+
"tests/standalone/*.{phpt}",
80+
"tests/utils/*.{inc,php}",
81+
"tests/writeConcern/*.{phpt}",
82+
);
83+
$files = array();
84+
foreach($dirs as $pattern) {
85+
$files += array_merge($files, glob($pattern, GLOB_BRACE));
86+
}
87+
sort($files);
88+
return $files;
89+
}
90+
91+
function format_open_dir($dir, $tab) {
92+
return sprintf('%s<dir name="%s">', str_repeat(" ", $tab), $dir);
93+
}
94+
function format_close_dir($tab) {
95+
return sprintf("%s</dir>", str_repeat(" ", $tab));
96+
}
97+
function format_file($filename, $tab) {
98+
return sprintf('%s<file role="%s" name="%s"/>', str_repeat(" ", $tab+1), get_role($filename), $filename);
99+
}
100+
function make_tree($files) {
101+
$retval = array();
102+
$lastdir = ".";
103+
$tab = 2;
104+
105+
$retval[] = format_open_dir("/", $tab);
106+
foreach($files as $file) {
107+
$dir = dirname($file);
108+
$filename = basename($file);
109+
if ($dir != $lastdir) {
110+
$currdir = explode("/", $dir);
111+
$prevdir = explode("/", $lastdir);
112+
foreach($currdir as $n => $d) {
113+
if (isset($prevdir[$n]) && $prevdir[$n] == $d) {
114+
/* In case we are shorter then previous */
115+
$n++;
116+
continue;
117+
}
118+
break;
119+
}
120+
if ($lastdir != ".") {
121+
foreach(array_reverse(array_slice($prevdir, $n)) as $close) {
122+
$retval[] = format_close_dir($tab--);
123+
}
124+
}
125+
foreach(array_slice($currdir, $n) as $open) {
126+
$retval[] = format_open_dir($open, ++$tab);
127+
}
128+
}
129+
$retval[] = format_file($filename, $tab);
130+
$lastdir = $dir;
131+
}
132+
foreach(array_reverse(explode("/", $lastdir)) as $close) {
133+
$retval[] = format_close_dir($tab--);
134+
}
135+
$retval[] = format_close_dir($tab);
136+
137+
return $retval;
138+
}
139+
140+
function usage() {
141+
global $argv;
142+
143+
echo "Usage:\n\t";
144+
echo $argv[0], " <version><-stability>\n";
145+
146+
exit(1);
147+
}
148+
149+
if ($argc != 2) {
150+
usage();
151+
}
152+
153+
if (strpos($argv[1], "-")) {
154+
list($VERSION, $STABILITY) = explode("-", $argv[1], 2);
155+
} else {
156+
$VERSION = $argv[1];
157+
158+
/* 0.x.y. are developmental releases and cannot be stable */
159+
if ((int)$VERSION < 1) {
160+
$STABILITY = "devel";
161+
}
162+
/* A release candidate is a "beta" stability in terms of PECL */
163+
$rc = substr($VERSION, -3, 2);
164+
if (strcasecmp($rc, "rc") == 0) {
165+
$STABILITY = "beta";
166+
} else {
167+
$STABILITY = "stable";
168+
}
169+
}
170+
171+
verify_stability($STABILITY);
172+
verify_version($VERSION, $STABILITY);
173+
$changelog = __DIR__ . "/../ChangeLog-" . $VERSION;
174+
verify_changelog($changelog);
175+
176+
177+
$currtime = $_SERVER["REQUEST_TIME"];
178+
$DATE = date("Y-m-d", $currtime);
179+
$TIME = date("H:i:s", $currtime);
180+
181+
$fullnotes = file($changelog, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
182+
$NOTES = array();
183+
foreach($fullnotes as $note) {
184+
$note = " " . str_replace("&", "&amp;", trim($note));
185+
/* PHP JIRA Project */
186+
if (strstr($note, "PHP-") !== false) {
187+
$NOTES[] = $note;
188+
continue;
189+
}
190+
/* Coverity ID */
191+
if (strstr($note, "CID-") !== false) {
192+
$NOTES[] = $note;
193+
continue;
194+
}
195+
}
196+
197+
198+
$TREE = make_tree(get_files());
199+
200+
$contents = file_get_contents(__DIR__ . "/package.xml.in");
201+
202+
$REPLACE = array(
203+
"%RELEASE_DATE%" => $DATE,
204+
"%RELEASE_TIME%" => $TIME,
205+
"%RELEASE_VERSION%" => $VERSION,
206+
"%RELEASE_STABILITY%" => $STABILITY,
207+
"%RELEASE_NOTES%" => join("\n", $NOTES),
208+
"%RELEASE_FILES%" => join("\n", $TREE),
209+
);
210+
211+
$contents = str_replace(array_keys($REPLACE), array_values($REPLACE), $contents);
212+
213+
file_put_contents(__DIR__ . "/../package.xml", $contents);
214+
echo "Wrote package.xml\n";
215+

0 commit comments

Comments
 (0)