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. |
11 | 11 |
12 import optparse | 12 import optparse |
| 13 import platform |
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 | 18 import os |
18 from os.path import join, exists, abspath | 19 from os.path import join, exists, abspath |
19 from shutil import copyfile | 20 from shutil import copyfile |
20 | 21 |
21 HOST_OS = utils.GuessOS() | 22 HOST_OS = utils.GuessOS() |
22 HOST_CPUS = utils.GuessCpus() | 23 HOST_CPUS = utils.GuessCpus() |
23 DART_DIR = abspath(join(__file__, '..', '..')) | 24 DART_DIR = abspath(join(__file__, '..', '..')) |
24 | 25 |
25 def BuildOptions(): | 26 def BuildOptions(): |
26 result = optparse.OptionParser() | 27 result = optparse.OptionParser() |
27 result.add_option("--tar_filename", | 28 result.add_option("--tar_filename", |
28 default=None, | 29 default=None, |
29 help="The tar file to build from.") | 30 help="The tar file to build from.") |
30 result.add_option("--out_dir", | 31 result.add_option("--out_dir", |
31 default=None, | 32 default=None, |
32 help="Where to put the packages.") | 33 help="Where to put the packages.") |
33 | 34 |
34 return result | 35 return result |
35 | 36 |
36 def RunBuildPackage(opt, cwd): | 37 def RunBuildPackage(opt, cwd): |
37 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] | 38 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] |
38 cmd.extend(opt) | 39 cmd.extend(opt) |
39 process = subprocess.Popen(cmd, | 40 process = subprocess.Popen(cmd, |
40 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 41 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
41 cwd=cwd) | 42 cwd=cwd) |
42 (stdout, stderr) = process.communicate() | 43 (stdout, stderr) = process.communicate() |
43 if process.returncode != 0: | 44 if process.returncode != 0: |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 '%s-1.dsc' % debbase, | 79 '%s-1.dsc' % debbase, |
79 '%s.orig.tar.gz' % debbase, | 80 '%s.orig.tar.gz' % debbase, |
80 '%s-1.debian.tar.gz' % debbase | 81 '%s-1.debian.tar.gz' % debbase |
81 ] | 82 ] |
82 i386_package = [ | 83 i386_package = [ |
83 '%s-1_i386.deb' % debbase | 84 '%s-1_i386.deb' % debbase |
84 ] | 85 ] |
85 amd64_package = [ | 86 amd64_package = [ |
86 '%s-1_amd64.deb' % debbase | 87 '%s-1_amd64.deb' % debbase |
87 ] | 88 ] |
| 89 |
88 for name in source_package: | 90 for name in source_package: |
89 copyfile(join(temp_dir, name), join(out_dir, name)) | 91 copyfile(join(temp_dir, name), join(out_dir, name)) |
90 for name in i386_package: | 92 for name in i386_package: |
91 copyfile(join(temp_dir, name), join(out_dir, name)) | 93 copyfile(join(temp_dir, name), join(out_dir, name)) |
92 for name in amd64_package: | 94 for name in amd64_package: |
93 copyfile(join(temp_dir, name), join(out_dir, name)) | 95 copyfile(join(temp_dir, name), join(out_dir, name)) |
94 | 96 |
95 def Main(): | 97 def Main(): |
96 if HOST_OS != 'linux': | 98 if HOST_OS != 'linux': |
97 print 'Debian build only supported on linux' | 99 print 'Debian build only supported on linux' |
98 return -1 | 100 return -1 |
99 | 101 |
100 options, args = BuildOptions().parse_args() | 102 options, args = BuildOptions().parse_args() |
101 out_dir = options.out_dir | 103 out_dir = options.out_dir |
102 tar_filename = options.tar_filename | 104 tar_filename = options.tar_filename |
103 if not options.out_dir: | 105 if not options.out_dir: |
104 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) | 106 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) |
105 if not options.tar_filename: | 107 |
106 raise Exception('Please specify the input filename.') | 108 if not tar_filename: |
107 BuildDebianPackage(options.tar_filename, options.out_dir) | 109 tar_filename = join(DART_DIR, |
| 110 utils.GetBuildDir(HOST_OS, HOST_OS), |
| 111 'dart-%s.tar.gz' % utils.GetVersion()) |
| 112 |
| 113 BuildDebianPackage(tar_filename, out_dir) |
108 | 114 |
109 if __name__ == '__main__': | 115 if __name__ == '__main__': |
110 sys.exit(Main()) | 116 sys.exit(Main()) |
OLD | NEW |