Flutter Engine
The Flutter Engine
create_tarball.py
Go to the documentation of this file.
1#!/usr/bin/env python3
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 one need to the tarball to follow the
17# Debian naming rules upstream tar files.
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
24import datetime
25import optparse
26import sys
27import tarfile
28from os import listdir
29from os.path import join, split, abspath, dirname
30sys.path.append(join(dirname(__file__), '..'))
31import utils
32
33HOST_OS = utils.GuessOS()
34DART_DIR = abspath(join(dirname(__file__), '..', '..'))
35# Flags.
36verbose = False
37
38# Name of the dart directory when unpacking the tarball.
39versiondir = ''
40
41# Ignore Git/SVN files, checked-in binaries, backup files, etc..
42ignoredPaths = [
43 'buildtools/linux-x64/go',
44 'buildtools/linux-x64/rust',
45 'third_party/7zip',
46 'third_party/android_tools',
47 'third_party/clang',
48 'third_party/d8',
49 'third_party/firefox_jsshell',
50 'third_party/gsutil',
51 'third_party/llvm-build',
52 'third_party/mdn',
53]
54ignoredDirs = [
55 '.cipd',
56 '.git',
57 'benchmarks',
58 'docs',
59 'fuchsia',
60 'parser_testcases',
61 'testcases',
62 'tests',
63]
64ignoredEndings = ['.mk', '.pyc', 'Makefile', '~']
65
66
68 result = optparse.OptionParser()
69 result.add_option("-v",
70 "--verbose",
71 help='Verbose output.',
72 default=False,
73 action="store_true")
74 result.add_option("--tar_filename", default=None, help="The output file.")
75
76 return result
77
78
79def Filter(tar_info):
80 # Get the name of the file relative to the dart directory. Note the
81 # name from the TarInfo does not include a leading slash.
82 assert tar_info.name.startswith(DART_DIR[1:])
83 original_name = tar_info.name[len(DART_DIR):]
84 _, tail = split(original_name)
85 if tail in ignoredDirs:
86 return None
87 for path in ignoredPaths:
88 if original_name.startswith(path):
89 return None
90 for ending in ignoredEndings:
91 if original_name.endswith(ending):
92 return None
93 # Add the dart directory name with version. Place the debian
94 # directory one level over the rest which are placed in the
95 # directory 'dart'. This enables building the Debian packages
96 # out-of-the-box.
97 tar_info.name = join(versiondir, 'dart', original_name)
98 if verbose:
99 print('Adding %s as %s' % (original_name, tar_info.name))
100 return tar_info
101
102
103def GenerateCopyright(filename):
104 with open(join(DART_DIR, 'LICENSE')) as lf:
105 license_lines = lf.readlines()
106
107 with open(filename, 'w') as f:
108 f.write('Name: dart\n')
109 f.write('Maintainer: Dart Team <misc@dartlang.org>\n')
110 f.write('Source: https://dart.googlesource.com/sdk\n')
111 f.write('License:\n')
112 for line in license_lines:
113 f.write(' %s' % line) # Line already contains trailing \n.
114
115
116def GenerateChangeLog(filename, version):
117 with open(filename, 'w') as f:
118 f.write('dart (%s-1) UNRELEASED; urgency=low\n' % version)
119 f.write('\n')
120 f.write(' * Generated file.\n')
121 f.write('\n')
122 f.write(' -- Dart Team <misc@dartlang.org> %s\n' %
123 datetime.datetime.utcnow().strftime('%a, %d %b %Y %X +0000'))
124
125
126def GenerateEmpty(filename):
127 f = open(filename, 'w')
128 f.close()
129
130
131def GenerateGitRevision(filename, git_revision):
132 with open(filename, 'w') as f:
133 f.write(str(git_revision))
134
135def GenerateGitTimestamp(filename, git_timestamp):
136 with open(filename, 'w') as f:
137 f.write(str(git_timestamp))
138
139def CreateTarball(tarfilename):
140 global ignoredPaths # Used for adding the output directory.
141 # Generate the name of the tarfile
142 version = utils.GetVersion()
143 global versiondir
144 versiondir = 'dart-%s' % version
145 debian_dir = 'tools/linux_dist_support/debian'
146 # Don't include the build directory in the tarball (ignored paths
147 # are relative to DART_DIR).
148 builddir = utils.GetBuildDir(HOST_OS)
149 ignoredPaths.append(builddir)
150
151 print('Creating tarball: %s' % tarfilename)
152 with tarfile.open(tarfilename, mode='w:gz') as tar:
153 for f in listdir(DART_DIR):
154 tar.add(join(DART_DIR, f), filter=Filter)
155 for f in listdir(join(DART_DIR, debian_dir)):
156 tar.add(join(DART_DIR, debian_dir, f),
157 arcname='%s/debian/%s' % (versiondir, f))
158
159 with utils.TempDir() as temp_dir:
160 # Generate and add debian/copyright
161 copyright_file = join(temp_dir, 'copyright')
162 GenerateCopyright(copyright_file)
163 tar.add(copyright_file, arcname='%s/debian/copyright' % versiondir)
164
165 # Generate and add debian/changelog
166 change_log = join(temp_dir, 'changelog')
167 GenerateChangeLog(change_log, version)
168 tar.add(change_log, arcname='%s/debian/changelog' % versiondir)
169
170 # For generated version file build dependency, add fake git reflog.
171 empty = join(temp_dir, 'empty')
172 GenerateEmpty(empty)
173 tar.add(empty, arcname='%s/dart/.git/logs/HEAD' % versiondir)
174
175 # For main, add the GIT_REVISION file.
176 if utils.GetChannel() in ['main', 'be']:
177 git_revision = join(temp_dir, 'GIT_REVISION')
179 tar.add(git_revision,
180 arcname='%s/dart/tools/GIT_REVISION' % versiondir)
181
182 # Add GIT_TIMESTAMP file as git is not available in tarball.
183 git_timestamp = join(temp_dir, 'GIT_TIMESTAMP')
185 tar.add(git_timestamp,
186 arcname='%s/dart/tools/GIT_TIMESTAMP' % versiondir)
187
188def Main():
189 if HOST_OS != 'linux':
190 print('Tarball can only be created on linux')
191 return -1
192
193 # Parse the options.
194 parser = BuildOptions()
195 (options, args) = parser.parse_args()
196 if options.verbose:
197 global verbose
198 verbose = True
199
200 tar_filename = options.tar_filename
201 if not tar_filename:
202 tar_filename = join(DART_DIR, utils.GetBuildDir(HOST_OS),
203 'dart-%s.tar.gz' % utils.GetVersion())
204
205 CreateTarball(tar_filename)
206
207
208if __name__ == '__main__':
209 sys.exit(Main())
def GenerateCopyright(filename)
def GenerateGitRevision(filename, git_revision)
def CreateTarball(tarfilename)
def Filter(tar_info)
def GenerateEmpty(filename)
def GenerateGitTimestamp(filename, git_timestamp)
def GenerateChangeLog(filename, version)
def print(*args, **kwargs)
Definition: run_tests.py:49
def GuessOS()
Definition: utils.py:21
def GetBuildDir(host_os)
Definition: utils.py:99
def GetGitTimestamp(git_timestamp_file=None, repo_path=DART_DIR)
Definition: utils.py:458
def GetChannel(version_file=None)
Definition: utils.py:376
def GetVersion(no_git_hash=False, version_file=None, git_revision_file=None)
Definition: utils.py:357
def GetGitRevision(git_revision_file=None, repo_path=DART_DIR)
Definition: utils.py:415
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741