OLD | NEW |
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. |
(...skipping 13 matching lines...) Expand all Loading... |
24 DART_DIR = abspath(join(__file__, '..', '..')) | 24 DART_DIR = abspath(join(__file__, '..', '..')) |
25 | 25 |
26 def BuildOptions(): | 26 def BuildOptions(): |
27 result = optparse.OptionParser() | 27 result = optparse.OptionParser() |
28 result.add_option("--tar_filename", | 28 result.add_option("--tar_filename", |
29 default=None, | 29 default=None, |
30 help="The tar file to build from.") | 30 help="The tar file to build from.") |
31 result.add_option("--out_dir", | 31 result.add_option("--out_dir", |
32 default=None, | 32 default=None, |
33 help="Where to put the packages.") | 33 help="Where to put the packages.") |
| 34 result.add_option("-a", "--arch", |
| 35 help='Target architectures (comma-separated).', |
| 36 metavar='[all,ia32,x64]', |
| 37 default='x64') |
34 | 38 |
35 return result | 39 return result |
36 | 40 |
37 def RunBuildPackage(opt, cwd): | 41 def RunBuildPackage(opt, cwd): |
38 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] | 42 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] |
39 cmd.extend(opt) | 43 cmd.extend(opt) |
40 process = subprocess.Popen(cmd, | 44 process = subprocess.Popen(cmd, |
41 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 45 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
42 cwd=cwd) | 46 cwd=cwd) |
43 (stdout, stderr) = process.communicate() | 47 (stdout, stderr) = process.communicate() |
44 if process.returncode != 0: | 48 if process.returncode != 0: |
45 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' % | 49 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' % |
46 (' '.join(cmd), stderr, stdout)) | 50 (' '.join(cmd), stderr, stdout)) |
47 | 51 |
48 def BuildDebianPackage(tarball, out_dir): | 52 def BuildDebianPackage(tarball, out_dir, arch): |
49 version = utils.GetVersion() | 53 version = utils.GetVersion() |
50 tarroot = 'dart-%s' % version | 54 tarroot = 'dart-%s' % version |
51 origtarname = 'dart_%s.orig.tar.gz' % version | 55 origtarname = 'dart_%s.orig.tar.gz' % version |
52 | 56 |
53 if not exists(tarball): | 57 if not exists(tarball): |
54 print 'Source tarball not found' | 58 print 'Source tarball not found' |
55 return -1 | 59 return -1 |
56 | 60 |
57 with utils.TempDir() as temp_dir: | 61 with utils.TempDir() as temp_dir: |
58 origtarball = join(temp_dir, origtarname) | 62 origtarball = join(temp_dir, origtarname) |
59 copyfile(tarball, origtarball) | 63 copyfile(tarball, origtarball) |
60 | 64 |
61 with tarfile.open(origtarball) as tar: | 65 with tarfile.open(origtarball) as tar: |
62 tar.extractall(path=temp_dir) | 66 tar.extractall(path=temp_dir) |
63 | 67 |
64 # Build source package. | 68 # Build source package. |
65 print "Building source package" | 69 print "Building source package" |
66 RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot)); | 70 RunBuildPackage(['-S', '-us', '-uc'], join(temp_dir, tarroot)); |
67 | 71 |
| 72 # Build 32-bit binary package. |
| 73 if ('ia32' in arch): |
| 74 print "Building i386 package" |
| 75 RunBuildPackage(['-B', '-ai386', '-us', '-uc'], join(temp_dir, tarroot)); |
| 76 |
68 # Build 64-bit binary package. | 77 # Build 64-bit binary package. |
69 print "Building amd64 package" | 78 if ('x64' in arch): |
70 RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot)); | 79 print "Building amd64 package" |
| 80 RunBuildPackage(['-B', '-aamd64', '-us', '-uc'], join(temp_dir, tarroot)); |
71 | 81 |
72 # Copy the Debian package files to the build directory. | 82 # Copy the Debian package files to the build directory. |
73 debbase = 'dart_%s' % version | 83 debbase = 'dart_%s' % version |
74 source_package = [ | 84 source_package = [ |
75 '%s-1.dsc' % debbase, | 85 '%s-1.dsc' % debbase, |
76 '%s.orig.tar.gz' % debbase, | 86 '%s.orig.tar.gz' % debbase, |
77 '%s-1.debian.tar.gz' % debbase | 87 '%s-1.debian.tar.gz' % debbase |
78 ] | 88 ] |
| 89 i386_package = [ |
| 90 '%s-1_i386.deb' % debbase |
| 91 ] |
79 amd64_package = [ | 92 amd64_package = [ |
80 '%s-1_amd64.deb' % debbase | 93 '%s-1_amd64.deb' % debbase |
81 ] | 94 ] |
82 | 95 |
83 for name in source_package: | 96 for name in source_package: |
84 copyfile(join(temp_dir, name), join(out_dir, name)) | 97 copyfile(join(temp_dir, name), join(out_dir, name)) |
85 for name in amd64_package: | 98 if ('ia32' in arch): |
86 copyfile(join(temp_dir, name), join(out_dir, name)) | 99 for name in i386_package: |
| 100 copyfile(join(temp_dir, name), join(out_dir, name)) |
| 101 if ('x64' in arch): |
| 102 for name in amd64_package: |
| 103 copyfile(join(temp_dir, name), join(out_dir, name)) |
87 | 104 |
88 def Main(): | 105 def Main(): |
89 if HOST_OS != 'linux': | 106 if HOST_OS != 'linux': |
90 print 'Debian build only supported on linux' | 107 print 'Debian build only supported on linux' |
91 return -1 | 108 return -1 |
92 | 109 |
93 options, args = BuildOptions().parse_args() | 110 options, args = BuildOptions().parse_args() |
94 out_dir = options.out_dir | 111 out_dir = options.out_dir |
95 tar_filename = options.tar_filename | 112 tar_filename = options.tar_filename |
| 113 if options.arch == 'all': |
| 114 options.arch = 'ia32,x64' |
| 115 arch = options.arch.split(',') |
| 116 |
96 if not options.out_dir: | 117 if not options.out_dir: |
97 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) | 118 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) |
98 | 119 |
99 if not tar_filename: | 120 if not tar_filename: |
100 tar_filename = join(DART_DIR, | 121 tar_filename = join(DART_DIR, |
101 utils.GetBuildDir(HOST_OS, HOST_OS), | 122 utils.GetBuildDir(HOST_OS, HOST_OS), |
102 'dart-%s.tar.gz' % utils.GetVersion()) | 123 'dart-%s.tar.gz' % utils.GetVersion()) |
103 | 124 |
104 BuildDebianPackage(tar_filename, out_dir) | 125 BuildDebianPackage(tar_filename, out_dir, arch) |
105 | 126 |
106 if __name__ == '__main__': | 127 if __name__ == '__main__': |
107 sys.exit(Main()) | 128 sys.exit(Main()) |
OLD | NEW |