diff --git a/build/mac/tweak_info_plist.py b/build/mac/tweak_info_plist.py index 5ad93b9c1235..771c921a21c6 100644 --- a/build/mac/tweak_info_plist.py +++ b/build/mac/tweak_info_plist.py @@ -29,6 +29,7 @@ def _ConvertPlist(source_plist, output_plist, fmt): """Convert |source_plist| to |fmt| and save as |output_plist|.""" + assert sys.version_info.major == 2, "Use plistlib directly in Python 3" return subprocess.call( ['plutil', '-convert', fmt, '-o', output_plist, source_plist]) @@ -82,10 +83,14 @@ def Main(): # Read the plist into its parsed format. Convert the file to 'xml1' as # plistlib only supports that format in Python 2.7. with tempfile.NamedTemporaryFile() as temp_info_plist: - retcode = _ConvertPlist(args.plist_path, temp_info_plist.name, 'xml1') - if retcode != 0: - return retcode - plist = plistlib.readPlist(temp_info_plist.name) + if sys.version_info.major == 2: + retcode = _ConvertPlist(args.plist_path, temp_info_plist.name, 'xml1') + if retcode != 0: + return retcode + plist = plistlib.readPlist(temp_info_plist.name) + else: + with open(args.plist_path, 'rb') as f: + plist = plistlib.load(f) output_path = args.plist_path if args.plist_output is not None: @@ -109,12 +114,15 @@ def Main(): plist['SUEnableSystemProfiling'] = False # Now that all keys have been mutated, rewrite the file. - with tempfile.NamedTemporaryFile() as temp_info_plist: - plistlib.writePlist(plist, temp_info_plist.name) - - # Convert Info.plist to the format requested by the --format flag. Any - # format would work on Mac but iOS requires specific format. - return _ConvertPlist(temp_info_plist.name, output_path, args.format) + # Convert Info.plist to the format requested by the --format flag. Any + # format would work on Mac but iOS requires specific format. + if sys.version_info.major == 2: + with tempfile.NamedTemporaryFile() as temp_info_plist: + plistlib.writePlist(plist, temp_info_plist.name) + return _ConvertPlist(temp_info_plist.name, output_path, args.format) + with open(output_path, 'wb') as f: + plist_format = {'binary1': plistlib.FMT_BINARY, 'xml1': plistlib.FMT_XML} + plistlib.dump(plist, f, fmt=plist_format[args.format]) if __name__ == '__main__':