From a41af665972e2b66580fe209076743ded178823d Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Thu, 5 Nov 2020 17:38:28 +0100 Subject: [PATCH] Fix cli default external encoding --- lib/bootsnap/cli.rb | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/bootsnap/cli.rb b/lib/bootsnap/cli.rb index 52ad39b2..8e413c3a 100644 --- a/lib/bootsnap/cli.rb +++ b/lib/bootsnap/cli.rb @@ -31,17 +31,19 @@ def initialize(argv) def precompile_command(*sources) require 'bootsnap/compile_cache/iseq' - Bootsnap::CompileCache::ISeq.cache_dir = self.cache_dir + fix_default_encoding do + Bootsnap::CompileCache::ISeq.cache_dir = self.cache_dir - if compile_gemfile - sources += $LOAD_PATH - end + if compile_gemfile + sources += $LOAD_PATH + end - sources.map { |d| File.expand_path(d) }.each do |path| - if !exclude || !exclude.match?(path) - list_ruby_files(path).each do |ruby_file| - if !exclude || !exclude.match?(ruby_file) - CompileCache::ISeq.fetch(ruby_file, cache_dir: cache_dir) + sources.map { |d| File.expand_path(d) }.each do |path| + if !exclude || !exclude.match?(path) + list_ruby_files(path).each do |ruby_file| + if !exclude || !exclude.match?(ruby_file) + CompileCache::ISeq.fetch(ruby_file, cache_dir: cache_dir) + end end end end @@ -91,6 +93,19 @@ def run private + def fix_default_encoding + if Encoding.default_external == Encoding::US_ASCII + Encoding.default_external = Encoding::UTF_8 + begin + yield + ensure + Encoding.default_external = Encoding::US_ASCII + end + else + yield + end + end + def invalid_usage!(message) STDERR.puts message STDERR.puts