Commit fd3dd4a3 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

mojo: Fix writing to file on Python 3

Doing the encode() when writing the file avoids needing to add it to all callsites. Removed where it was previously added.
There should be no behavioural changes.

Traceback (most recent call last):
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 556, in <module>
    sys.exit(main())
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 551, in main
    return args.func(args, remaining_args)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 267, in _Generate
    processor._GenerateModule(args, remaining_args, generator_modules,
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 238, in _GenerateModule
    generator.GenerateFiles(filtered_args)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\generators\mojom_cpp_generator.py", line 464, in GenerateFiles
    self.WriteWithComment(self._GenerateModuleSharedHeader(),
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\generator.py", line 234, in WriteWithComment
    self.Write(contents, filename)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\generator.py", line 226, in Write
    WriteFile(contents, full_path)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\generator.py", line 115, in WriteFile
    f.write(contents)
TypeError: a bytes-like object is required, not 'str'

Bug: 941669
Change-Id: I0669c2021e71077f28f156a3e055e5746da246c1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1994882
Auto-Submit: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Raul Tambre <raul@tambre.ee>
Cr-Commit-Position: refs/heads/master@{#732472}
parent 433dfdab
......@@ -149,7 +149,7 @@ def main():
for path in params.dependency:
typemaps.update(ReadTypemap(path))
WriteFile(json.dumps({'c++': typemaps}, indent=2).encode(), params.output)
WriteFile(json.dumps({'c++': typemaps}, indent=2), params.output)
if __name__ == '__main__':
......
......@@ -395,7 +395,7 @@ def _VerifyImportDeps(args, __):
source_filename, _ = os.path.splitext(rel_path.relative_path())
output_file = source_filename + '.v'
output_file_path = os.path.join(args.gen_dir, output_file)
WriteFile(b"", output_file_path)
WriteFile("", output_file_path)
return 0
......
......@@ -112,7 +112,7 @@ def WriteFile(contents, full_path):
# Dump the data to disk.
with open(full_path, "wb") as f:
f.write(contents)
f.write(contents.encode('utf-8'))
def AddComputedData(module):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment