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

Side by Side Diff: tools/create_tarball.py

Issue 197313010: Initial refactorings to support archiving the src and debian package builds. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 9 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 | « tools/create_debian_packages.py ('k') | 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
(...skipping 14 matching lines...) Expand all
25 import optparse 25 import optparse
26 import sys 26 import sys
27 import tarfile 27 import tarfile
28 import utils 28 import utils
29 29
30 from os import listdir, makedirs 30 from os import listdir, makedirs
31 from os.path import join, exists, split, dirname, abspath 31 from os.path import join, exists, split, dirname, abspath
32 32
33 HOST_OS = utils.GuessOS() 33 HOST_OS = utils.GuessOS()
34 DART_DIR = abspath(join(__file__, '..', '..')) 34 DART_DIR = abspath(join(__file__, '..', '..'))
35
36 # Flags. 35 # Flags.
37 verbose = False 36 verbose = False
38 37
39 # Name of the dart directory when unpacking the tarball. 38 # Name of the dart directory when unpacking the tarball.
40 versiondir = '' 39 versiondir = ''
41 40
42 # Ignore Git/SVN files, checked-in binaries, backup files, etc.. 41 # Ignore Git/SVN files, checked-in binaries, backup files, etc..
43 ignoredPaths = ['tools/testing/bin', 42 ignoredPaths = ['tools/testing/bin',
44 'third_party/7zip', 'third_party/android_tools', 43 'third_party/7zip', 'third_party/android_tools',
45 'third_party/clang', 'third_party/d8', 44 'third_party/clang', 'third_party/d8',
46 'third_party/firefox_jsshell'] 45 'third_party/firefox_jsshell']
47 ignoredDirs = ['.svn', '.git'] 46 ignoredDirs = ['.svn', '.git']
48 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~'] 47 ignoredEndings = ['.mk', '.pyc', 'Makefile', '~']
49 48
50 def BuildOptions(): 49 def BuildOptions():
51 result = optparse.OptionParser() 50 result = optparse.OptionParser()
52 result.add_option("-v", "--verbose", 51 result.add_option("-v", "--verbose",
53 help='Verbose output.', 52 help='Verbose output.',
54 default=False, action="store_true") 53 default=False, action="store_true")
54 result.add_option("--tar_filename",
55 default=None,
56 help="The output file.")
57
55 return result 58 return result
56 59
57 def Filter(tar_info): 60 def Filter(tar_info):
58 # Get the name of the file relative to the dart directory. Note the 61 # Get the name of the file relative to the dart directory. Note the
59 # name from the TarInfo does not include a leading slash. 62 # name from the TarInfo does not include a leading slash.
60 assert tar_info.name.startswith(DART_DIR[1:]) 63 assert tar_info.name.startswith(DART_DIR[1:])
61 original_name = tar_info.name[len(DART_DIR):] 64 original_name = tar_info.name[len(DART_DIR):]
62 _, tail = split(original_name) 65 _, tail = split(original_name)
63 if tail in ignoredDirs: 66 if tail in ignoredDirs:
64 return None 67 return None
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 f.write(' * Generated file.\n') 99 f.write(' * Generated file.\n')
97 f.write('\n') 100 f.write('\n')
98 f.write(' -- Dart Team <misc@dartlang.org> %s\n' % 101 f.write(' -- Dart Team <misc@dartlang.org> %s\n' %
99 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000')) 102 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000'))
100 103
101 def GenerateSvnRevision(filename, svn_revision): 104 def GenerateSvnRevision(filename, svn_revision):
102 with open(filename, 'w') as f: 105 with open(filename, 'w') as f:
103 f.write(svn_revision) 106 f.write(svn_revision)
104 107
105 108
106 def CreateTarball(): 109 def CreateTarball(tarfilename):
107 global ignoredPaths # Used for adding the output directory. 110 global ignoredPaths # Used for adding the output directory.
108 # Generate the name of the tarfile 111 # Generate the name of the tarfile
109 version = utils.GetVersion() 112 version = utils.GetVersion()
110 global versiondir 113 global versiondir
111 versiondir = 'dart-%s' % version 114 versiondir = 'dart-%s' % version
112 tarname = '%s.tar.gz' % versiondir
113 debian_dir = 'tools/linux_dist_support/debian' 115 debian_dir = 'tools/linux_dist_support/debian'
114 # Create the tar file in the build directory.
115 builddir = utils.GetBuildDir(HOST_OS, HOST_OS)
116 tardir = join(DART_DIR, builddir)
117 # Don't include the build directory in the tarball (ignored paths 116 # Don't include the build directory in the tarball (ignored paths
118 # are relative to DART_DIR). 117 # are relative to DART_DIR).
118 builddir = utils.GetBuildDir(HOST_OS, HOST_OS)
119 ignoredPaths.append(builddir) 119 ignoredPaths.append(builddir)
120 if not exists(tardir): 120
121 makedirs(tardir)
122 tarfilename = join(tardir, tarname)
123 print 'Creating tarball: %s' % tarfilename 121 print 'Creating tarball: %s' % tarfilename
124 with tarfile.open(tarfilename, mode='w:gz') as tar: 122 with tarfile.open(tarfilename, mode='w:gz') as tar:
125 for f in listdir(DART_DIR): 123 for f in listdir(DART_DIR):
126 tar.add(join(DART_DIR, f), filter=Filter) 124 tar.add(join(DART_DIR, f), filter=Filter)
127 for f in listdir(join(DART_DIR, debian_dir)): 125 for f in listdir(join(DART_DIR, debian_dir)):
128 tar.add(join(DART_DIR, debian_dir, f), 126 tar.add(join(DART_DIR, debian_dir, f),
129 arcname='%s/debian/%s' % (versiondir, f)) 127 arcname='%s/debian/%s' % (versiondir, f))
130 128
131 with utils.TempDir() as temp_dir: 129 with utils.TempDir() as temp_dir:
132 # Generate and add debian/copyright 130 # Generate and add debian/copyright
(...skipping 17 matching lines...) Expand all
150 print 'Tarball can only be created on linux' 148 print 'Tarball can only be created on linux'
151 return -1 149 return -1
152 150
153 # Parse the options. 151 # Parse the options.
154 parser = BuildOptions() 152 parser = BuildOptions()
155 (options, args) = parser.parse_args() 153 (options, args) = parser.parse_args()
156 if options.verbose: 154 if options.verbose:
157 global verbose 155 global verbose
158 verbose = True 156 verbose = True
159 157
160 CreateTarball() 158 if not options.tar_filename:
159 raise Exception('Please specify an output filename')
160
161 CreateTarball(options.tar_filename)
161 162
162 if __name__ == '__main__': 163 if __name__ == '__main__':
163 sys.exit(Main()) 164 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/create_debian_packages.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698