Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: tools/create_tarball.py

Issue 157383002: Address additional comments to tarball creation script (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # 2 #
3 # Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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. 5 # BSD-style license that can be found in the LICENSE file.
6 # 6 #
7 7
8 # Script to build a tarball of the Dart source. 8 # Script to build a tarball of the Dart source.
9 # 9 #
10 # The tarball includes all the source needed to build Dart. This 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 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 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 13 # directory. This makes it easy to build Debian packages from the
14 # tarball. 14 # tarball.
15 # 15 #
16 # For building a Debian package renaming the tarball to follow the 16 # For building a Debian package one need to the tarball to follow the
17 # Debian is needed. 17 # Debian naming rules upstream tar files.
18 # 18 #
19 # $ mv dart-XXX.tar.gz dart_XXX.orig.tar.gz 19 # $ mv dart-XXX.tar.gz dart_XXX.orig.tar.gz
20 # $ tar xf dart_XXX.orig.tar.gz 20 # $ tar xf dart_XXX.orig.tar.gz
21 # $ cd dart_XXX 21 # $ cd dart_XXX
22 # $ debuild -us -uc 22 # $ debuild -us -uc
23 23
24 import datetime 24 import datetime
25 import optparse 25 import optparse
26 import sys 26 import sys
27 import tarfile 27 import tarfile
28 import tempfile
29 import utils 28 import utils
30 29
31 from os import listdir, makedirs, remove, rmdir 30 from os import listdir, makedirs
32 from os.path import basename, dirname, join, realpath, exists, isdir, split 31 from os.path import join, exists, split, dirname, abspath
33 32
34 HOST_OS = utils.GuessOS() 33 HOST_OS = utils.GuessOS()
34 DART_DIR = abspath(join(__file__, '..', '..'))
35 35
36 # TODO (16582): Remove this when the LICENSE file becomes part of 36 # TODO (16582): Remove this when the LICENSE file becomes part of
37 # all checkouts. 37 # all checkouts.
38 license = [ 38 license = [
39 'This license applies to all parts of Dart that are not externally', 39 'This license applies to all parts of Dart that are not externally',
40 'maintained libraries. The external maintained libraries used by', 40 'maintained libraries. The external maintained libraries used by',
41 'Dart are:', 41 'Dart are:',
42 '', 42 '',
43 '7-Zip - in third_party/7zip', 43 '7-Zip - in third_party/7zip',
44 'JSCRE - in runtime/third_party/jscre', 44 'JSCRE - in runtime/third_party/jscre',
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 'OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.' 89 'OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'
90 ] 90 ]
91 91
92 # Flags. 92 # Flags.
93 verbose = False 93 verbose = False
94 94
95 # Name of the dart directory when unpacking the tarball. 95 # Name of the dart directory when unpacking the tarball.
96 versiondir = '' 96 versiondir = ''
97 97
98 # Ignore Git/SVN files, checked-in binaries, backup files, etc.. 98 # Ignore Git/SVN files, checked-in binaries, backup files, etc..
99 ignoredPaths = ['out', 'tools/testing/bin' 99 ignoredPaths = ['tools/testing/bin'
100 'third_party/7zip', 'third_party/android_tools', 100 'third_party/7zip', 'third_party/android_tools',
101 'third_party/clang', 'third_party/d8', 101 'third_party/clang', 'third_party/d8',
102 'third_party/firefox_jsshell'] 102 'third_party/firefox_jsshell']
103 ignoredDirs = ['.svn', '.git'] 103 ignoredDirs = ['.svn', '.git']
104 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~'] 104 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~']
105 105
106 def BuildOptions(): 106 def BuildOptions():
107 result = optparse.OptionParser() 107 result = optparse.OptionParser()
108 result.add_option("-v", "--verbose", 108 result.add_option("-v", "--verbose",
109 help='Verbose output.', 109 help='Verbose output.',
110 default=False, action="store_true") 110 default=False, action="store_true")
111 return result 111 return result
112 112
113 def Filter(tar_info): 113 def Filter(tar_info):
114 _, tail = split(tar_info.name) 114 # Get the name of the file relative to the dart directory. Note the
115 # name from the TarInfo does not include a leading slash.
116 assert tar_info.name.startswith(DART_DIR[1:])
117 original_name = tar_info.name[len(DART_DIR):]
118 _, tail = split(original_name)
115 if tail in ignoredDirs: 119 if tail in ignoredDirs:
116 return None 120 return None
117 for path in ignoredPaths: 121 for path in ignoredPaths:
118 if tar_info.name.startswith(path): 122 if original_name.startswith(path):
119 return None 123 return None
120 for ending in ignoredEndings: 124 for ending in ignoredEndings:
121 if tar_info.name.endswith(ending): 125 if original_name.endswith(ending):
122 return None 126 return None
123 # Add the dart directory name with version. 127 # Add the dart directory name with version. Place the debian
124 original_name = tar_info.name 128 # directory one level over the rest which are placed in the
125 # Place the debian directory one level over the rest which are 129 # directory 'dart'. This enables building the Debian packages
126 # placed in the directory 'dart'. This enables building the Debian 130 # out-of-the-box.
127 # packages out-of-the-box. 131 tar_info.name = join(versiondir, 'dart', original_name)
128 tar_info.name = join(versiondir, 'dart', tar_info.name)
129 if verbose: 132 if verbose:
130 print 'Adding %s as %s' % (original_name, tar_info.name) 133 print 'Adding %s as %s' % (original_name, tar_info.name)
131 return tar_info 134 return tar_info
132 135
133 def GenerateCopyright(filename): 136 def GenerateCopyright(filename):
134 license_lines = license 137 license_lines = license
135 try: 138 try:
136 # Currently the LICENSE file is part of a svn-root checkout. 139 # TODO (16582): The LICENSE file is currently not in a normal the
137 lf = open('../LICENSE', 'r') 140 # dart checkout.
138 license_lines = lf.read().splitlines() 141 with open(join(DART_DIR, 'LICENSE')) as lf:
139 print license_lines 142 license_lines = lf.read().splitlines()
140 lf.close()
141 except: 143 except:
142 pass 144 pass
143 145
144 f = open(filename, 'w') 146 with open(filename, 'w') as f:
145 f.write('Name: dart\n') 147 f.write('Name: dart\n')
146 f.write('Maintainer: Dart Team <misc@dartlang.org>\n') 148 f.write('Maintainer: Dart Team <misc@dartlang.org>\n')
147 f.write('Source: https://code.google.com/p/dart/\n') 149 f.write('Source: https://code.google.com/p/dart/\n')
148 f.write('License:\n') 150 f.write('License:\n')
149 for line in license_lines: 151 for line in license_lines:
150 f.write(' %s\n' % line) 152 f.write(' %s\n' % line)
151 f.close()
152 153
153 def GenerateChangeLog(filename, version): 154 def GenerateChangeLog(filename, version):
154 f = open(filename, 'w') 155 with open(filename, 'w') as f:
155 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version) 156 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version)
156 f.write('\n') 157 f.write('\n')
157 f.write(' * Generated file.\n') 158 f.write(' * Generated file.\n')
158 f.write('\n') 159 f.write('\n')
159 f.write(' -- Dart Team <misc@dartlang.org> %s\n' % 160 f.write(' -- Dart Team <misc@dartlang.org> %s\n' %
160 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000')) 161 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000'))
161 f.close()
162 162
163 def GenerateSvnRevision(filename, svn_revision): 163 def GenerateSvnRevision(filename, svn_revision):
164 f = open(filename, 'w') 164 with open(filename, 'w') as f:
165 f.write(svn_revision) 165 f.write(svn_revision)
166 f.close()
167 166
168 167
169 def CreateTarball(): 168 def CreateTarball():
169 global ignoredPaths # Used for adding the output directory.
170 # Generate the name of the tarfile 170 # Generate the name of the tarfile
171 version = utils.GetVersion() 171 version = utils.GetVersion()
172 global versiondir 172 global versiondir
173 versiondir = 'dart-%s' % version 173 versiondir = 'dart-%s' % version
174 tarname = '%s.tar.gz' % versiondir 174 tarname = '%s.tar.gz' % versiondir
175 debian_dir = 'tools/linux_dist_support/debian' 175 debian_dir = 'tools/linux_dist_support/debian'
176 # Create the tar file in the out directory. 176 # Create the tar file in the build directory.
177 tardir = utils.GetBuildDir(HOST_OS, HOST_OS) 177 tardir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS))
178 # Don't include the build directory in the tarball.
179 ignoredPaths.append(tardir)
178 if not exists(tardir): 180 if not exists(tardir):
179 makedirs(tardir) 181 makedirs(tardir)
180 tarfilename = join(tardir, tarname) 182 tarfilename = join(tardir, tarname)
181 print 'Creating tarball: %s' % (tarfilename) 183 print 'Creating tarball: %s' % tarfilename
182 with tarfile.open(tarfilename, mode='w:gz') as tar: 184 with tarfile.open(tarfilename, mode='w:gz') as tar:
183 for f in listdir('.'): 185 for f in listdir(DART_DIR):
184 tar.add(f, filter=Filter) 186 tar.add(join(DART_DIR, f), filter=Filter)
185 for f in listdir(debian_dir): 187 for f in listdir(join(DART_DIR, debian_dir)):
186 tar.add(join(debian_dir, f), 188 tar.add(join(DART_DIR, debian_dir, f),
187 arcname='%s/debian/%s' % (versiondir, f)) 189 arcname='%s/debian/%s' % (versiondir, f))
188 190
189 with utils.TempDir() as temp_dir: 191 with utils.TempDir() as temp_dir:
190 # Generate and add debian/copyright 192 # Generate and add debian/copyright
191 copyright = join(temp_dir, 'copyright') 193 copyright = join(temp_dir, 'copyright')
192 GenerateCopyright(copyright) 194 GenerateCopyright(copyright)
193 tar.add(copyright, arcname='%s/debian/copyright' % versiondir) 195 tar.add(copyright, arcname='%s/debian/copyright' % versiondir)
194 196
195 # Generate and add debian/changelog 197 # Generate and add debian/changelog
196 change_log = join(temp_dir, 'changelog') 198 change_log = join(temp_dir, 'changelog')
(...skipping 15 matching lines...) Expand all
212 parser = BuildOptions() 214 parser = BuildOptions()
213 (options, args) = parser.parse_args() 215 (options, args) = parser.parse_args()
214 if options.verbose: 216 if options.verbose:
215 global verbose 217 global verbose
216 verbose = True 218 verbose = True
217 219
218 CreateTarball() 220 CreateTarball()
219 221
220 if __name__ == '__main__': 222 if __name__ == '__main__':
221 sys.exit(Main()) 223 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698