Skip to content

Commit

Permalink
Only rename closure inputs if needed
Browse files Browse the repository at this point in the history
We rename the files we pass to closure in order to work around
google/closure-compiler#3784.

However when we do this it makes debugging difficult because the
error messages contains temp files rather than actual input files.

So, only do the renaming if actually needed.
  • Loading branch information
sbc100 committed Aug 24, 2021
1 parent b7f995b commit d0b5724
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,17 @@ def check_closure_compiler(cmd, args, env, allowed_to_fail):
return True


# Remove this once we require python3.7 and can use std.isascii.
# See: https://docs.python.org/3/library/stdtypes.html#str.isascii
def isascii(s):
try:
s.encode('ascii')
except UnicodeEncodeError:
return False
else:
return True


@ToolchainProfiler.profile_block('closure_compiler')
def closure_compiler(filename, pretty, advanced=True, extra_closure_args=None):
env = shared.env_with_node_in_path()
Expand Down Expand Up @@ -842,6 +853,8 @@ def add_to_path(dirname):
outfile = tempfiles.get('.cc.js').name # Safe 7-bit filename

def move_to_safe_7bit_ascii_filename(filename):
if isascii(filename):
return filename
safe_filename = tempfiles.get('.js').name # Safe 7-bit filename
shutil.copyfile(filename, safe_filename)
return os.path.relpath(safe_filename, tempfiles.tmpdir)
Expand Down

0 comments on commit d0b5724

Please sign in to comment.