Flutter Engine
The Flutter Engine
create_debian_packages.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 Debian packages from a Dart tarball. The script
9# will build a source package and a 32-bit (i386) and 64-bit (amd64)
10# binary packages.
11
12import optparse
13import os
14import sys
15import tarfile
16import subprocess
17from os.path import join, exists, abspath, dirname
18sys.path.append(join(dirname(__file__), '..'))
19import utils
20from shutil import copyfile
21
22HOST_OS = utils.GuessOS()
23HOST_CPUS = utils.GuessCpus()
24DART_DIR = abspath(join(dirname(__file__), '..', '..'))
25
26GN_ARCH_TO_DEBIAN_ARCH = {
27 "ia32": "i386",
28 "x64": "amd64",
29 "arm": "armhf",
30 "arm64": "arm64",
31 "riscv64": "riscv64",
32}
33
34
36 result = optparse.OptionParser()
37 result.add_option("--tar_filename",
38 default=None,
39 help="The tar file to build from.")
40 result.add_option("--out_dir",
41 default=None,
42 help="Where to put the packages.")
43 result.add_option("-a",
44 "--arch",
45 help='Target architectures (comma-separated).',
46 metavar='[all,ia32,x64,arm,arm64,riscv64]',
47 default='x64')
48 result.add_option("-t",
49 "--toolchain",
50 help='Cross-compilation toolchain prefix',
51 default=None)
52
53 return result
54
55
56def RunBuildPackage(opt, cwd, toolchain=None):
57 env = os.environ.copy()
58 if toolchain != None:
59 env["TOOLCHAIN"] = '--toolchain=' + toolchain
60 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS]
61 cmd.extend(opt)
62 process = subprocess.check_call(cmd, cwd=cwd, env=env)
63
64
65def BuildDebianPackage(tarball, out_dir, arches, toolchain):
66 version = utils.GetVersion()
67 tarroot = 'dart-%s' % version
68 origtarname = 'dart_%s.orig.tar.gz' % version
69
70 if not exists(tarball):
71 print('Source tarball not found')
72 return -1
73
74 with utils.TempDir() as temp_dir:
75 origtarball = join(temp_dir, origtarname)
76 copyfile(tarball, origtarball)
77
78 with tarfile.open(origtarball) as tar:
79 tar.extractall(path=temp_dir)
80
81 # Build source package.
82 print("Building source package")
83 RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot))
84
85 # Build binary package(s).
86 for arch in arches:
87 print("Building %s package" % arch)
89 ['-B', '-a', GN_ARCH_TO_DEBIAN_ARCH[arch], '-us', '-uc'],
90 join(temp_dir, tarroot))
91
92 # Copy the Debian package files to the build directory.
93 debbase = 'dart_%s' % version
94 source_package = [
95 '%s-1.dsc' % debbase,
96 '%s.orig.tar.gz' % debbase,
97 '%s-1.debian.tar.xz' % debbase
98 ]
99 for name in source_package:
100 copyfile(join(temp_dir, name), join(out_dir, name))
101 for arch in arches:
102 name = '%s-1_%s.deb' % (debbase, GN_ARCH_TO_DEBIAN_ARCH[arch])
103 copyfile(join(temp_dir, name), join(out_dir, name))
104
105
106def Main():
107 if HOST_OS != 'linux':
108 print('Debian build only supported on linux')
109 return -1
110
111 options, args = BuildOptions().parse_args()
112 out_dir = options.out_dir
113 tar_filename = options.tar_filename
114 if options.arch == 'all':
115 options.arch = 'ia32,x64,arm,arm64,riscv64'
116 arch = options.arch.split(',')
117
118 if not options.out_dir:
119 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS))
120
121 if not tar_filename:
122 tar_filename = join(DART_DIR, utils.GetBuildDir(HOST_OS),
123 'dart-%s.tar.gz' % utils.GetVersion())
124
125 BuildDebianPackage(tar_filename, out_dir, arch, options.toolchain)
126
127
128if __name__ == '__main__':
129 sys.exit(Main())
def RunBuildPackage(opt, cwd, toolchain=None)
def BuildDebianPackage(tarball, out_dir, arches, toolchain)
def print(*args, **kwargs)
Definition: run_tests.py:49
def GuessOS()
Definition: utils.py:21
def GetBuildDir(host_os)
Definition: utils.py:99
def GuessCpus()
Definition: utils.py:55
def GetVersion(no_git_hash=False, version_file=None, git_revision_file=None)
Definition: utils.py:357
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741
static void parse_args(int argc, char *argv[], Args *args)
Definition: skqp_main.cpp:97