2012-11-29 12:12:29 +04:00
|
|
|
# -*- coding: us-ascii -*-
|
2016-07-03 00:01:04 +03:00
|
|
|
|
|
|
|
# Used to expand Ruby template files by common.mk, uncommon.mk and
|
|
|
|
# some Ruby extension libraries.
|
|
|
|
|
2008-09-26 12:18:49 +04:00
|
|
|
require 'erb'
|
2008-10-17 14:46:23 +04:00
|
|
|
require 'optparse'
|
2022-11-01 05:08:47 +03:00
|
|
|
require_relative 'lib/output'
|
2008-09-26 12:18:49 +04:00
|
|
|
|
2022-11-01 05:08:47 +03:00
|
|
|
out = Output.new
|
2013-05-16 08:13:36 +04:00
|
|
|
source = false
|
2017-10-01 05:39:22 +03:00
|
|
|
templates = []
|
2012-08-25 11:20:29 +04:00
|
|
|
|
2017-10-01 05:39:22 +03:00
|
|
|
ARGV.options do |o|
|
|
|
|
o.on('-i', '--input=PATH') {|v| template << v}
|
2013-05-16 08:13:36 +04:00
|
|
|
o.on('-x', '--source') {source = true}
|
2022-11-01 05:08:47 +03:00
|
|
|
out.def_options(o)
|
2008-10-17 14:46:23 +04:00
|
|
|
o.order!(ARGV)
|
2017-10-01 05:39:22 +03:00
|
|
|
templates << (ARGV.shift or abort o.to_s) if templates.empty?
|
2009-02-03 02:15:59 +03:00
|
|
|
end
|
2022-11-01 05:08:47 +03:00
|
|
|
|
|
|
|
# Used in prelude.c.tmpl and unicode_norm_gen.tmpl
|
|
|
|
output = out.path
|
|
|
|
vpath = out.vpath
|
2017-04-21 06:01:12 +03:00
|
|
|
|
2022-11-18 08:56:55 +03:00
|
|
|
# A hack to prevent "unused variable" warnings
|
|
|
|
output, vpath = output, vpath
|
|
|
|
|
2017-10-01 05:39:22 +03:00
|
|
|
result = templates.map do |template|
|
2019-05-30 03:58:18 +03:00
|
|
|
if ERB.instance_method(:initialize).parameters.assoc(:key) # Ruby 2.6+
|
|
|
|
erb = ERB.new(File.read(template), trim_mode: '%-')
|
2018-02-22 16:28:25 +03:00
|
|
|
else
|
|
|
|
erb = ERB.new(File.read(template), nil, '%-')
|
|
|
|
end
|
2017-10-01 05:39:22 +03:00
|
|
|
erb.filename = template
|
2022-11-18 08:45:21 +03:00
|
|
|
source ? erb.src : proc{erb.result(binding)}.call
|
2017-10-01 05:39:22 +03:00
|
|
|
end
|
|
|
|
result = result.size == 1 ? result[0] : result.join("")
|
2022-11-01 05:08:47 +03:00
|
|
|
out.write(result)
|