|
| 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("&", "&", 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