Skip to content

Commit

Permalink
Avoid diffutils 3.8 bug#61193 [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Apr 14, 2023
1 parent 3733ee8 commit eab1f1e
Showing 1 changed file with 59 additions and 5 deletions.
64 changes: 59 additions & 5 deletions tool/enc-unicode.rb
Expand Up @@ -10,9 +10,22 @@
# ruby1.9 tool/enc-unicode.rb data_dir > enc/unicode/name2ctype.kwd
# You can get source file for gperf. After this, simply make ruby.

if ARGV[0] == "--header"
header = true
ARGV.shift
while arg = ARGV.shift
case arg
when "--"
break
when "--header"
header = true
when "--diff"
diff = ARGV.shift or abort "#{$0}: --diff=DIFF-COMMAND"
when /\A--diff=(.+)/m
diff = $1
when /\A-/
abort "#{$0}: unknown option #{arg}"
else
ARGV.unshift(arg)
break
end
end
unless ARGV.size == 2
abort "Usage: #{$0} data_directory emoji_data_directory"
Expand Down Expand Up @@ -544,6 +557,47 @@ def write(str)
if header
require 'tempfile'

def diff_args(diff)
ok = IO.popen([diff, "-DDIFF_TEST", IO::NULL, "-"], "r+") do |f|
f.puts "Test for diffutils 3.8"
f.close_write
/^#if/ =~ f.read
end
if ok
proc {|macro, *inputs|
[diff, "-D#{macro}", *inputs]
}
else
IO.popen([diff, "--old-group-format=%<", "--new-group-format=%>", IO::NULL, IO::NULL], err: %i[child out], &:read)
unless $?.success?
abort "#{$0}: #{diff} -D does not work"
end
warn "Avoiding diffutils 3.8 bug#61193"
proc {|macro, *inputs|
[diff] + [
"--old-group-format=" \
"#ifndef @\n" \
"%<" \
"#endif /* ! @ */\n",

"--new-group-format=" \
"#ifdef @\n" \
"%>" \
"#endif /* @ */\n",

"--changed-group-format=" \
"#ifndef @\n" \
"%<" \
"#else /* @ */\n" \
"%>" \
"#endif /* @ */\n"
].map {|opt| opt.gsub(/@/) {macro}} + inputs
}
end
end

ifdef = diff_args(diff || "diff")

NAME2CTYPE = %w[gperf -7 -c -j1 -i1 -t -C -P -T -H uniname2ctype_hash -Q uniname2ctype_pool -N uniname2ctype_p]

fds = []
Expand All @@ -554,8 +608,8 @@ def write(str)
end while syms.pop
fds.each(&:close)
ff = nil
IO.popen(%W[diff -DUSE_UNICODE_AGE_PROPERTIES #{fds[1].path} #{fds[0].path}], "r") {|age|
IO.popen(%W[diff -DUSE_UNICODE_PROPERTIES #{fds[2].path} -], "r", in: age) {|f|
IO.popen(ifdef["USE_UNICODE_AGE_PROPERTIES", fds[1].path, fds[0].path], "r") {|age|
IO.popen(ifdef["USE_UNICODE_PROPERTIES", fds[2].path, "-"], "r", in: age) {|f|
ansi = false
f.each {|line|
if /ANSI-C code produced by gperf/ =~ line
Expand Down

0 comments on commit eab1f1e

Please sign in to comment.