GPU workaround to simulate Out of Memory errors with large textures
[chromium-blink-merge.git] / native_client_sdk / src / tools / fix_manifest.py
blob28729b98776fe226ddbb283c7555beb5ead52632
1 #!/usr/bin/env python
2 # Copyright (c) 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 # Disable the lint error for too-long lines for the URL below.
7 # pylint: disable=C0301
9 """Fix Chrome App manifest.json files for use with multi-platform zip files.
11 See info about multi-platform zip files here:
12 https://developer.chrome.com/native-client/devguide/distributing#packaged-application
14 The manifest.json file needs to point to the correct platform-specific paths,
15 but we build all toolchains and configurations in the same tree. As a result,
16 we can't have one manifest.json for all combinations.
18 Instead, we update the top-level manifest.json file during the build:
20 "platforms": [
22 "nacl_arch": "x86-64",
23 "sub_package_path": "_platform_specific/x86-64/"
25 ...
27 Becomes
29 "platforms": [
31 "nacl_arch": "x86-64",
32 "sub_package_path": "<toolchain>/<config>/_platform_specific/x86-64/"
34 ...
35 """
37 import argparse
38 import collections
39 import json
40 import os
41 import sys
43 if sys.version_info < (2, 7, 0):
44 sys.stderr.write("python 2.7 or later is required run this script\n")
45 sys.exit(1)
48 class Error(Exception):
49 """Local Error class for this file."""
50 pass
53 def Trace(msg):
54 if Trace.verbose:
55 sys.stderr.write(str(msg) + '\n')
57 Trace.verbose = False
60 def main(args):
61 parser = argparse.ArgumentParser(description=__doc__)
62 parser.add_argument('-p', '--prefix',
63 help='Prefix to set for all sub_package_paths in the '
64 'manifest. If none is specified, the prefix will be '
65 'removed; i.e. the start of the path will be '
66 '"_platform_specific/..."')
67 parser.add_argument('-v', '--verbose',
68 help='Verbose output', action='store_true')
69 parser.add_argument('manifest_json')
71 options = parser.parse_args(args)
72 if options.verbose:
73 Trace.verbose = True
75 Trace('Reading %s' % options.manifest_json)
76 with open(options.manifest_json) as f:
77 # Keep the dictionary order. This is only supported on Python 2.7+
78 if sys.version_info >= (2, 7, 0):
79 data = json.load(f, object_pairs_hook=collections.OrderedDict)
80 else:
81 data = json.load(f)
83 if 'platforms' not in data:
84 raise Error('%s does not have "platforms" key.' % options.manifest_json)
86 platforms = data['platforms']
87 if type(platforms) is not list:
88 raise Error('Expected "platforms" key to be array.')
90 if options.prefix:
91 prefix = options.prefix + '/'
92 else:
93 prefix = ''
95 for platform in platforms:
96 nacl_arch = platform.get('nacl_arch')
98 if 'sub_package_path' not in platform:
99 raise Error('Expected each platform to have "sub_package_path" key.')
101 sub_package_path = platform['sub_package_path']
102 index = sub_package_path.find('_platform_specific')
103 if index == -1:
104 raise Error('Could not find "_platform_specific" in the '
105 '"sub_package_path" key.')
107 new_path = prefix + sub_package_path[index:]
108 platform['sub_package_path'] = new_path
110 Trace(' %s: "%s" -> "%s"' % (nacl_arch, sub_package_path, new_path))
112 with open(options.manifest_json, 'w') as f:
113 json.dump(data, f, indent=2)
115 return 0
118 if __name__ == '__main__':
119 try:
120 rtn = main(sys.argv[1:])
121 except Error, e:
122 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
123 rtn = 1
124 except KeyboardInterrupt:
125 sys.stderr.write('%s: interrupted\n' % os.path.basename(__file__))
126 rtn = 1
127 sys.exit(rtn)