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

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: 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, realpath
33 32
34 HOST_OS = utils.GuessOS() 33 HOST_OS = utils.GuessOS()
34 SCRIPT_DIR = dirname(sys.argv[0])
35 DART_ROOT = realpath(join(SCRIPT_DIR, '..'))
kustermann 2014/02/07 10:10:14 We usually do it like this (see e.g. tools/utils.p
Søren Gjesse 2014/02/07 12:02:51 Done (build.py still uses the other pattern)
35 36
36 # TODO (16582): Remove this when the LICENSE file becomes part of 37 # TODO (16582): Remove this when the LICENSE file becomes part of
37 # all checkouts. 38 # all checkouts.
38 license = [ 39 license = [
39 'This license applies to all parts of Dart that are not externally', 40 'This license applies to all parts of Dart that are not externally',
40 'maintained libraries. The external maintained libraries used by', 41 'maintained libraries. The external maintained libraries used by',
41 'Dart are:', 42 'Dart are:',
42 '', 43 '',
43 '7-Zip - in third_party/7zip', 44 '7-Zip - in third_party/7zip',
44 'JSCRE - in runtime/third_party/jscre', 45 '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.' 90 'OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'
90 ] 91 ]
91 92
92 # Flags. 93 # Flags.
93 verbose = False 94 verbose = False
94 95
95 # Name of the dart directory when unpacking the tarball. 96 # Name of the dart directory when unpacking the tarball.
96 versiondir = '' 97 versiondir = ''
97 98
98 # Ignore Git/SVN files, checked-in binaries, backup files, etc.. 99 # Ignore Git/SVN files, checked-in binaries, backup files, etc..
99 ignoredPaths = ['out', 'tools/testing/bin' 100 ignoredPaths = ['tools/testing/bin'
100 'third_party/7zip', 'third_party/android_tools', 101 'third_party/7zip', 'third_party/android_tools',
101 'third_party/clang', 'third_party/d8', 102 'third_party/clang', 'third_party/d8',
102 'third_party/firefox_jsshell'] 103 'third_party/firefox_jsshell']
103 ignoredDirs = ['.svn', '.git'] 104 ignoredDirs = ['.svn', '.git']
104 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~'] 105 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~']
105 106
106 def BuildOptions(): 107 def BuildOptions():
107 result = optparse.OptionParser() 108 result = optparse.OptionParser()
108 result.add_option("-v", "--verbose", 109 result.add_option("-v", "--verbose",
109 help='Verbose output.', 110 help='Verbose output.',
110 default=False, action="store_true") 111 default=False, action="store_true")
111 return result 112 return result
112 113
113 def Filter(tar_info): 114 def Filter(tar_info):
114 _, tail = split(tar_info.name) 115 # Get the name of the file relative to the dart root directory.
116 original_name = tar_info.name[len(DART_ROOT):]
kustermann 2014/02/07 10:10:14 Add an assert before that: assert tar_info.name
Søren Gjesse 2014/02/07 12:02:51 Done.
117 _, tail = split(original_name)
115 if tail in ignoredDirs: 118 if tail in ignoredDirs:
116 return None 119 return None
117 for path in ignoredPaths: 120 for path in ignoredPaths:
118 if tar_info.name.startswith(path): 121 if original_name.startswith(path):
119 return None 122 return None
120 for ending in ignoredEndings: 123 for ending in ignoredEndings:
121 if tar_info.name.endswith(ending): 124 if original_name.endswith(ending):
122 return None 125 return None
123 # Add the dart directory name with version. 126 # Add the dart directory name with version. Place the debian
124 original_name = tar_info.name 127 # directory one level over the rest which are placed in the
125 # Place the debian directory one level over the rest which are 128 # directory 'dart'. This enables building the Debian packages
126 # placed in the directory 'dart'. This enables building the Debian 129 # out-of-the-box.
127 # packages out-of-the-box. 130 tar_info.name = join(versiondir, 'dart', original_name)
128 tar_info.name = join(versiondir, 'dart', tar_info.name)
129 if verbose: 131 if verbose:
130 print 'Adding %s as %s' % (original_name, tar_info.name) 132 print 'Adding %s as %s' % (original_name, tar_info.name)
131 return tar_info 133 return tar_info
132 134
133 def GenerateCopyright(filename): 135 def GenerateCopyright(filename):
134 license_lines = license 136 license_lines = license
135 try: 137 try:
136 # Currently the LICENSE file is part of a svn-root checkout. 138 # TODO (16582): The LICENSE file is currently not in a normal the
137 lf = open('../LICENSE', 'r') 139 # dart checkout.
138 license_lines = lf.read().splitlines() 140 with open(join(DART_ROOT, 'LICENSE')) as lf:
139 print license_lines 141 license_lines = lf.read().splitlines()
140 lf.close()
141 except: 142 except:
142 pass 143 pass
143 144
144 f = open(filename, 'w') 145 with open(filename, 'w') as f:
145 f.write('Name: dart\n') 146 f.write('Name: dart\n')
146 f.write('Maintainer: Dart Team <misc@dartlang.org>\n') 147 f.write('Maintainer: Dart Team <misc@dartlang.org>\n')
147 f.write('Source: https://code.google.com/p/dart/\n') 148 f.write('Source: https://code.google.com/p/dart/\n')
148 f.write('License:\n') 149 f.write('License:\n')
149 for line in license_lines: 150 for line in license_lines:
150 f.write(' %s\n' % line) 151 f.write(' %s\n' % line)
151 f.close()
152 152
153 def GenerateChangeLog(filename, version): 153 def GenerateChangeLog(filename, version):
154 f = open(filename, 'w') 154 with open(filename, 'w') as f:
155 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version) 155 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version)
156 f.write('\n') 156 f.write('\n')
157 f.write(' * Generated file.\n') 157 f.write(' * Generated file.\n')
158 f.write('\n') 158 f.write('\n')
159 f.write(' -- Dart Team <misc@dartlang.org> %s\n' % 159 f.write(' -- Dart Team <misc@dartlang.org> %s\n' %
160 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000')) 160 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000'))
161 f.close()
162 161
163 def GenerateSvnRevision(filename, svn_revision): 162 def GenerateSvnRevision(filename, svn_revision):
164 f = open(filename, 'w') 163 with open(filename, 'w') as f:
165 f.write(svn_revision) 164 f.write(svn_revision)
166 f.close()
167 165
168 166
169 def CreateTarball(): 167 def CreateTarball():
168 global ignoredPaths # Used for adding the output directory.
170 # Generate the name of the tarfile 169 # Generate the name of the tarfile
171 version = utils.GetVersion() 170 version = utils.GetVersion()
172 global versiondir 171 global versiondir
173 versiondir = 'dart-%s' % version 172 versiondir = 'dart-%s' % version
174 tarname = '%s.tar.gz' % versiondir 173 tarname = '%s.tar.gz' % versiondir
175 debian_dir = 'tools/linux_dist_support/debian' 174 debian_dir = 'tools/linux_dist_support/debian'
176 # Create the tar file in the out directory. 175 # Create the tar file in the build directory.
177 tardir = utils.GetBuildDir(HOST_OS, HOST_OS) 176 tardir = join(DART_ROOT, utils.GetBuildDir(HOST_OS, HOST_OS))
177 # Don't include the build directory in the tarball.
178 ignoredPaths.append(tardir)
178 if not exists(tardir): 179 if not exists(tardir):
179 makedirs(tardir) 180 makedirs(tardir)
180 tarfilename = join(tardir, tarname) 181 tarfilename = join(tardir, tarname)
181 print 'Creating tarball: %s' % (tarfilename) 182 print 'Creating tarball: %s' % tarfilename
182 with tarfile.open(tarfilename, mode='w:gz') as tar: 183 with tarfile.open(tarfilename, mode='w:gz') as tar:
183 for f in listdir('.'): 184 for f in listdir(DART_ROOT):
184 tar.add(f, filter=Filter) 185 tar.add(join(DART_ROOT, f), filter=Filter)
185 for f in listdir(debian_dir): 186 for f in listdir(join(DART_ROOT, debian_dir)):
186 tar.add(join(debian_dir, f), 187 tar.add(join(DART_ROOT, debian_dir, f),
187 arcname='%s/debian/%s' % (versiondir, f)) 188 arcname='%s/debian/%s' % (versiondir, f))
188 189
189 with utils.TempDir() as temp_dir: 190 with utils.TempDir() as temp_dir:
190 # Generate and add debian/copyright 191 # Generate and add debian/copyright
191 copyright = join(temp_dir, 'copyright') 192 copyright = join(temp_dir, 'copyright')
192 GenerateCopyright(copyright) 193 GenerateCopyright(copyright)
193 tar.add(copyright, arcname='%s/debian/copyright' % versiondir) 194 tar.add(copyright, arcname='%s/debian/copyright' % versiondir)
194 195
195 # Generate and add debian/changelog 196 # Generate and add debian/changelog
196 change_log = join(temp_dir, 'changelog') 197 change_log = join(temp_dir, 'changelog')
(...skipping 15 matching lines...) Expand all
212 parser = BuildOptions() 213 parser = BuildOptions()
213 (options, args) = parser.parse_args() 214 (options, args) = parser.parse_args()
214 if options.verbose: 215 if options.verbose:
215 global verbose 216 global verbose
216 verbose = True 217 verbose = True
217 218
218 CreateTarball() 219 CreateTarball()
219 220
220 if __name__ == '__main__': 221 if __name__ == '__main__':
221 sys.exit(Main()) 222 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