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:
22 "nacl_arch": "x86-64",
23 "sub_package_path": "_platform_specific/x86-64/"
31 "nacl_arch": "x86-64",
32 "sub_package_path": "<toolchain>/<config>/_platform_specific/x86-64/"
43 if sys
.version_info
< (2, 6, 0):
44 sys
.stderr
.write("python 2.6 or later is required run this script\n")
48 class Error(Exception):
49 """Local Error class for this file."""
55 sys
.stderr
.write(str(msg
) + '\n')
61 parser
= optparse
.OptionParser(
62 usage
='Usage: %prog [options] manifest.json', description
=__doc__
)
63 parser
.add_option('-p', '--prefix',
64 help='Prefix to set for all sub_package_paths in the '
65 'manifest. If none is specified, the prefix will be '
66 'removed; i.e. the start of the path will be '
67 '"_platform_specific/..."')
68 parser
.add_option('-v', '--verbose',
69 help='Verbose output', action
='store_true')
71 options
, args
= parser
.parse_args(argv
)
76 parser
.error('Expected manifest file.')
80 Trace('Reading %s' % manifest
)
81 with
open(manifest
) as f
:
82 # Keep the dictionary order. This is only supported on Python 2.7+
83 if sys
.version_info
>= (2, 7, 0):
84 data
= json
.load(f
, object_pairs_hook
=collections
.OrderedDict
)
88 if 'platforms' not in data
:
89 raise Error('%s does not have "platforms" key.' % manifest
)
91 platforms
= data
['platforms']
92 if type(platforms
) is not list:
93 raise Error('Expected "platforms" key to be array.')
96 prefix
= options
.prefix
+ '/'
100 for platform
in platforms
:
101 nacl_arch
= platform
.get('nacl_arch')
103 if 'sub_package_path' not in platform
:
104 raise Error('Expected each platform to have "sub_package_path" key.')
106 sub_package_path
= platform
['sub_package_path']
107 index
= sub_package_path
.find('_platform_specific')
109 raise Error('Could not find "_platform_specific" in the '
110 '"sub_package_path" key.')
112 new_path
= prefix
+ sub_package_path
[index
:]
113 platform
['sub_package_path'] = new_path
115 Trace(' %s: "%s" -> "%s"' % (nacl_arch
, sub_package_path
, new_path
))
117 with
open(manifest
, 'w') as f
:
118 json
.dump(data
, f
, indent
=2)
123 if __name__
== '__main__':
125 rtn
= main(sys
.argv
[1:])
127 sys
.stderr
.write('%s: %s\n' % (os
.path
.basename(__file__
), e
))
129 except KeyboardInterrupt:
130 sys
.stderr
.write('%s: interrupted\n' % os
.path
.basename(__file__
))