OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # | |
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | |
4 # for details. All rights reserved. Use of this source code is governed by a | |
5 # BSD-style license that can be found in the LICENSE file. | |
6 # | |
7 | |
8 # Script to build a tarball of the Dart source. | |
9 # | |
10 # The tarball includes all the source needed to build Dart. This | |
11 # includes source in third_party. As part of creating the tarball the | |
12 # files used to build Debian packages are copied to a top-level debian | |
13 # directory. This makes it easy to build Debian packages from the | |
14 # tarball. | |
15 # | |
16 # For building a Debian package renaming the tarball to follow the | |
17 # Debian is needed. | |
18 # | |
19 # $ mv dart-XXX.tar.gz dart_XXX.orig.tar.gz | |
20 # $ tar xf dart_XXX.orig.tar.gz | |
21 # $ cd dart_XXX | |
22 # $ debuild -us -uc | |
23 | |
24 import datetime | |
25 import optparse | |
26 import sys | |
27 import tarfile | |
28 import tempfile | |
29 import utils | |
30 | |
31 from os import listdir, makedirs, remove, rmdir | |
32 from os.path import basename, dirname, join, realpath, exists, isdir, split | |
33 | |
34 # TODO (sgjesse): Remove this when the LICENSE file becomes part of | |
ricow1
2014/02/06 08:45:26
Feel free to file a bug and assign it to me, and I
Søren Gjesse
2014/02/06 13:15:31
Thanks, done.
| |
35 # all checkouts. | |
36 license = [ | |
37 'This license applies to all parts of Dart that are not externally', | |
38 'maintained libraries. The external maintained libraries used by', | |
39 'Dart are:', | |
40 '', | |
41 '7-Zip - in third_party/7zip', | |
42 'JSCRE - in runtime/third_party/jscre', | |
43 'Ant - in third_party/apache_ant', | |
44 'args4j - in third_party/args4j', | |
45 'bzip2 - in third_party/bzip2', | |
46 'Commons IO - in third_party/commons-io', | |
47 'Commons Lang in third_party/commons-lang', | |
48 'dromaeo - in samples/third_party/dromaeo', | |
49 'Eclipse - in third_party/eclipse', | |
50 'gsutil - in third_party/gsutil', | |
51 'Guava - in third_party/guava', | |
52 'hamcrest - in third_party/hamcrest', | |
53 'Httplib2 - in samples/third_party/httplib2', | |
54 'JSON - in third_party/json', | |
55 'JUnit - in third_party/junit', | |
56 'Oauth - in samples/third_party/oauth2client', | |
57 'weberknecht - in third_party/weberknecht', | |
58 'fest - in third_party/fest', | |
59 'mockito - in third_party/mockito', | |
60 '', | |
61 'The libraries may have their own licenses; we recommend you read them,', | |
62 'as their terms may differ from the terms below.', | |
63 '', | |
64 'Copyright 2012, the Dart project authors. All rights reserved.', | |
65 'Redistribution and use in source and binary forms, with or without', | |
66 'modification, are permitted provided that the following conditions are', | |
67 'met:', | |
68 ' * Redistributions of source code must retain the above copyright', | |
69 ' notice, this list of conditions and the following disclaimer.', | |
70 ' * Redistributions in binary form must reproduce the above', | |
71 ' copyright notice, this list of conditions and the following', | |
72 ' disclaimer in the documentation and/or other materials provided', | |
73 ' with the distribution.', | |
74 ' * Neither the name of Google Inc. nor the names of its', | |
75 ' contributors may be used to endorse or promote products derived', | |
76 ' from this software without specific prior written permission.', | |
77 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS', | |
78 '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT', | |
79 'LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR', | |
80 'A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT', | |
81 'OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,', | |
82 'SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT', | |
83 'LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,', | |
84 'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY', | |
85 'THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT', | |
86 '(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE', | |
87 'OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.' | |
88 ] | |
89 | |
90 # Flags. | |
91 verbose = False | |
92 | |
93 # Name of the dart directory when unpacking the tarball. | |
94 versiondir = '' | |
95 | |
96 # Ignore Git/SVN files, checked-in binaries, backup files, etc.. | |
97 ignoredPaths = ['out', 'tools/testing/bin' | |
98 'third_party/7zip', 'third_party/android_tools', | |
99 'third_party/clang', 'third_party/d8'] | |
ricow1
2014/02/06 08:45:26
maybe add third_party/firefox_jsshell
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
100 ignoredDirs = ['.svn', '.git'] | |
101 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~'] | |
102 | |
103 def BuildOptions(): | |
104 result = optparse.OptionParser() | |
105 result.add_option("-v", "--verbose", | |
106 help='Verbose output.', | |
107 default=False, action="store_true") | |
108 return result | |
109 | |
110 def Filter(tar_info): | |
111 _, tail = split(tar_info.name) | |
112 if tail in ignoredDirs: | |
113 return None | |
114 for path in ignoredPaths: | |
115 if tar_info.name.startswith(path): | |
116 return None | |
117 for ending in ignoredEndings: | |
118 if tar_info.name.endswith(ending): | |
119 return None | |
120 # Add the dart directory name with version. | |
121 original_name = tar_info.name | |
122 # Place the debian directory one level over the rest which are | |
123 # placed in the directory 'dart'. This enables building the Debian | |
124 # packages out-of-the-box. | |
125 if tar_info.name.startswith('debian/'): | |
ricow1
2014/02/06 08:45:26
this now starts with tools/linux_dist_support/debi
Søren Gjesse
2014/02/06 13:15:31
Yes, I forgot to remove this, done
| |
126 tar_info.name = join(versiondir, tar_info.name) | |
127 else: | |
128 tar_info.name = join(versiondir, 'dart', tar_info.name) | |
129 if verbose: | |
130 print 'Adding %s as %s' % (original_name, tar_info.name) | |
131 return tar_info | |
132 | |
133 def GenerateCopyright(filename): | |
134 license_lines = license | |
135 try: | |
136 # Currently the LICENSE file is part of a svn-root checkout. | |
137 lf = open('../LICENSE', 'r') | |
138 license_lines = lf.read().splitlines() | |
139 print license_lines | |
140 lf.close() | |
141 except: | |
142 pass | |
143 | |
144 f = open(filename, 'w') | |
145 f.write('Name: dart\n') | |
146 f.write('Maintainer: Dart Team <misc@dartlang.org>\n') | |
147 f.write('Source: https://code.google.com/p/dart/\n') | |
148 f.write('License:\n') | |
149 for line in license_lines: | |
150 f.write(' %s\n' % line) | |
151 f.close() | |
152 | |
153 def GenerateChangeLog(filename, version): | |
154 f = open(filename, 'w') | |
155 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version) | |
156 f.write('\n') | |
157 f.write(' * Generated file.\n') | |
158 f.write('\n') | |
159 f.write(' -- Dart Team <misc@dartlang.org> %s\n' % | |
160 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000')) | |
161 f.close() | |
162 | |
163 def GenerateSvnRevision(filename, svn_revision): | |
164 f = open(filename, 'w') | |
165 f.write(svn_revision) | |
166 f.close() | |
167 | |
168 | |
169 def CreateTarball(): | |
170 global ignoredPaths | |
ricow1
2014/02/06 08:45:26
why do you global this?
Søren Gjesse
2014/02/06 13:15:31
From some testing, removed.
| |
171 | |
172 # Generate the name of the tarfile | |
173 version = utils.GetVersion() | |
174 global versiondir | |
175 versiondir = 'dart-%s' % version | |
176 tarname = '%s.tar.gz' % versiondir | |
177 # Create the tar file in the out directory. | |
178 tardir = 'out' | |
ricow1
2014/02/06 08:45:26
use utils.GetBuildDir
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
179 if not exists(tardir): | |
180 makedirs(tardir) | |
181 tarfilename = join(tardir, tarname) | |
182 print 'Creating tarball: %s' % (tarfilename) | |
183 tar = tarfile.open(tarfilename, mode='w:gz') | |
ricow1
2014/02/06 08:45:26
I think we assume python 2.7 - so you could do wit
Søren Gjesse
2014/02/06 13:15:31
Good point, done.
| |
184 for f in listdir('.'): | |
185 tar.add(f, filter=Filter) | |
186 debian_dir = 'tools/linux_dist_support/debian' | |
ricow1
2014/02/06 08:45:26
maybe put this at the top of the file collecting a
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
187 for f in listdir(debian_dir): | |
188 tar.add(join('tools/linux_dist_support/debian', f), | |
ricow1
2014/02/06 08:45:26
tar.add(join(debian_dir, f), ...
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
189 arcname='%s/debian/%s' % (versiondir, f)) | |
190 | |
191 temp_dir = tempfile.mkdtemp() | |
ricow1
2014/02/06 08:45:26
you can use
with utils.TempDir() as temp_dir:
the
Søren Gjesse
2014/02/06 13:15:31
Nice!
| |
192 | |
193 # Generate and add debian/copyright | |
194 copyright = join(temp_dir, 'copyright') | |
195 GenerateCopyright(copyright) | |
196 tar.add(copyright, arcname='%s/debian/copyright' % versiondir) | |
197 | |
198 # Generate and add debian/changelog | |
199 change_log = join(temp_dir, 'changelog') | |
200 GenerateChangeLog(change_log, version) | |
201 tar.add(change_log, arcname='%s/debian/changelog' % versiondir) | |
202 | |
203 # For bleeding_edge add the SVN_REVISION file. | |
204 full_version = utils.ReadVersionFile() | |
ricow1
2014/02/06 08:45:26
use utils.GetChannel() instead (in the if statemen
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
205 if full_version.channel == 'be': | |
206 svn_revision = join(temp_dir, 'SVN_REVISION') | |
207 GenerateSvnRevision(svn_revision, utils.GetSVNRevision()) | |
208 tar.add(svn_revision, arcname='%s/dart/tools/SVN_REVISION' % versiondir) | |
209 | |
210 remove(copyright) | |
211 remove(change_log) | |
212 remove(svn_revision) | |
213 rmdir(temp_dir) | |
214 | |
215 # Tarball done. | |
216 tar.close() | |
217 | |
218 def Main(): | |
219 if utils.GuessOS() != 'linux': | |
220 print 'Tarball can only be created on linux' | |
221 return 0 | |
ricow1
2014/02/06 08:45:26
maybe return non zero here?
Søren Gjesse
2014/02/06 13:15:31
Done.
| |
222 | |
223 # Parse the options. | |
224 parser = BuildOptions() | |
225 (options, args) = parser.parse_args() | |
226 if options.verbose: | |
227 global verbose | |
228 verbose = True | |
229 | |
230 CreateTarball() | |
231 | |
232 if __name__ == '__main__': | |
233 sys.exit(Main()) | |
OLD | NEW |