OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
| 6 import hashlib |
| 7 import json |
6 import os | 8 import os |
7 import sys | 9 import sys |
8 | 10 |
9 import buildbot_common | 11 import buildbot_common |
10 import build_utils | 12 import build_utils |
11 | 13 |
| 14 GS_MANIFEST_PATH = 'gs://nativeclient-mirror/nacl/nacl_sdk/' |
| 15 SDK_MANIFEST = 'naclsdk_manifest2.json' |
| 16 MONO_MANIFEST = 'naclmono_manifest.json' |
| 17 |
| 18 def build_and_upload_mono(sdk_revision, pepper_revision, sdk_url, upload_path, a
rgs): |
| 19 install_dir = 'naclmono' |
| 20 buildbot_common.RemoveDir(install_dir) |
| 21 |
| 22 revision_opt = ['--sdk-revision', sdk_revision] if sdk_revision else [] |
| 23 url_opt = ['--sdk-url', sdk_url] if sdk_url else [] |
| 24 |
| 25 buildbot_common.Run([sys.executable, 'nacl-mono-builder.py', |
| 26 '--arch', 'x86-32', '--install-dir', install_dir] + |
| 27 revision_opt + url_opt + args) |
| 28 buildbot_common.Run([sys.executable, 'nacl-mono-builder.py', |
| 29 '--arch', 'x86-64', '--install-dir', install_dir] + |
| 30 revision_opt + url_opt + args) |
| 31 buildbot_common.Run([sys.executable, 'nacl-mono-archive.py', |
| 32 '--upload-path', upload_path, |
| 33 '--pepper-revision', pepper_revision, |
| 34 '--install-dir', install_dir] + args) |
| 35 |
| 36 def get_sdk_build_info(): |
| 37 '''Returns a list of dictionaries for versions of NaCl Mono to build which are |
| 38 out of date compared to the SDKs available to naclsdk''' |
| 39 |
| 40 # Get a copy of the naclsdk manifest file |
| 41 buildbot_common.Run([buildbot_common.GetGsutil(), 'cp', |
| 42 GS_MANIFEST_PATH + SDK_MANIFEST, '.']) |
| 43 manifest_file = open(SDK_MANIFEST, 'r') |
| 44 sdk_manifest = json.loads(manifest_file.read()) |
| 45 manifest_file.close() |
| 46 |
| 47 pepper_infos = [] |
| 48 for key, value in sdk_manifest.items(): |
| 49 if key == 'bundles': |
| 50 stabilities = ['stable', 'beta', 'dev', 'post_stable'] |
| 51 # Pick pepper_* bundles, need pepper_19 or greater to build Mono |
| 52 bundles = filter(lambda b: (b['stability'] in stabilities |
| 53 and 'pepper_' in b['name']) |
| 54 and b['version'] >= 19, value) |
| 55 for b in bundles: |
| 56 newdict = {} |
| 57 newdict['pepper_revision'] = str(b['version']) |
| 58 linux_arch = filter(lambda u: u['host_os'] == 'linux', b['archives']) |
| 59 newdict['sdk_url'] = linux_arch[0]['url'] |
| 60 newdict['sdk_revision'] = b['revision'] |
| 61 newdict['stability'] = b['stability'] |
| 62 newdict['naclmono_name'] = 'naclmono_' + newdict['pepper_revision'] |
| 63 pepper_infos.append(newdict) |
| 64 |
| 65 # Get a copy of the naclmono manifest file |
| 66 buildbot_common.Run([buildbot_common.GetGsutil(), 'cp', |
| 67 GS_MANIFEST_PATH + MONO_MANIFEST, '.']) |
| 68 manifest_file = open(MONO_MANIFEST, 'r') |
| 69 mono_manifest = json.loads(manifest_file.read()) |
| 70 manifest_file.close() |
| 71 |
| 72 ret = [] |
| 73 mono_manifest_dirty = False |
| 74 # Check to see if we need to rebuild mono based on sdk revision |
| 75 for key, value in mono_manifest.items(): |
| 76 if key == 'bundles': |
| 77 for info in pepper_infos: |
| 78 bundle = filter(lambda b: b['name'] == info['naclmono_name'], value) |
| 79 if len(bundle) == 0: |
| 80 info['naclmono_rev'] = '1' |
| 81 ret.append(info) |
| 82 else: |
| 83 if info['sdk_revision'] != bundle[0]['sdk_revision']: |
| 84 # This bundle exists in the mono manifest, bump the revision |
| 85 # for the new build we're about to make. |
| 86 info['naclmono_rev'] = str(bundle[0]['revision'] + 1) |
| 87 ret.append(info) |
| 88 elif info['stability'] != bundle[0]['stability']: |
| 89 # If all that happened was the SDK bundle was promoted in stability, |
| 90 # change only that and re-write the manifest |
| 91 mono_manifest_dirty = True |
| 92 bundle[0]['stability'] = info['stability'] |
| 93 |
| 94 # re-write the manifest here because there are no bundles to build but |
| 95 # the manifest has changed |
| 96 if mono_manifest_dirty and len(ret) == 0: |
| 97 manifest_file = open(MONO_MANIFEST, 'w') |
| 98 manifest_file.write(json.dumps(mono_manifest, sort_keys=False, indent=2)) |
| 99 manifest_file.close() |
| 100 buildbot_common.Run([buildbot_common.GetGsutil(), 'cp', '-a', 'public-read', |
| 101 MONO_MANIFEST, GS_MANIFEST_PATH + MONO_MANIFEST]) |
| 102 |
| 103 return ret |
| 104 |
| 105 def update_mono_sdk_json(infos): |
| 106 '''Update the naclmono manifest with the newly built packages''' |
| 107 if len(infos) == 0: |
| 108 return |
| 109 |
| 110 manifest_file = open(MONO_MANIFEST, 'r') |
| 111 mono_manifest = json.loads(manifest_file.read()) |
| 112 manifest_file.close() |
| 113 |
| 114 newbundles = {} |
| 115 for info in infos: |
| 116 bundle = {} |
| 117 bundle['name'] = info['naclmono_name'] |
| 118 bundle['description'] = 'Mono for Native Client' |
| 119 bundle['stability'] = info['stability'] |
| 120 bundle['recommended'] = 'no' |
| 121 bundle['version'] = 'experimental' |
| 122 archive = {} |
| 123 sha1_hash = hashlib.sha1() |
| 124 f = open(info['naclmono_name'] + '.bz2', 'rb') |
| 125 sha1_hash.update(f.read()) |
| 126 archive['size'] = f.tell() |
| 127 f.close() |
| 128 archive['checksum'] = { 'sha1': sha1_hash.hexdigest() } |
| 129 archive['host_os'] = 'all' |
| 130 archive['url'] = ('https://commondatastorage.googleapis.com/' |
| 131 'nativeclient-mirror/nacl/nacl_sdk/%s/%s/%s.bz2' |
| 132 % (info['naclmono_name'], info['naclmono_rev'], |
| 133 info['naclmono_name'])) |
| 134 bundle['archives'] = [archive] |
| 135 bundle['revision'] = int(info['naclmono_rev']) |
| 136 bundle['sdk_revision'] = int(info['sdk_revision']) |
| 137 |
| 138 # Insert this new bundle into the manifest, |
| 139 # probably overwriting an existing bundle. |
| 140 for key, value in mono_manifest.items(): |
| 141 if key == 'bundles': |
| 142 existing = filter(lambda b: b['name'] == info['naclmono_name'], value) |
| 143 if len(existing) > 0: |
| 144 loc = value.index(existing[0]) |
| 145 value[loc] = bundle |
| 146 else: |
| 147 value.append(bundle) |
| 148 |
| 149 # Write out the file locally, then upload to its known location. |
| 150 manifest_file = open(MONO_MANIFEST, 'w') |
| 151 manifest_file.write(json.dumps(mono_manifest, sort_keys=False, indent=2)) |
| 152 manifest_file.close() |
| 153 buildbot_common.Run([buildbot_common.GetGsutil(), 'cp', '-a', 'public-read', |
| 154 MONO_MANIFEST, GS_MANIFEST_PATH + MONO_MANIFEST]) |
| 155 |
12 | 156 |
13 def main(args): | 157 def main(args): |
14 args = args[1:] | 158 args = args[1:] |
15 | 159 |
16 buildbot_revision = os.environ.get('BUILDBOT_REVISION', '') | 160 buildbot_revision = os.environ.get('BUILDBOT_REVISION', '') |
17 assert buildbot_revision | 161 buildername = os.environ.get('BUILDBOT_BUILDERNAME', '') |
18 sdk_revision = buildbot_revision.split(':')[0] | |
19 pepper_revision = build_utils.ChromeMajorVersion() | |
20 | 162 |
21 install_dir = 'naclmono' | 163 if buildername == 'linux-sdk-mono32': |
22 buildbot_common.RemoveDir(install_dir) | 164 assert buildbot_revision |
23 | 165 sdk_revision = buildbot_revision.split(':')[0] |
24 buildbot_common.Run([sys.executable, 'nacl-mono-builder.py', | 166 pepper_revision = build_utils.ChromeMajorVersion() |
25 '--arch', 'x86-32', '--install-dir', install_dir] + args) | 167 build_and_upload_mono(sdk_revision, pepper_revision, None, |
26 buildbot_common.Run([sys.executable, 'nacl-mono-builder.py', | 168 'trunk.' + sdk_revision, args) |
27 '--arch', 'x86-64', '--install-dir', install_dir] + args) | 169 elif buildername == 'linux-sdk-mono64': |
28 buildbot_common.Run([sys.executable, 'nacl-mono-archive.py', | 170 infos = get_sdk_build_info() |
29 '--sdk-revision', sdk_revision, | 171 for info in infos: |
30 '--pepper-revision', pepper_revision, | 172 # This will put the file in naclmono_19/1/naclmono_19.bz2 for example. |
31 '--install-dir', install_dir] + args) | 173 upload_path = info['naclmono_name'] + '/' + info['naclmono_rev'] |
| 174 build_and_upload_mono(None, info['pepper_revision'], info['sdk_url'], |
| 175 upload_path, args) |
| 176 update_mono_sdk_json(infos) |
| 177 |
32 | 178 |
33 | 179 |
34 if __name__ == '__main__': | 180 if __name__ == '__main__': |
35 sys.exit(main(sys.argv)) | 181 sys.exit(main(sys.argv)) |
OLD | NEW |