Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 1 | """Tag the sandbox for release, make source and doc tarballs. |
| 2 | |
| 3 | Requires Python 2.6 |
| 4 | |
| 5 | Example of invocation (use to test the script): |
Baptiste Lepilleur | e1b2645 | 2010-03-13 10:59:50 +0000 | [diff] [blame] | 6 | python makerelease.py --platform=msvc6,msvc71,msvc80,msvc90,mingw -ublep 0.6.0 0.7.0-dev |
Baptiste Lepilleur | cd6cb5d | 2010-03-13 07:59:07 +0000 | [diff] [blame] | 7 | |
| 8 | When testing this script: |
Baptiste Lepilleur | bafb43c | 2011-05-01 20:36:55 +0000 | [diff] [blame] | 9 | python makerelease.py --force --retag --platform=msvc6,msvc71,msvc80,mingw -ublep test-0.6.0 test-0.6.1-dev |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 10 | |
| 11 | Example of invocation when doing a release: |
| 12 | python makerelease.py 0.5.0 0.6.0-dev |
Christopher Dunn | b789497 | 2014-09-10 18:01:10 -0700 | [diff] [blame] | 13 | |
| 14 | Note: This was for Subversion. Now that we are in GitHub, we do not |
| 15 | need to build versioned tarballs anymore, so makerelease.py is defunct. |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 16 | """ |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 17 | from __future__ import print_function |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 18 | import os.path |
| 19 | import subprocess |
| 20 | import sys |
| 21 | import doxybuild |
| 22 | import subprocess |
| 23 | import xml.etree.ElementTree as ElementTree |
Baptiste Lepilleur | 7c171ee | 2010-02-23 08:44:52 +0000 | [diff] [blame] | 24 | import shutil |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 25 | import urllib2 |
| 26 | import tempfile |
| 27 | import os |
| 28 | import time |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 29 | from devtools import antglob, fixeol, tarball |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 30 | import amalgamate |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 31 | |
| 32 | SVN_ROOT = 'https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/' |
| 33 | SVN_TAG_ROOT = SVN_ROOT + 'tags/jsoncpp' |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 34 | SCONS_LOCAL_URL = 'http://sourceforge.net/projects/scons/files/scons-local/1.2.0/scons-local-1.2.0.tar.gz/download' |
| 35 | SOURCEFORGE_PROJECT = 'jsoncpp' |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 36 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 37 | def set_version(version): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 38 | with open('version','wb') as f: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 39 | f.write(version.strip()) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 40 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 41 | def rmdir_if_exist(dir_path): |
| 42 | if os.path.isdir(dir_path): |
| 43 | shutil.rmtree(dir_path) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 44 | |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 45 | class SVNError(Exception): |
| 46 | pass |
| 47 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 48 | def svn_command(command, *args): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 49 | cmd = ['svn', '--non-interactive', command] + list(args) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 50 | print('Running:', ' '.join(cmd)) |
| 51 | process = subprocess.Popen(cmd, |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 52 | stdout=subprocess.PIPE, |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 53 | stderr=subprocess.STDOUT) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 54 | stdout = process.communicate()[0] |
| 55 | if process.returncode: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 56 | error = SVNError('SVN command failed:\n' + stdout) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 57 | error.returncode = process.returncode |
| 58 | raise error |
| 59 | return stdout |
| 60 | |
| 61 | def check_no_pending_commit(): |
| 62 | """Checks that there is no pending commit in the sandbox.""" |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 63 | stdout = svn_command('status', '--xml') |
| 64 | etree = ElementTree.fromstring(stdout) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 65 | msg = [] |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 66 | for entry in etree.getiterator('entry'): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 67 | path = entry.get('path') |
| 68 | status = entry.find('wc-status').get('item') |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 69 | if status != 'unversioned' and path != 'version': |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 70 | msg.append('File "%s" has pending change (status="%s")' % (path, status)) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 71 | if msg: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 72 | msg.insert(0, 'Pending change to commit found in sandbox. Commit them first!') |
| 73 | return '\n'.join(msg) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 74 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 75 | def svn_join_url(base_url, suffix): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 76 | if not base_url.endswith('/'): |
| 77 | base_url += '/' |
| 78 | if suffix.startswith('/'): |
| 79 | suffix = suffix[1:] |
| 80 | return base_url + suffix |
| 81 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 82 | def svn_check_if_tag_exist(tag_url): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 83 | """Checks if a tag exist. |
| 84 | Returns: True if the tag exist, False otherwise. |
| 85 | """ |
| 86 | try: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 87 | list_stdout = svn_command('list', tag_url) |
Christopher Dunn | 9aa6144 | 2014-11-19 23:10:02 -0600 | [diff] [blame] | 88 | except SVNError as e: |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 89 | if e.returncode != 1 or not str(e).find('tag_url'): |
| 90 | raise e |
| 91 | # otherwise ignore error, meaning tag does not exist |
| 92 | return False |
| 93 | return True |
| 94 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 95 | def svn_commit(message): |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 96 | """Commit the sandbox, providing the specified comment. |
| 97 | """ |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 98 | svn_command('ci', '-m', message) |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 99 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 100 | def svn_tag_sandbox(tag_url, message): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 101 | """Makes a tag based on the sandbox revisions. |
| 102 | """ |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 103 | svn_command('copy', '-m', message, '.', tag_url) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 104 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 105 | def svn_remove_tag(tag_url, message): |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 106 | """Removes an existing tag. |
| 107 | """ |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 108 | svn_command('delete', '-m', message, tag_url) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 109 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 110 | def svn_export(tag_url, export_dir): |
Baptiste Lepilleur | 7c171ee | 2010-02-23 08:44:52 +0000 | [diff] [blame] | 111 | """Exports the tag_url revision to export_dir. |
| 112 | Target directory, including its parent is created if it does not exist. |
| 113 | If the directory export_dir exist, it is deleted before export proceed. |
| 114 | """ |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 115 | rmdir_if_exist(export_dir) |
| 116 | svn_command('export', tag_url, export_dir) |
Baptiste Lepilleur | 7c171ee | 2010-02-23 08:44:52 +0000 | [diff] [blame] | 117 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 118 | def fix_sources_eol(dist_dir): |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 119 | """Set file EOL for tarball distribution. |
| 120 | """ |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 121 | print('Preparing exported source file EOL for distribution...') |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 122 | prune_dirs = antglob.prune_dirs + 'scons-local* ./build* ./libs ./dist' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 123 | win_sources = antglob.glob(dist_dir, |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 124 | includes = '**/*.sln **/*.vcproj', |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 125 | prune_dirs = prune_dirs) |
| 126 | unix_sources = antglob.glob(dist_dir, |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 127 | includes = '''**/*.h **/*.cpp **/*.inl **/*.txt **/*.dox **/*.py **/*.html **/*.in |
| 128 | sconscript *.json *.expected AUTHORS LICENSE''', |
| 129 | excludes = antglob.default_excludes + 'scons.py sconsign.py scons-*', |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 130 | prune_dirs = prune_dirs) |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 131 | for path in win_sources: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 132 | fixeol.fix_source_eol(path, is_dry_run = False, verbose = True, eol = '\r\n') |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 133 | for path in unix_sources: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 134 | fixeol.fix_source_eol(path, is_dry_run = False, verbose = True, eol = '\n') |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 135 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 136 | def download(url, target_path): |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 137 | """Download file represented by url to target_path. |
| 138 | """ |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 139 | f = urllib2.urlopen(url) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 140 | try: |
| 141 | data = f.read() |
| 142 | finally: |
| 143 | f.close() |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 144 | fout = open(target_path, 'wb') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 145 | try: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 146 | fout.write(data) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 147 | finally: |
| 148 | fout.close() |
| 149 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 150 | def check_compile(distcheck_top_dir, platform): |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 151 | cmd = [sys.executable, 'scons.py', 'platform=%s' % platform, 'check'] |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 152 | print('Running:', ' '.join(cmd)) |
| 153 | log_path = os.path.join(distcheck_top_dir, 'build-%s.log' % platform) |
| 154 | flog = open(log_path, 'wb') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 155 | try: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 156 | process = subprocess.Popen(cmd, |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 157 | stdout=flog, |
| 158 | stderr=subprocess.STDOUT, |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 159 | cwd=distcheck_top_dir) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 160 | stdout = process.communicate()[0] |
| 161 | status = (process.returncode == 0) |
| 162 | finally: |
| 163 | flog.close() |
| 164 | return (status, log_path) |
| 165 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 166 | def write_tempfile(content, **kwargs): |
| 167 | fd, path = tempfile.mkstemp(**kwargs) |
| 168 | f = os.fdopen(fd, 'wt') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 169 | try: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 170 | f.write(content) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 171 | finally: |
| 172 | f.close() |
| 173 | return path |
| 174 | |
| 175 | class SFTPError(Exception): |
| 176 | pass |
| 177 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 178 | def run_sftp_batch(userhost, sftp, batch, retry=0): |
| 179 | path = write_tempfile(batch, suffix='.sftp', text=True) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 180 | # psftp -agent -C blep,jsoncpp@web.sourceforge.net -batch -b batch.sftp -bc |
| 181 | cmd = [sftp, '-agent', '-C', '-batch', '-b', path, '-bc', userhost] |
| 182 | error = None |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 183 | for retry_index in range(0, max(1,retry)): |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 184 | heading = retry_index == 0 and 'Running:' or 'Retrying:' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 185 | print(heading, ' '.join(cmd)) |
| 186 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 187 | stdout = process.communicate()[0] |
| 188 | if process.returncode != 0: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 189 | error = SFTPError('SFTP batch failed:\n' + stdout) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 190 | else: |
| 191 | break |
| 192 | if error: |
| 193 | raise error |
| 194 | return stdout |
| 195 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 196 | def sourceforge_web_synchro(sourceforge_project, doc_dir, |
| 197 | user=None, sftp='sftp'): |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 198 | """Notes: does not synchronize sub-directory of doc-dir. |
| 199 | """ |
| 200 | userhost = '%s,%s@web.sourceforge.net' % (user, sourceforge_project) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 201 | stdout = run_sftp_batch(userhost, sftp, """ |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 202 | cd htdocs |
| 203 | dir |
| 204 | exit |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 205 | """) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 206 | existing_paths = set() |
| 207 | collect = 0 |
| 208 | for line in stdout.split('\n'): |
| 209 | line = line.strip() |
| 210 | if not collect and line.endswith('> dir'): |
| 211 | collect = True |
| 212 | elif collect and line.endswith('> exit'): |
| 213 | break |
| 214 | elif collect == 1: |
| 215 | collect = 2 |
| 216 | elif collect == 2: |
| 217 | path = line.strip().split()[-1:] |
| 218 | if path and path[0] not in ('.', '..'): |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 219 | existing_paths.add(path[0]) |
| 220 | upload_paths = set([os.path.basename(p) for p in antglob.glob(doc_dir)]) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 221 | paths_to_remove = existing_paths - upload_paths |
| 222 | if paths_to_remove: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 223 | print('Removing the following file from web:') |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 224 | print('\n'.join(paths_to_remove)) |
| 225 | stdout = run_sftp_batch(userhost, sftp, """cd htdocs |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 226 | rm %s |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 227 | exit""" % ' '.join(paths_to_remove)) |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 228 | print('Uploading %d files:' % len(upload_paths)) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 229 | batch_size = 10 |
| 230 | upload_paths = list(upload_paths) |
| 231 | start_time = time.time() |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 232 | for index in range(0,len(upload_paths),batch_size): |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 233 | paths = upload_paths[index:index+batch_size] |
| 234 | file_per_sec = (time.time() - start_time) / (index+1) |
| 235 | remaining_files = len(upload_paths) - index |
| 236 | remaining_sec = file_per_sec * remaining_files |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 237 | print('%d/%d, ETA=%.1fs' % (index+1, len(upload_paths), remaining_sec)) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 238 | run_sftp_batch(userhost, sftp, """cd htdocs |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 239 | lcd %s |
| 240 | mput %s |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 241 | exit""" % (doc_dir, ' '.join(paths)), retry=3) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 242 | |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 243 | def sourceforge_release_tarball(sourceforge_project, paths, user=None, sftp='sftp'): |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 244 | userhost = '%s,%s@frs.sourceforge.net' % (user, sourceforge_project) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 245 | run_sftp_batch(userhost, sftp, """ |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 246 | mput %s |
| 247 | exit |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 248 | """ % (' '.join(paths),)) |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 249 | |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 250 | |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 251 | def main(): |
| 252 | usage = """%prog release_version next_dev_version |
| 253 | Update 'version' file to release_version and commit. |
| 254 | Generates the document tarball. |
| 255 | Tags the sandbox revision with release_version. |
| 256 | Update 'version' file to next_dev_version and commit. |
| 257 | |
| 258 | Performs an svn export of tag release version, and build a source tarball. |
| 259 | |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 260 | Must be started in the project top directory. |
| 261 | |
| 262 | Warning: --force should only be used when developping/testing the release script. |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 263 | """ |
| 264 | from optparse import OptionParser |
| 265 | parser = OptionParser(usage=usage) |
| 266 | parser.allow_interspersed_args = False |
| 267 | parser.add_option('--dot', dest="dot_path", action='store', default=doxybuild.find_program('dot'), |
| 268 | help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""") |
| 269 | parser.add_option('--doxygen', dest="doxygen_path", action='store', default=doxybuild.find_program('doxygen'), |
| 270 | help="""Path to Doxygen tool. [Default: %default]""") |
| 271 | parser.add_option('--force', dest="ignore_pending_commit", action='store_true', default=False, |
| 272 | help="""Ignore pending commit. [Default: %default]""") |
| 273 | parser.add_option('--retag', dest="retag_release", action='store_true', default=False, |
| 274 | help="""Overwrite release existing tag if it exist. [Default: %default]""") |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 275 | parser.add_option('-p', '--platforms', dest="platforms", action='store', default='', |
| 276 | help="""Comma separated list of platform passed to scons for build check.""") |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 277 | parser.add_option('--no-test', dest="no_test", action='store_true', default=False, |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 278 | help="""Skips build check.""") |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 279 | parser.add_option('--no-web', dest="no_web", action='store_true', default=False, |
| 280 | help="""Do not update web site.""") |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 281 | parser.add_option('-u', '--upload-user', dest="user", action='store', |
| 282 | help="""Sourceforge user for SFTP documentation upload.""") |
| 283 | parser.add_option('--sftp', dest='sftp', action='store', default=doxybuild.find_program('psftp', 'sftp'), |
| 284 | help="""Path of the SFTP compatible binary used to upload the documentation.""") |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 285 | parser.enable_interspersed_args() |
| 286 | options, args = parser.parse_args() |
| 287 | |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 288 | if len(args) != 2: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 289 | parser.error('release_version missing on command-line.') |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 290 | release_version = args[0] |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 291 | next_version = args[1] |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 292 | |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 293 | if not options.platforms and not options.no_test: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 294 | parser.error('You must specify either --platform or --no-test option.') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 295 | |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 296 | if options.ignore_pending_commit: |
| 297 | msg = '' |
| 298 | else: |
| 299 | msg = check_no_pending_commit() |
| 300 | if not msg: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 301 | print('Setting version to', release_version) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 302 | set_version(release_version) |
| 303 | svn_commit('Release ' + release_version) |
| 304 | tag_url = svn_join_url(SVN_TAG_ROOT, release_version) |
| 305 | if svn_check_if_tag_exist(tag_url): |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 306 | if options.retag_release: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 307 | svn_remove_tag(tag_url, 'Overwriting previous tag') |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 308 | else: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 309 | print('Aborting, tag %s already exist. Use --retag to overwrite it!' % tag_url) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 310 | sys.exit(1) |
| 311 | svn_tag_sandbox(tag_url, 'Release ' + release_version) |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 312 | |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 313 | print('Generated doxygen document...') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 314 | ## doc_dirname = r'jsoncpp-api-html-0.5.0' |
| 315 | ## doc_tarball_path = r'e:\prg\vc\Lib\jsoncpp-trunk\dist\jsoncpp-api-html-0.5.0.tar.gz' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 316 | doc_tarball_path, doc_dirname = doxybuild.build_doc(options, make_release=True) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 317 | doc_distcheck_dir = 'dist/doccheck' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 318 | tarball.decompress(doc_tarball_path, doc_distcheck_dir) |
| 319 | doc_distcheck_top_dir = os.path.join(doc_distcheck_dir, doc_dirname) |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 320 | |
| 321 | export_dir = 'dist/export' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 322 | svn_export(tag_url, export_dir) |
| 323 | fix_sources_eol(export_dir) |
Baptiste Lepilleur | e94d2f4 | 2010-02-23 21:00:30 +0000 | [diff] [blame] | 324 | |
| 325 | source_dir = 'jsoncpp-src-' + release_version |
| 326 | source_tarball_path = 'dist/%s.tar.gz' % source_dir |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 327 | print('Generating source tarball to', source_tarball_path) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 328 | tarball.make_tarball(source_tarball_path, [export_dir], export_dir, prefix_dir=source_dir) |
Baptiste Lepilleur | 35bdc07 | 2010-02-24 08:05:41 +0000 | [diff] [blame] | 329 | |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 330 | amalgamation_tarball_path = 'dist/%s-amalgamation.tar.gz' % source_dir |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 331 | print('Generating amalgamation source tarball to', amalgamation_tarball_path) |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 332 | amalgamation_dir = 'dist/amalgamation' |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 333 | amalgamate.amalgamate_source(export_dir, '%s/jsoncpp.cpp' % amalgamation_dir, 'json/json.h') |
Baptiste Lepilleur | eadc478 | 2011-05-02 21:09:30 +0000 | [diff] [blame] | 334 | amalgamation_source_dir = 'jsoncpp-src-amalgamation' + release_version |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 335 | tarball.make_tarball(amalgamation_tarball_path, [amalgamation_dir], |
| 336 | amalgamation_dir, prefix_dir=amalgamation_source_dir) |
Baptiste Lepilleur | bafb43c | 2011-05-01 20:36:55 +0000 | [diff] [blame] | 337 | |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 338 | # Decompress source tarball, download and install scons-local |
Baptiste Lepilleur | 35bdc07 | 2010-02-24 08:05:41 +0000 | [diff] [blame] | 339 | distcheck_dir = 'dist/distcheck' |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 340 | distcheck_top_dir = distcheck_dir + '/' + source_dir |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 341 | print('Decompressing source tarball to', distcheck_dir) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 342 | rmdir_if_exist(distcheck_dir) |
| 343 | tarball.decompress(source_tarball_path, distcheck_dir) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 344 | scons_local_path = 'dist/scons-local.tar.gz' |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 345 | print('Downloading scons-local to', scons_local_path) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 346 | download(SCONS_LOCAL_URL, scons_local_path) |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 347 | print('Decompressing scons-local to', distcheck_top_dir) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 348 | tarball.decompress(scons_local_path, distcheck_top_dir) |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 349 | |
| 350 | # Run compilation |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 351 | print('Compiling decompressed tarball') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 352 | all_build_status = True |
| 353 | for platform in options.platforms.split(','): |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 354 | print('Testing platform:', platform) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 355 | build_status, log_path = check_compile(distcheck_top_dir, platform) |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 356 | print('see build log:', log_path) |
| 357 | print(build_status and '=> ok' or '=> FAILED') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 358 | all_build_status = all_build_status and build_status |
| 359 | if not build_status: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 360 | print('Testing failed on at least one platform, aborting...') |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 361 | svn_remove_tag(tag_url, 'Removing tag due to failed testing') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 362 | sys.exit(1) |
| 363 | if options.user: |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 364 | if not options.no_web: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 365 | print('Uploading documentation using user', options.user) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 366 | sourceforge_web_synchro(SOURCEFORGE_PROJECT, doc_distcheck_top_dir, user=options.user, sftp=options.sftp) |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 367 | print('Completed documentation upload') |
| 368 | print('Uploading source and documentation tarballs for release using user', options.user) |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 369 | sourceforge_release_tarball(SOURCEFORGE_PROJECT, |
Baptiste Lepilleur | d89d796 | 2010-02-25 08:30:09 +0000 | [diff] [blame] | 370 | [source_tarball_path, doc_tarball_path], |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 371 | user=options.user, sftp=options.sftp) |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 372 | print('Source and doc release tarballs uploaded') |
Baptiste Lepilleur | 64ba062 | 2010-02-24 23:08:47 +0000 | [diff] [blame] | 373 | else: |
Christopher Dunn | bd1e895 | 2014-11-19 23:30:47 -0600 | [diff] [blame] | 374 | print('No upload user specified. Web site and download tarbal were not uploaded.') |
| 375 | print('Tarball can be found at:', doc_tarball_path) |
Baptiste Lepilleur | e6a7741 | 2010-03-11 21:02:26 +0000 | [diff] [blame] | 376 | |
| 377 | # Set next version number and commit |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 378 | set_version(next_version) |
| 379 | svn_commit('Released ' + release_version) |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 380 | else: |
Christopher Dunn | 494950a | 2015-01-24 15:29:52 -0600 | [diff] [blame] | 381 | sys.stderr.write(msg + '\n') |
Baptiste Lepilleur | 1f4847c | 2010-02-23 07:57:38 +0000 | [diff] [blame] | 382 | |
| 383 | if __name__ == '__main__': |
| 384 | main() |