258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
1 |
#!/usr/bin/python
|
2 |
# vim:expandtab:shiftwidth=2:tabstop=2:
|
|
3 |
||
4 |
# Copyright (C) 2013 Canonical Ltd.
|
|
5 |
||
6 |
# This library is free software; you can redistribute it and/or
|
|
7 |
# modify it under the terms of the GNU Lesser General Public
|
|
8 |
# License as published by the Free Software Foundation; either
|
|
9 |
# version 2.1 of the License, or (at your option) any later version.
|
|
10 |
||
11 |
# This library is distributed in the hope that it will be useful,
|
|
12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 |
# Lesser General Public License for more details.
|
|
15 |
||
16 |
# You should have received a copy of the GNU Lesser General Public
|
|
17 |
# License along with this library; if not, write to the Free Software
|
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
||
20 |
from __future__ import print_function |
|
21 |
import optparse |
|
22 |
import os.path |
|
23 |
import re |
|
24 |
import sys |
|
25 |
||
360
by Chris Coulson
Stop leaving pyc files everywhere |
26 |
sys.dont_write_bytecode = True |
27 |
os.environ["PYTHONDONTWRITEBYTECODE"] = "1" |
|
28 |
||
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
29 |
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "build", "python")) |
30 |
from oxide_utils import ( |
|
31 |
CHROMIUMSRCDIR, |
|
32 |
TOPSRCDIR, |
|
318.1.1
by Chris Coulson
Build the core library, renderer and sandbox with cmake |
33 |
CheckCall, |
34 |
VersionFileParser
|
|
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
35 |
)
|
36 |
import subcommand |
|
37 |
||
437
by Chris Coulson
Update exclude list for tarball |
38 |
TAR_EXCLUDE_DIRS = [ |
39 |
'.bzrignore', |
|
539.1.4
by Chris Coulson
Update release-tool.py |
40 |
'third_party/chromium/src/breakpad/src/processor/testdata', |
41 |
'third_party/chromium/src/chrome/browser/resources/tracing/tests', |
|
42 |
'third_party/chromium/src/chrome/common/extensions/docs', |
|
43 |
'third_party/chromium/src/chrome/test/data', |
|
44 |
'third_party/chromium/src/courgette/testdata', |
|
45 |
'third_party/chromium/src/native_client/src/trusted/service_runtime/testdata', |
|
46 |
'third_party/chromium/src/native_client/toolchain', |
|
47 |
'third_party/chromium/src/out', |
|
48 |
'third_party/chromium/src/ppapi/examples', |
|
49 |
'third_party/chromium/src/ppapi/native_client/tests', |
|
50 |
'third_party/chromium/src/third_party/angle/samples/gles2_book', |
|
51 |
'third_party/chromium/src/third_party/hunspell/tests', |
|
52 |
'third_party/chromium/src/third_party/mesa/src/src/gallium/state_trackers/d3d1x/w32api', |
|
53 |
'third_party/chromium/src/third_party/xdg-utils/tests', |
|
54 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/arch/x86/tests', |
|
55 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/dbgfmts/dwarf2/tests', |
|
56 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/bin/tests', |
|
57 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/coff/tests', |
|
58 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/elf/tests', |
|
59 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/macho/tests', |
|
60 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/rdf/tests', |
|
61 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/win32/tests', |
|
62 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/win64/tests', |
|
63 |
'third_party/chromium/src/third_party/yasm/source/patched-yasm/modules/objfmts/xdf/tests', |
|
64 |
'third_party/chromium/src/third_party/WebKit/LayoutTests', |
|
65 |
'third_party/chromium/src/third_party/WebKit/Tools/Scripts', |
|
66 |
'third_party/chromium/src/tools/gyp/test', |
|
67 |
'third_party/chromium/src/v8/test', |
|
68 |
'third_party/chromium/src/webkit/tools/test/reference_build', |
|
437
by Chris Coulson
Update exclude list for tarball |
69 |
'client.py', |
70 |
'gclient.conf', |
|
71 |
'patch-tool.py', |
|
72 |
'release-tool.py', |
|
73 |
]
|
|
74 |
||
75 |
TAR_EXCLUDE_REGEXPS = [ |
|
640
by Chris Coulson
Don't exclude .git/index. It's required by angle, at least |
76 |
r'(^|\/)\.git\/(?!(|index)$)', |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
77 |
r'(^|\/)\.gitignore$', |
78 |
r'(^|\/)\.gitattributes$', |
|
79 |
r'(^|\/)\.hg(\/|$)', |
|
80 |
r'(^|\/)\.svn(\/|$)', |
|
81 |
r'\.mk$', |
|
82 |
r'\.o$', |
|
83 |
r'\.so(|\..*)$', |
|
84 |
r'\.pyc$', |
|
85 |
]
|
|
86 |
||
87 |
class OptionParser(optparse.OptionParser): |
|
88 |
def __init__(self): |
|
89 |
optparse.OptionParser.__init__(self) |
|
90 |
||
91 |
self.description = """ |
|
92 |
Tool for handling release tasks.
|
|
93 |
"""
|
|
94 |
||
95 |
@subcommand.Command("make-tarball") |
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
96 |
@subcommand.CommandOption("--deb", dest="deb", action="store_true", |
97 |
help="Create a tarball suitable for Ubuntu / Debian " |
|
98 |
"packaging") |
|
99 |
@subcommand.CommandOption("-f", "--force", dest="force", action="store_true", |
|
100 |
help="Create a tarball even if the tree has " |
|
101 |
"uncommitted changes") |
|
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
102 |
@subcommand.CommandOption("-c", "--compression", dest="compression", action="store", |
290
by Chris Coulson
Shrink the tarball quite a bit and switch to lzma |
103 |
type="string", default="xz", |
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
104 |
help="Specify the compression (gz, bz2 or xz)") |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
105 |
def cmd_make_tarball(options, args): |
262
by Chris Coulson
Make a tarball more suitable to packaging |
106 |
"""Create a tarball.
|
107 |
||
108 |
This command will create a source tarball, which will include the
|
|
109 |
appropriate Chromium checkout embedded and all Chromium patches applied.
|
|
110 |
||
111 |
"bzr export" is not used because the tarball includes a lot of files that
|
|
112 |
are not maintained in Bzr, and Bzr currently provides no mechanism for hooks
|
|
113 |
to extend "export". Please do not use "bzr export", as it won't work as
|
|
114 |
expected.
|
|
115 |
"""
|
|
116 |
||
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
117 |
if options.compression not in ("gz", "bz2", "xz"): |
118 |
print("Invalid compression (must be \"gz\", \"bz2\" or \"xz\"", file=sys.stderr) |
|
119 |
sys.exit(1) |
|
120 |
||
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
121 |
from bzrlib.branch import Branch |
122 |
from bzrlib.workingtree import WorkingTree |
|
123 |
import tarfile |
|
124 |
||
125 |
# Make sure we have an up-to-date Chromium checkout
|
|
126 |
CheckCall([sys.executable, "client.py"]) |
|
127 |
||
128 |
# XXX: Qt-specific
|
|
318.1.1
by Chris Coulson
Build the core library, renderer and sandbox with cmake |
129 |
v = VersionFileParser(os.path.join(TOPSRCDIR, "qt", "VERSION")) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
130 |
basename = "oxide-qt" |
262
by Chris Coulson
Make a tarball more suitable to packaging |
131 |
topsrcdir = basename |
132 |
||
133 |
if options.deb: |
|
134 |
filename = "%s_%s" % (basename, str(v)) |
|
135 |
else: |
|
136 |
filename = "%s-%s" % (basename, str(v)) |
|
137 |
||
138 |
topsrcdir = "%s-%s" % (basename, str(v)) |
|
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
139 |
|
140 |
# If we're not creating a tarball from a revision with a release
|
|
141 |
# tag, then add the revision to the filename
|
|
142 |
branch = Branch.open(TOPSRCDIR) |
|
143 |
rev_id = branch.last_revision() |
|
144 |
tag_dict = branch.tags.get_reverse_tag_dict() |
|
145 |
tags = tag_dict[rev_id] if rev_id in tag_dict else [] |
|
146 |
# XXX: Qt-specific
|
|
357
by Chris Coulson
Move to a 3 part version number, as the "major" and "build" components of Chromium's version have pretty much the same meaning in Oxide. Also, bump the version to 1.0.0, which will be the first version once we create a beta branch |
147 |
if not any(re.match(r'QT_[0-9]+_[0-9]+_[0-9]+', tag) for tag in tags): |
262
by Chris Coulson
Make a tarball more suitable to packaging |
148 |
filename = "%s~bzr%s" % (filename, branch.revision_id_to_revno(rev_id)) |
149 |
topsrcdir = "%s~bzr%s" % (topsrcdir, branch.revision_id_to_revno(rev_id)) |
|
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
150 |
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
151 |
if options.deb: |
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
152 |
filename = "%s.orig.tar.%s" % (filename, options.compression) |
262
by Chris Coulson
Make a tarball more suitable to packaging |
153 |
else: |
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
154 |
filename = "%s.tar.%s" % (filename, options.compression) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
155 |
|
156 |
# Build list of files in bzr
|
|
157 |
tree = WorkingTree.open(TOPSRCDIR) |
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
158 |
if tree.has_changes() and not options.force: |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
159 |
print("Tree has uncommitted changes. Please commit your changes and try again", file=sys.stderr) |
160 |
sys.exit(1) |
|
161 |
||
162 |
lock = tree.lock_read() |
|
163 |
try: |
|
164 |
files = [path for (path, cls, kind, id, entry) in tree.list_files() if cls == "V"] |
|
165 |
finally: |
|
166 |
lock.unlock() |
|
167 |
||
437
by Chris Coulson
Update exclude list for tarball |
168 |
re_excludes = [re.compile(r) for r in TAR_EXCLUDE_REGEXPS] |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
169 |
|
170 |
def tar_filter(info): |
|
437
by Chris Coulson
Update exclude list for tarball |
171 |
(root, ext) = os.path.splitext(info.name) |
172 |
if ext == ".gyp" or ext == ".gypi": |
|
173 |
return info |
|
174 |
if any(os.path.relpath(info.name, topsrcdir).startswith(r) for r in TAR_EXCLUDE_DIRS): |
|
175 |
return None |
|
176 |
if any(r.search(os.path.relpath(info.name, topsrcdir)) is not None for r in re_excludes): |
|
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
177 |
return None |
178 |
return info |
|
179 |
||
277
by Chris Coulson
Don't use lzma by default, as dput seems to hang when uploading |
180 |
with tarfile.open(os.path.join(TOPSRCDIR, filename), "w:%s" % options.compression) as tar: |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
181 |
# Add files from bzr
|
182 |
for f in files: |
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
183 |
tar.add(f, os.path.join(topsrcdir, f), filter=tar_filter, recursive=False) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
184 |
|
185 |
# Add Chromium
|
|
186 |
chromium = os.path.relpath(CHROMIUMSRCDIR, TOPSRCDIR) |
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
187 |
tar.add(chromium, os.path.join(topsrcdir, chromium), filter=tar_filter, recursive=True) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
188 |
|
189 |
@subcommand.Command("release") |
|
190 |
def cmd_tag(options, args): |
|
191 |
"""Create a release from the current revision.
|
|
192 |
||
193 |
This command will tag the current revision, and automatically increase
|
|
262
by Chris Coulson
Make a tarball more suitable to packaging |
194 |
the version number. Only for non-trunk branches
|
195 |
"""
|
|
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
196 |
|
197 |
from bzrlib.branch import Branch |
|
198 |
from bzrlib.errors import ( |
|
199 |
NoSuchTag, |
|
200 |
TagAlreadyExists
|
|
201 |
)
|
|
202 |
from bzrlib.workingtree import WorkingTree |
|
203 |
||
204 |
# XXX: Qt-specific
|
|
318.1.1
by Chris Coulson
Build the core library, renderer and sandbox with cmake |
205 |
v = VersionFileParser(os.path.join(TOPSRCDIR, "qt", "VERSION")) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
206 |
|
207 |
branch = Branch.open(TOPSRCDIR) |
|
208 |
lock = branch.lock_write() |
|
209 |
||
210 |
try: |
|
211 |
# XXX: Qt-specific
|
|
357
by Chris Coulson
Move to a 3 part version number, as the "major" and "build" components of Chromium's version have pretty much the same meaning in Oxide. Also, bump the version to 1.0.0, which will be the first version once we create a beta branch |
212 |
tag = "QT_%s_%s_%s" % (v.major, v.minor, v.patch) |
258
by Chris Coulson
Add release-tool.py script for creating a tarball. We don't use bzr export because we want much tighter control of this, and it's not possible to add hooks for export |
213 |
rev_id = branch.last_revision() |
214 |
try: |
|
215 |
existing_tag = branch.tags.lookup_tag(tag) |
|
216 |
except NoSuchTag: |
|
217 |
existing_tag = None |
|
218 |
if existing_tag is not None: |
|
219 |
raise TagAlreadyExists(tag) |
|
220 |
||
221 |
branch.tags.set_tag(tag, rev_id) |
|
222 |
finally: |
|
223 |
lock.unlock() |
|
224 |
||
225 |
v.patch = str(int(v.patch) + 1) |
|
226 |
v.update() |
|
227 |
||
228 |
tree = WorkingTree.open(TOPSRCDIR) |
|
229 |
# XXX: Qt-specific
|
|
230 |
tree.commit(message="Automatically bump qt revision to %s" % str(v), |
|
231 |
allow_pointless=False) |
|
232 |
||
233 |
def main(argv): |
|
234 |
return subcommand.Dispatcher.execute(argv, OptionParser()) |
|
235 |
||
236 |
if __name__ == "__main__": |
|
237 |
sys.exit(main(sys.argv[1:])) |