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 sys | 13 import sys |
13 import tarfile | 14 import tarfile |
14 import subprocess | 15 import subprocess |
15 import utils | 16 import utils |
16 | 17 |
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 |
| 25 def BuildOptions(): |
| 26 result = optparse.OptionParser() |
| 27 result.add_option("--tar_filename", |
| 28 default=None, |
| 29 help="The tar file to build from.") |
| 30 result.add_option("--out_dir", |
| 31 default=None, |
| 32 help="Where to put the packages.") |
| 33 |
| 34 return result |
| 35 |
24 def RunBuildPackage(opt, cwd): | 36 def RunBuildPackage(opt, cwd): |
25 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] | 37 cmd = ['dpkg-buildpackage', '-j%d' % HOST_CPUS] |
26 cmd.extend(opt) | 38 cmd.extend(opt) |
27 process = subprocess.Popen(cmd, | 39 process = subprocess.Popen(cmd, |
28 stdout=subprocess.PIPE, stderr=subprocess.PIPE, | 40 stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
29 cwd=cwd) | 41 cwd=cwd) |
30 (stdout, stderr) = process.communicate() | 42 (stdout, stderr) = process.communicate() |
31 if process.returncode != 0: | 43 if process.returncode != 0: |
32 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' % | 44 raise Exception('Command \'%s\' failed: %s\nSTDOUT: %s' % |
33 (' '.join(cmd), stderr, stdout)) | 45 (' '.join(cmd), stderr, stdout)) |
34 | 46 |
35 def BuildDebianPackage(): | 47 def BuildDebianPackage(tarball, out_dir): |
36 version = utils.GetVersion() | 48 version = utils.GetVersion() |
37 builddir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) | |
38 tarroot = 'dart-%s' % version | 49 tarroot = 'dart-%s' % version |
39 tarname = 'dart-%s.tar.gz' % version | |
40 origtarname = 'dart_%s.orig.tar.gz' % version | 50 origtarname = 'dart_%s.orig.tar.gz' % version |
41 tarball = join(builddir, tarname) | 51 |
42 if not exists(join(builddir, tarball)): | 52 if not exists(join(out_dir, tarball)): |
43 print 'Source tarball not found' | 53 print 'Source tarball not found' |
44 return -1 | 54 return -1 |
45 | 55 |
46 with utils.TempDir() as temp_dir: | 56 with utils.TempDir() as temp_dir: |
47 origtarball = join(temp_dir, origtarname) | 57 origtarball = join(temp_dir, origtarname) |
48 copyfile(tarball, origtarball) | 58 copyfile(tarball, origtarball) |
49 | 59 |
50 with tarfile.open(origtarball) as tar: | 60 with tarfile.open(origtarball) as tar: |
51 tar.extractall(path=temp_dir) | 61 tar.extractall(path=temp_dir) |
52 | 62 |
(...skipping 16 matching lines...) Expand all Loading... |
69 '%s.orig.tar.gz' % debbase, | 79 '%s.orig.tar.gz' % debbase, |
70 '%s-1.debian.tar.gz' % debbase | 80 '%s-1.debian.tar.gz' % debbase |
71 ] | 81 ] |
72 i386_package = [ | 82 i386_package = [ |
73 '%s-1_i386.deb' % debbase | 83 '%s-1_i386.deb' % debbase |
74 ] | 84 ] |
75 amd64_package = [ | 85 amd64_package = [ |
76 '%s-1_amd64.deb' % debbase | 86 '%s-1_amd64.deb' % debbase |
77 ] | 87 ] |
78 for name in source_package: | 88 for name in source_package: |
79 copyfile(join(temp_dir, name), join(builddir, name)) | 89 copyfile(join(temp_dir, name), join(out_dir, name)) |
80 for name in i386_package: | 90 for name in i386_package: |
81 copyfile(join(temp_dir, name), join(builddir, name)) | 91 copyfile(join(temp_dir, name), join(out_dir, name)) |
82 for name in amd64_package: | 92 for name in amd64_package: |
83 copyfile(join(temp_dir, name), join(builddir, name)) | 93 copyfile(join(temp_dir, name), join(out_dir, name)) |
84 | 94 |
85 def Main(): | 95 def Main(): |
86 if HOST_OS != 'linux': | 96 if HOST_OS != 'linux': |
87 print 'Debian build only supported on linux' | 97 print 'Debian build only supported on linux' |
88 return -1 | 98 return -1 |
89 | 99 |
90 BuildDebianPackage() | 100 options, args = BuildOptions().parse_args() |
| 101 out_dir = options.out_dir |
| 102 tar_filename = options.tar_filename |
| 103 if not options.out_dir: |
| 104 out_dir = join(DART_DIR, utils.GetBuildDir(HOST_OS, HOST_OS)) |
| 105 if not options.tar_filename: |
| 106 raise Exception('Please specify the input filename.') |
| 107 BuildDebianPackage(options.tar_filename, options.out_dir) |
91 | 108 |
92 if __name__ == '__main__': | 109 if __name__ == '__main__': |
93 sys.exit(Main()) | 110 sys.exit(Main()) |
OLD | NEW |