Skip to content

Change Response Files encoding to be identified by response file suffix? #15292

Description

@juj

When python sees open(file, 'r') without explicit encoding= parameter, it opens a text file using the default system encoding. This happens today at

with open(response_filename) as f:

So when users are calling emcc and other tools with response files, they need to encode their response files using the current system encoding locale.

It would be preferable to always use utf-8 encoding to encode response files with, but there is a danger that changing open(file, 'r', encoding='utf-8') there will break existing user build systems.

For example on Windows if a shell script did echo arg1 arg2 arg3 arg4 > file.rsp, I believe that will create a current system encoding locale encoded file.

Also related, we have this quirky code when different Emscripten tools create response files:

# When writing windows repsonse files force the encoding to UTF8 which we know
# that llvm tools understand. Without this, we get whatever the default codepage
# might be.
# See: https://github.com/llvm/llvm-project/blob/3f3d1c901d7abcc5b91468335679b1b27d8a02dd/llvm/include/llvm/Support/Program.h#L168-L170
# And: https://github.com/llvm/llvm-project/blob/63d16d06f5b8f71382033b5ea4aa668f8150817a/clang/include/clang/Driver/Job.h#L58-L69
# TODO(sbc): Should we also force utf-8 on non-windows?
if WINDOWS:
encoding = 'utf-8'
else:
encoding = None

here the code is making an assumption that the only time the Emscripten toolchain is creating response files, it would be creating those in a call to an LLVM tool. This might be true, though the intent of create_response_file() definitely is not to create response files only for LLVM to consume.

(btw I believe the answer to that TODO above is 'yes')

To fix both of these, I would propose that the response file logic would use the file suffix to decide what the encoding of the file should be:

  • if the suffix is .utf8, then the response file should be created and/or read using explicit utf-8 encoding.
  • if the suffix is anything else (e.g. the usual .rsp), then the response file should be created using current system encoding locale.

Then when Emscripten users are creating response files, they can create files with suffix .rsp or .rsp.utf8 to choose either current locale (open(file, 'r') in python), or utf-8 locale (open(file, 'r', encoding='utf-8') for python). Likewise, the function create_response_file() can then be extended to take in a suffix, and the call sites to that tool can choose which encoding to use (I think they all will want .rsp.utf8 at the moment)

Does that sound good?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions