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

Side by Side Diff: tools/create_debian_packages.py

Issue 396123003: Allows building debian packages for ARM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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/build.py ('k') | tools/linux_dist_support/debian/control » ('j') | 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 Debian packages from a Dart tarball. The script 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) 9 # will build a source package and a 32-bit (i386) and 64-bit (amd64)
10 # binary packages. 10 # binary packages.
11 11
12 import optparse 12 import optparse
13 import os
13 import sys 14 import sys
14 import tarfile 15 import tarfile
15 import subprocess 16 import subprocess
16 import utils 17 import utils
17 from os.path import join, exists, abspath 18 from os.path import join, exists, abspath
18 from shutil import copyfile 19 from shutil import copyfile
19 20
20 HOST_OS = utils.GuessOS() 21 HOST_OS = utils.GuessOS()
21 HOST_CPUS = utils.GuessCpus() 22 HOST_CPUS = utils.GuessCpus()
22 DART_DIR = abspath(join(__file__, '..', '..')) 23 DART_DIR = abspath(join(__file__, '..', '..'))
23 24
24 def BuildOptions(): 25 def BuildOptions():
25 result = optparse.OptionParser() 26 result = optparse.OptionParser()
26 result.add_option("--tar_filename", 27 result.add_option("--tar_filename",
27 default=None, 28 default=None,
28 help="The tar file to build from.") 29 help="The tar file to build from.")
29 result.add_option("--out_dir", 30 result.add_option("--out_dir",
30 default=None, 31 default=None,
31 help="Where to put the packages.") 32 help="Where to put the packages.")
32 result.add_option("-a", "--arch", 33 result.add_option("-a", "--arch",
33 help='Target architectures (comma-separated).', 34 help='Target architectures (comma-separated).',
34 metavar='[all,ia32,x64]', 35 metavar='[all,ia32,x64,armel,armhf]',
35 default='x64') 36 default='x64')
37 result.add_option("-t", "--toolchain",
38 help='Cross-compilation toolchain prefix',
39 default=None)
36 40
37 return result 41 return result
38 42
39 def RunBuildPackage(opt, cwd): 43 def RunBuildPackage(opt, cwd, toolchain=None):
44 env = os.environ.copy()
45 if toolchain != None:
46 env["TOOLCHAIN"] = '--toolchain=' + toolchain
40 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] 47 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS]
41 cmd.extend(opt) 48 cmd.extend(opt)
42 process = subprocess.Popen(cmd, 49 process = subprocess.Popen(cmd,
43 stdout=subprocess.PIPE, stderr=subprocess.PIPE, 50 stdout=subprocess.PIPE, stderr=subprocess.PIPE,
44 cwd=cwd) 51 cwd=cwd, env=env)
45 (stdout, stderr) = process.communicate() 52 (stdout, stderr) = process.communicate()
46 if process.returncode != 0: 53 if process.returncode != 0:
47 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' % 54 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' %
48 (' '.join(cmd), stderr, stdout)) 55 (' '.join(cmd), stderr, stdout))
49 56
50 def BuildDebianPackage(tarball, out_dir, arch): 57 def BuildDebianPackage(tarball, out_dir, arch, toolchain):
51 version = utils.GetVersion() 58 version = utils.GetVersion()
52 tarroot = 'dart-%s' % version 59 tarroot = 'dart-%s' % version
53 origtarname = 'dart_%s.orig.tar.gz' % version 60 origtarname = 'dart_%s.orig.tar.gz' % version
54 61
55 if not exists(tarball): 62 if not exists(tarball):
56 print 'Source tarball not found' 63 print 'Source tarball not found'
57 return -1 64 return -1
58 65
59 with utils.TempDir() as temp_dir: 66 with utils.TempDir() as temp_dir:
60 origtarball = join(temp_dir, origtarname) 67 origtarball = join(temp_dir, origtarname)
61 copyfile(tarball, origtarball) 68 copyfile(tarball, origtarball)
62 69
63 with tarfile.open(origtarball) as tar: 70 with tarfile.open(origtarball) as tar:
64 tar.extractall(path=temp_dir) 71 tar.extractall(path=temp_dir)
65 72
66 # Build source package. 73 # Build source package.
67 print "Building source package" 74 print "Building source package"
68 RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot)) 75 RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot))
69 76
70 # Build 32-bit binary package. 77 # Build 32-bit binary package.
71 if 'ia32' in arch: 78 if 'ia32' in arch:
72 print "Building i386 package" 79 print "Building i386 package"
73 RunBuildPackage(['-B', '-ai386', '-us', '-uc'], join(temp_dir, tarroot)) 80 RunBuildPackage(['-B', '-ai386', '-us', '-uc'], join(temp_dir, tarroot))
74 81
75 # Build 64-bit binary package. 82 # Build 64-bit binary package.
76 if 'x64' in arch: 83 if 'x64' in arch:
77 print "Building amd64 package" 84 print "Building amd64 package"
78 RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot)) 85 RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot))
79 86
87 # Build armhf binary package.
88 if 'armhf' in arch:
89 print "Building armhf package"
90 RunBuildPackage(
91 ['-B', '-aarmhf', '-us', '-uc'], join(temp_dir, tarroot), toolchain)
92
93 # Build armel binary package.
94 if 'armel' in arch:
95 print "Building armel package"
96 RunBuildPackage(
97 ['-B', '-aarmel', '-us', '-uc'], join(temp_dir, tarroot), toolchain)
98
80 # Copy the Debian package files to the build directory. 99 # Copy the Debian package files to the build directory.
81 debbase = 'dart_%s' % version 100 debbase = 'dart_%s' % version
82 source_package = [ 101 source_package = [
83 '%s-1.dsc' % debbase, 102 '%s-1.dsc' % debbase,
84 '%s.orig.tar.gz' % debbase, 103 '%s.orig.tar.gz' % debbase,
85 '%s-1.debian.tar.gz' % debbase 104 '%s-1.debian.tar.gz' % debbase
86 ] 105 ]
87 i386_package = [ 106 i386_package = [
88 '%s-1_i386.deb' % debbase 107 '%s-1_i386.deb' % debbase
89 ] 108 ]
90 amd64_package = [ 109 amd64_package = [
91 '%s-1_amd64.deb' % debbase 110 '%s-1_amd64.deb' % debbase
92 ] 111 ]
112 armhf_package = [
113 '%s-1_armhf.deb' % debbase
114 ]
115 armel_package = [
116 '%s-1_armel.deb' % debbase
117 ]
93 118
94 for name in source_package: 119 for name in source_package:
95 copyfile(join(temp_dir, name), join(out_dir, name)) 120 copyfile(join(temp_dir, name), join(out_dir, name))
96 if 'ia32' in arch: 121 if 'ia32' in arch:
97 for name in i386_package: 122 for name in i386_package:
98 copyfile(join(temp_dir, name), join(out_dir, name)) 123 copyfile(join(temp_dir, name), join(out_dir, name))
99 if 'x64' in arch: 124 if 'x64' in arch:
100 for name in amd64_package: 125 for name in amd64_package:
101 copyfile(join(temp_dir, name), join(out_dir, name)) 126 copyfile(join(temp_dir, name), join(out_dir, name))
127 if ('armhf' in arch):
128 for name in armhf_package:
129 copyfile(join(temp_dir, name), join(out_dir, name))
130 if ('armel' in arch):
131 for name in armel_package:
132 copyfile(join(temp_dir, name), join(out_dir, name))
133
102 134
103 def Main(): 135 def Main():
104 if HOST_OS != 'linux': 136 if HOST_OS != 'linux':
105 print 'Debian build only supported on linux' 137 print 'Debian build only supported on linux'
106 return -1 138 return -1
107 139
108 options, args = BuildOptions().parse_args() 140 options, args = BuildOptions().parse_args()
109 out_dir = options.out_dir 141 out_dir = options.out_dir
110 tar_filename = options.tar_filename 142 tar_filename = options.tar_filename
111 if options.arch == 'all': 143 if options.arch == 'all':
112 options.arch = 'ia32,x64' 144 options.arch = 'ia32,x64,armhf'
113 arch = options.arch.split(',') 145 arch = options.arch.split(',')
114 146
115 if not options.out_dir: 147 if not options.out_dir:
116 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS)) 148 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS))
117 149
118 if not tar_filename: 150 if not tar_filename:
119 tar_filename = join(DART_DIR, 151 tar_filename = join(DART_DIR,
120 utils.GetBuildDir(HOST_OS), 152 utils.GetBuildDir(HOST_OS),
121 'dart-%s.tar.gz' % utils.GetVersion()) 153 'dart-%s.tar.gz' % utils.GetVersion())
122 154
123 BuildDebianPackage(tar_filename, out_dir, arch) 155 BuildDebianPackage(tar_filename, out_dir, arch, options.toolchain)
124 156
125 if __name__ == '__main__': 157 if __name__ == '__main__':
126 sys.exit(Main()) 158 sys.exit(Main())
OLDNEW
« no previous file with comments | « tools/build.py ('k') | tools/linux_dist_support/debian/control » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698