blob: c21a1e3d54c896af3f712af6d002a7233d90c358 [file] [log] [blame]
Baptiste Lepilleur1f4847c2010-02-23 07:57:38 +00001"""Tag the sandbox for release, make source and doc tarballs.
2
3Requires Python 2.6
4
5Example of invocation (use to test the script):
6python makerelease.py --force --retag 0.5.0 0.6.0-dev
7
8Example of invocation when doing a release:
9python makerelease.py 0.5.0 0.6.0-dev
10"""
11import os.path
12import subprocess
13import sys
14import doxybuild
15import subprocess
16import xml.etree.ElementTree as ElementTree
17
18SVN_ROOT = 'https://jsoncpp.svn.sourceforge.net/svnroot/jsoncpp/'
19SVN_TAG_ROOT = SVN_ROOT + 'tags/jsoncpp'
20
21def set_version( version ):
22 with open('version','wb') as f:
23 f.write( version.strip() )
24
25class SVNError(Exception):
26 pass
27
28def svn_command( command, *args ):
29 cmd = ['svn', '--non-interactive', command] + list(args)
30 print 'Running:', ' '.join( cmd )
31 process = subprocess.Popen( cmd,
32 stdout=subprocess.PIPE,
33 stderr=subprocess.STDOUT )
34 stdout = process.communicate()[0]
35 if process.returncode:
36 error = SVNError( 'SVN command failed:\n' + stdout )
37 error.returncode = process.returncode
38 raise error
39 return stdout
40
41def check_no_pending_commit():
42 """Checks that there is no pending commit in the sandbox."""
43 stdout = svn_command( 'status', '--xml' )
44 etree = ElementTree.fromstring( stdout )
45 msg = []
46 for entry in etree.getiterator( 'entry' ):
47 path = entry.get('path')
48 status = entry.find('wc-status').get('item')
49 if status != 'unversioned':
50 msg.append( 'File "%s" has pending change (status="%s")' % (path, status) )
51 if msg:
52 msg.insert(0, 'Pending change to commit found in sandbox. Commit them first!' )
53 return '\n'.join( msg )
54
55def svn_join_url( base_url, suffix ):
56 if not base_url.endswith('/'):
57 base_url += '/'
58 if suffix.startswith('/'):
59 suffix = suffix[1:]
60 return base_url + suffix
61
62def svn_check_if_tag_exist( tag_url ):
63 """Checks if a tag exist.
64 Returns: True if the tag exist, False otherwise.
65 """
66 try:
67 list_stdout = svn_command( 'list', tag_url )
68 except SVNError, e:
69 if e.returncode != 1 or not str(e).find('tag_url'):
70 raise e
71 # otherwise ignore error, meaning tag does not exist
72 return False
73 return True
74
75def svn_tag_sandbox( tag_url, message ):
76 """Makes a tag based on the sandbox revisions.
77 """
78 svn_command( 'copy', '-m', message, '.', tag_url )
79
80def svn_remove_tag( tag_url, message ):
81 """Removes an existing tag.
82 """
83 svn_command( 'delete', '-m', message, tag_url )
84
85def main():
86 usage = """%prog release_version next_dev_version
87Update 'version' file to release_version and commit.
88Generates the document tarball.
89Tags the sandbox revision with release_version.
90Update 'version' file to next_dev_version and commit.
91
92Performs an svn export of tag release version, and build a source tarball.
93
94Must be started in the project top directory.
95"""
96 from optparse import OptionParser
97 parser = OptionParser(usage=usage)
98 parser.allow_interspersed_args = False
99 parser.add_option('--dot', dest="dot_path", action='store', default=doxybuild.find_program('dot'),
100 help="""Path to GraphViz dot tool. Must be full qualified path. [Default: %default]""")
101 parser.add_option('--doxygen', dest="doxygen_path", action='store', default=doxybuild.find_program('doxygen'),
102 help="""Path to Doxygen tool. [Default: %default]""")
103 parser.add_option('--force', dest="ignore_pending_commit", action='store_true', default=False,
104 help="""Ignore pending commit. [Default: %default]""")
105 parser.add_option('--retag', dest="retag_release", action='store_true', default=False,
106 help="""Overwrite release existing tag if it exist. [Default: %default]""")
107 parser.enable_interspersed_args()
108 options, args = parser.parse_args()
109
110 if len(args) < 1:
111 parser.error( 'release_version missing on command-line.' )
112 release_version = args[0]
113
114 if options.ignore_pending_commit:
115 msg = ''
116 else:
117 msg = check_no_pending_commit()
118 if not msg:
119 print 'Setting version to', release_version
120 set_version( release_version )
121 tag_url = svn_join_url( SVN_TAG_ROOT, release_version )
122 if svn_check_if_tag_exist( tag_url ):
123 if options.retag_release:
124 svn_remove_tag( tag_url, 'Overwriting previous tag' )
125 else:
126 print 'Aborting, tag %s already exist. Use --retag to overwrite it!' % tag_url
127 sys.exit( 1 )
128 svn_tag_sandbox( tag_url, 'Release ' + release_version )
129 print 'Generated doxygen document...'
130 doxybuild.build_doc( options, make_release=True )
131 #@todo:
132 # svn export
133 # source tarball
134 # decompress source tarball
135 # ?compile & run & check
136 # ?upload documentation
137 else:
138 sys.stderr.write( msg + '\n' )
139
140if __name__ == '__main__':
141 main()