Skip to content

Commit

Permalink
Merge pull request #332 from Shopify/fix-precompile-encoding
Browse files Browse the repository at this point in the history
Fix cli default external encoding
  • Loading branch information
casperisfine committed Nov 6, 2020
2 parents ed25baa + a41af66 commit 1aae379
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/bootsnap/cli.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1aae379

Please sign in to comment.