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, 7, 0):
44 sys
.stderr
.write("python 2.7 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
= 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
)
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
)
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.')
91 prefix
= options
.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')
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)
118 if __name__
== '__main__':
120 rtn
= main(sys
.argv
[1:])
122 sys
.stderr
.write('%s: %s\n' % (os
.path
.basename(__file__
), e
))
124 except KeyboardInterrupt:
125 sys
.stderr
.write('%s: interrupted\n' % os
.path
.basename(__file__
))