mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Expand tabs for rb_mjit_header.h (#2975)
This is necessary to avoid converting a hard tab to just 1 space in
preprocessor to generate rb_mjit_header.h, which is helpful when using
gdb or perf report.
See also: [Misc #16112]
This reverts commit 91acdd17c4
.
Fixed permission failure on Travis, encoding, and added SKIPPED_FILES.
This commit is contained in:
parent
1c05682929
commit
9ebf74fd78
Notes:
git
2020-03-23 03:51:07 +09:00
Merged-By: k0kubun <takashikkbn@gmail.com>
2 changed files with 50 additions and 2 deletions
|
@ -224,9 +224,10 @@ mjit_config.h: Makefile
|
|||
# Other `-Dxxx`s preceding `-DMJIT_HEADER` will be removed in transform_mjit_header.rb.
|
||||
# So `-DMJIT_HEADER` should be passed first when rb_mjit_header.h is generated.
|
||||
$(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time: probes.h vm.$(OBJEXT) \
|
||||
$(TIMESTAMPDIR)/$(arch)/.time
|
||||
$(TIMESTAMPDIR)/$(arch)/.time $(srcdir)/tool/run_without_tabs.rb
|
||||
$(ECHO) building $(@F:.time=.h)
|
||||
$(Q) $(CPP) -DMJIT_HEADER $(MJIT_HEADER_FLAGS) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(srcdir)/vm.c $(CPPOUTFLAG)$(@F:.time=.h).new
|
||||
$(Q) $(BASERUBY) $(srcdir)/tool/run_without_tabs.rb \
|
||||
$(CPP) -DMJIT_HEADER $(MJIT_HEADER_FLAGS) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(srcdir)/vm.c $(CPPOUTFLAG)$(@F:.time=.h).new
|
||||
$(Q) $(IFCHANGE) "--timestamp=$@" $(@F:.time=.h) $(@F:.time=.h).new
|
||||
|
||||
$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).h: $(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time
|
||||
|
|
47
tool/run_without_tabs.rb
Normal file
47
tool/run_without_tabs.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
# frozen_string_literal: true
|
||||
# This is a script to run a command in ARGV, expanding tabs in some files
|
||||
# included by vm.c to normalize indentation of MJIT header.
|
||||
#
|
||||
# Note that preprocessor of GCC converts a hard tab to one spaces, where
|
||||
# we expect it to be shown as 8 spaces. To obviate this script, we need
|
||||
# to convert all tabs to spaces in these files.
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
# These files have no hard tab indentations. Skip normalizing these files.
|
||||
SKIPPED_FILES = %w[
|
||||
vm_callinfo.h
|
||||
vm_debug.h
|
||||
vm_exec.h
|
||||
vm_opts.h
|
||||
]
|
||||
|
||||
srcdir = File.expand_path('..', __dir__)
|
||||
targets = Dir.glob(File.join(srcdir, 'vm*.*')) - SKIPPED_FILES.map { |f| File.join(srcdir, f) }
|
||||
sources = {}
|
||||
mtimes = {}
|
||||
|
||||
if skip = targets.any? { |target| !File.writable?(target) }
|
||||
puts "tool/run_without_tabs.rb: srcdir has non-writable files. Skipping tab expansion."
|
||||
end
|
||||
|
||||
targets.each do |target|
|
||||
sources[target] = File.read(target)
|
||||
mtimes[target] = File.mtime(target)
|
||||
|
||||
expanded = sources[target].force_encoding('UTF-8').gsub(/^\t+/) { |tab| ' ' * 8 * tab.length }
|
||||
if sources[target] == expanded
|
||||
puts "#{target.dump} has no hard tab indentation. This should be ignored in tool/run_without_tabs.rb."
|
||||
end
|
||||
File.write(target, expanded)
|
||||
FileUtils.touch(target, mtime: mtimes[target])
|
||||
end unless skip
|
||||
|
||||
result = system(*ARGV)
|
||||
|
||||
targets.each do |target|
|
||||
File.write(target, sources.fetch(target))
|
||||
FileUtils.touch(target, mtime: mtimes.fetch(target))
|
||||
end unless skip
|
||||
|
||||
exit result
|
Loading…
Add table
Reference in a new issue