OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Build packages on a host machine, then install them on the local target. | 7 """Build packages on a host machine, then install them on the local target. |
8 | 8 |
9 Contacts a devserver (trunk/src/platform/dev/devserver.py) and | 9 Contacts a devserver (trunk/src/platform/dev/devserver.py) and |
10 requests that it build a package, then performs a binary install of | 10 requests that it build a package, then performs a binary install of |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 'CONFIG_PROTECT': '-*', | 65 'CONFIG_PROTECT': '-*', |
66 'FEATURES': '-sandbox', | 66 'FEATURES': '-sandbox', |
67 'ACCEPT_KEYWORDS': 'arm x86 ~arm ~x86', | 67 'ACCEPT_KEYWORDS': 'arm x86 ~arm ~x86', |
68 'ROOT': '/', | 68 'ROOT': '/', |
69 }) | 69 }) |
70 | 70 |
71 def GeneratePackageRequest(self, package_name): | 71 def GeneratePackageRequest(self, package_name): |
72 """Build the POST string that conveys our options to the devserver.""" | 72 """Build the POST string that conveys our options to the devserver.""" |
73 post_data = {'board': self.board_name, | 73 post_data = {'board': self.board_name, |
74 'pkg': package_name, | 74 'pkg': package_name, |
75 'use': FLAGS.use, | 75 'features': os.environ.get('FEATURES', None), |
76 'use': os.environ.get('USE', None), | |
76 'accept_stable': FLAGS.accept_stable, | 77 'accept_stable': FLAGS.accept_stable, |
77 } | 78 } |
78 post_data = dict([(key, value) for (key, value) in post_data.iteritems() | 79 post_data = dict([(key, value) for (key, value) in post_data.iteritems() |
79 if value]) | 80 if value]) |
80 return urllib.urlencode(post_data) | 81 return urllib.urlencode(post_data) |
81 | 82 |
82 def RequestPackageBuild(self, package_name): | 83 def RequestPackageBuild(self, package_name): |
83 """Contacts devserver to request a build.""" | 84 """Contacts devserver to request a build.""" |
84 try: | 85 try: |
85 result = urllib2.urlopen(self.devkit_url + '/build', | 86 result = urllib2.urlopen(self.devkit_url + '/build', |
86 data=self.GeneratePackageRequest(package_name)) | 87 data=self.GeneratePackageRequest(package_name)) |
87 print result.read() | 88 print result.read() |
88 result.close() | 89 result.close() |
89 | 90 |
90 except urllib2.HTTPError, e: | 91 except urllib2.HTTPError, e: |
91 # The exception includes the content, which is the error mesage | 92 # The exception includes the content, which is the error mesage |
92 sys.exit(e.read()) | 93 sys.exit(e.read()) |
93 | 94 |
94 | 95 |
95 def main(): | 96 def main(): |
96 global FLAGS | 97 global FLAGS |
97 parser = optparse.OptionParser(usage='usage: %prog [options] package_name') | 98 parser = optparse.OptionParser(usage='usage: %prog [options] package_name') |
98 parser.add_option('--accept_stable', | 99 parser.add_option('--accept_stable', |
99 action='store_true', dest='accept_stable', default=False, | 100 action='store_true', dest='accept_stable', default=False, |
100 help=('Build even if a cros_workon package is not ' | 101 help=('Build even if a cros_workon package is not ' |
101 'using the live package')) | 102 'using the live package')) |
102 parser.add_option('-n', '--no_devserver', | 103 parser.add_option('-n', '--no_devserver', |
103 action='store_false', dest='call_devserver', default=True, | 104 action='store_false', dest='call_devserver', default=True, |
104 help='Do not actually ask the server to build') | 105 help='Do not actually ask the server to build') |
105 parser.add_option('--use', '--USE', | |
106 dest='use', default=None, | |
107 help='USE flags to pass to emerge on the server') | |
108 | 106 |
109 (FLAGS, remaining_arguments) = parser.parse_args() | 107 (FLAGS, remaining_arguments) = parser.parse_args() |
110 if len(remaining_arguments) != 1: | 108 if len(remaining_arguments) != 1: |
111 parser.print_help() | 109 parser.print_help() |
112 sys.exit('Need exactly one package name') | 110 sys.exit('Need exactly one package name') |
113 | 111 |
114 package_name = remaining_arguments[0] | 112 package_name = remaining_arguments[0] |
115 | 113 |
116 try: | 114 try: |
117 subprocess.check_call(['mount', '-o', 'remount,exec', '/tmp']) | 115 subprocess.check_call(['mount', '-o', 'remount,exec', '/tmp']) |
118 merger = GMerger(open('/etc/lsb-release').readlines()) | 116 merger = GMerger(open('/etc/lsb-release').readlines()) |
119 merger.SetupPortageEnvironment(os.environ) | |
120 merger.RemountOrChangeRoot(os.environ) | |
121 if FLAGS.call_devserver: | 117 if FLAGS.call_devserver: |
122 merger.RequestPackageBuild(package_name) | 118 merger.RequestPackageBuild(package_name) |
123 else: | 119 else: |
124 print 'Not requesting fresh build on server---installing whatever we find' | 120 print 'Not requesting fresh build on server---installing whatever we find' |
125 | 121 |
126 print 'Emerging ', package_name | 122 print 'Emerging ', package_name |
123 merger.SetupPortageEnvironment(os.environ) | |
sosa
2011/04/13 20:04:08
Move down to not affect environment passed to buil
| |
124 merger.RemountOrChangeRoot(os.environ) | |
127 subprocess.check_call([ | 125 subprocess.check_call([ |
128 'emerge', '--getbinpkgonly', '--usepkgonly', package_name]) | 126 'emerge', '--getbinpkgonly', '--usepkgonly', package_name]) |
129 finally: | 127 finally: |
130 subprocess.call(['mount', '-o', 'remount,noexec', '/tmp']) | 128 subprocess.call(['mount', '-o', 'remount,noexec', '/tmp']) |
131 | 129 |
132 | 130 |
133 if __name__ == '__main__': | 131 if __name__ == '__main__': |
134 main() | 132 main() |
OLD | NEW |