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

Side by Side Diff: tools/create_tarball.py

Issue 154073002: Add script for generating a source tarball and rules for bilding a Debian package (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed final 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
OLDNEW
(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.
kustermann 2014/02/06 15:28:04 "to follow the Debian" sounds strange.
Søren Gjesse 2014/02/07 09:52:43 Done.
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
kustermann 2014/02/06 15:28:04 tempfile not used.
Søren Gjesse 2014/02/07 09:52:43 Removed.
29 import utils
30
31 from os import listdir, makedirs, remove, rmdir
kustermann 2014/02/06 15:28:04 remove, rmdir not used.
Søren Gjesse 2014/02/07 09:52:43 Removed.
32 from os.path import basename, dirname, join, realpath, exists, isdir, split
kustermann 2014/02/06 15:28:04 basename, dirname, realpath, isdir unused.
Søren Gjesse 2014/02/07 09:52:43 Removed.
33
34 HOST_OS = utils.GuessOS()
35
36 # TODO (16582): Remove this when the LICENSE file becomes part of
37 # all checkouts.
38 license = [
kustermann 2014/02/06 15:28:04 Python supports multiline strings, why don't you d
Søren Gjesse 2014/02/07 09:52:43 This will go away when https://codereview.chromium
39 'This license applies to all parts of Dart that are not externally',
40 'maintained libraries. The external maintained libraries used by',
41 'Dart are:',
42 '',
43 '7-Zip - in third_party/7zip',
44 'JSCRE - in runtime/third_party/jscre',
45 'Ant - in third_party/apache_ant',
46 'args4j - in third_party/args4j',
47 'bzip2 - in third_party/bzip2',
48 'Commons IO - in third_party/commons-io',
49 'Commons Lang in third_party/commons-lang',
50 'dromaeo - in samples/third_party/dromaeo',
51 'Eclipse - in third_party/eclipse',
52 'gsutil - in third_party/gsutil',
53 'Guava - in third_party/guava',
54 'hamcrest - in third_party/hamcrest',
55 'Httplib2 - in samples/third_party/httplib2',
56 'JSON - in third_party/json',
57 'JUnit - in third_party/junit',
58 'Oauth - in samples/third_party/oauth2client',
59 'weberknecht - in third_party/weberknecht',
60 'fest - in third_party/fest',
61 'mockito - in third_party/mockito',
62 '',
63 'The libraries may have their own licenses; we recommend you read them,',
64 'as their terms may differ from the terms below.',
65 '',
66 'Copyright 2012, the Dart project authors. All rights reserved.',
67 'Redistribution and use in source and binary forms, with or without',
68 'modification, are permitted provided that the following conditions are',
69 'met:',
70 ' * Redistributions of source code must retain the above copyright',
71 ' notice, this list of conditions and the following disclaimer.',
72 ' * Redistributions in binary form must reproduce the above',
73 ' copyright notice, this list of conditions and the following',
74 ' disclaimer in the documentation and/or other materials provided',
75 ' with the distribution.',
76 ' * Neither the name of Google Inc. nor the names of its',
77 ' contributors may be used to endorse or promote products derived',
78 ' from this software without specific prior written permission.',
79 'THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS',
80 '"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT',
81 'LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR',
82 'A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT',
83 'OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,',
84 'SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT',
85 'LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,',
86 'DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY',
87 'THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT',
88 '(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE',
89 'OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.'
90 ]
91
92 # Flags.
93 verbose = False
94
95 # Name of the dart directory when unpacking the tarball.
96 versiondir = ''
97
98 # Ignore Git/SVN files, checked-in binaries, backup files, etc..
99 ignoredPaths = ['out', 'tools/testing/bin'
100 'third_party/7zip', 'third_party/android_tools',
101 'third_party/clang', 'third_party/d8',
102 'third_party/firefox_jsshell']
103 ignoredDirs = ['.svn', '.git']
104 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~']
105
106 def BuildOptions():
107 result = optparse.OptionParser()
108 result.add_option("-v", "--verbose",
109 help='Verbose output.',
110 default=False, action="store_true")
111 return result
112
113 def Filter(tar_info):
114 _, tail = split(tar_info.name)
115 if tail in ignoredDirs:
116 return None
117 for path in ignoredPaths:
118 if tar_info.name.startswith(path):
119 return None
120 for ending in ignoredEndings:
121 if tar_info.name.endswith(ending):
122 return None
123 # Add the dart directory name with version.
124 original_name = tar_info.name
125 # Place the debian directory one level over the rest which are
126 # placed in the directory 'dart'. This enables building the Debian
127 # packages out-of-the-box.
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')
kustermann 2014/02/06 15:28:04 'r' is the default + using context manager?
Søren Gjesse 2014/02/07 09:52:43 Done.
138 license_lines = lf.read().splitlines()
139 print license_lines
kustermann 2014/02/06 15:28:04 Why print?
Søren Gjesse 2014/02/07 09:52:43 Debug code. Removed.
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'))
kustermann 2014/02/06 15:28:04 Maybe use a multiline string? [see comment at lice
Søren Gjesse 2014/02/07 09:52:43 It does not indent as well as this I think.
161 f.close()
162
163 def GenerateSvnRevision(filename, svn_revision):
164 f = open(filename, 'w')
kustermann 2014/02/06 15:28:04 It's usually nicer (and safer if an exception occu
Søren Gjesse 2014/02/07 09:52:43 Done.
165 f.write(svn_revision)
166 f.close()
167
168
169 def CreateTarball():
170 # Generate the name of the tarfile
171 version = utils.GetVersion()
172 global versiondir
173 versiondir = 'dart-%s' % version
174 tarname = '%s.tar.gz' % versiondir
175 debian_dir = 'tools/linux_dist_support/debian'
176 # Create the tar file in the out directory.
177 tardir = utils.GetBuildDir(HOST_OS, HOST_OS)
178 if not exists(tardir):
179 makedirs(tardir)
180 tarfilename = join(tardir, tarname)
kustermann 2014/02/06 15:28:04 It's slightly spooky, that you tar up the dart dir
Søren Gjesse 2014/02/07 09:52:43 I started out by generating it in the parent direc
181 print 'Creating tarball: %s' % (tarfilename)
kustermann 2014/02/06 15:28:04 No parenthesis needed!
Søren Gjesse 2014/02/07 09:52:43 Done.
182 with tarfile.open(tarfilename, mode='w:gz') as tar:
183 for f in listdir('.'):
kustermann 2014/02/06 15:28:04 You assume this is run from the root of the dart d
Søren Gjesse 2014/02/07 09:52:43 Done. The script can now be run from anywhere.
184 tar.add(f, filter=Filter)
185 for f in listdir(debian_dir):
186 tar.add(join(debian_dir, f),
187 arcname='%s/debian/%s' % (versiondir, f))
188
189 with utils.TempDir() as temp_dir:
190 # Generate and add debian/copyright
191 copyright = join(temp_dir, 'copyright')
192 GenerateCopyright(copyright)
193 tar.add(copyright, arcname='%s/debian/copyright' % versiondir)
194
195 # Generate and add debian/changelog
196 change_log = join(temp_dir, 'changelog')
197 GenerateChangeLog(change_log, version)
198 tar.add(change_log, arcname='%s/debian/changelog' % versiondir)
199
200 # For bleeding_edge add the SVN_REVISION file.
201 if utils.GetChannel() == 'be':
202 svn_revision = join(temp_dir, 'SVN_REVISION')
203 GenerateSvnRevision(svn_revision, utils.GetSVNRevision())
204 tar.add(svn_revision, arcname='%s/dart/tools/SVN_REVISION' % versiondir)
205
206 def Main():
207 if HOST_OS != 'linux':
208 print 'Tarball can only be created on linux'
209 return -1
210
211 # Parse the options.
212 parser = BuildOptions()
213 (options, args) = parser.parse_args()
214 if options.verbose:
215 global verbose
216 verbose = True
217
218 CreateTarball()
219
220 if __name__ == '__main__':
221 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | tools/linux_dist_support/debian/compat » ('j') | tools/linux_dist_support/debian/control » ('J')

Powered by Google App Engine
This is Rietveld 408576698