mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
f6f1a42039
By performing output to presym files after header files, there is no longer a need to check for the existence of header files. Furthermore, concentrating the file output logic into an "if" block eliminates the need for the `update` variable. Strict atomicity between presym files and header files is still not guaranteed, as before. If atomicity is truly required, it can be achieved by deleting the presym file before updating the header files.
60 lines
2.0 KiB
Ruby
60 lines
2.0 KiB
Ruby
all_prerequisites = ->(task_name, prereqs) do
|
|
Rake::Task[task_name].prerequisites.each do |prereq_name|
|
|
next if prereqs[prereq_name]
|
|
prereqs[prereq_name] = true
|
|
all_prerequisites.(Rake::Task[prereq_name].name, prereqs)
|
|
end
|
|
end
|
|
|
|
MRuby.each_target do |build|
|
|
gensym_task = task(:gensym)
|
|
|
|
presym = build.presym
|
|
|
|
include_dir = "#{build.build_dir}/include"
|
|
build.compilers.each{|c| c.include_paths << include_dir}
|
|
build.gems.each{|gem| gem.compilers.each{|c| c.include_paths << include_dir}}
|
|
|
|
prereqs = {}
|
|
ppps = []
|
|
build_dir = "#{build.build_dir}/"
|
|
mrbc_build_dir = "#{build.mrbc_build.build_dir}/" if build.mrbc_build
|
|
build.products.each{|product| all_prerequisites.(product, prereqs)}
|
|
prereqs.each_key do |prereq|
|
|
next unless File.extname(prereq) == build.exts.object
|
|
next unless prereq.start_with?(build_dir)
|
|
next if mrbc_build_dir && prereq.start_with?(mrbc_build_dir)
|
|
ppp = prereq.ext(build.exts.presym_preprocessed)
|
|
if Rake.application.lookup(ppp) ||
|
|
Rake.application.enhance_with_matching_rule(ppp)
|
|
ppps << ppp
|
|
end
|
|
end
|
|
|
|
file presym.list_path => ppps do
|
|
presyms = presym.scan(ppps)
|
|
current_presyms = presym.read_list if File.exist?(presym.list_path)
|
|
if presyms != current_presyms
|
|
mkdir_p presym.header_dir
|
|
%w[id table].each do |type|
|
|
presym.send("write_#{type}_header", presyms)
|
|
end
|
|
presym.write_list(presyms)
|
|
end
|
|
end
|
|
|
|
# Ensure .o files depend on presym headers being generated.
|
|
# This is critical when a build's .o files are compiled during another
|
|
# build's presym scanning chain (before :gensym completes), e.g.:
|
|
# - internal sub-builds (mrbc) triggered by their parent build
|
|
# - the implicit host build triggered by a cross build needing mrbc
|
|
prereqs.each_key do |prereq|
|
|
next unless File.extname(prereq) == build.exts.object
|
|
next unless prereq.start_with?(build_dir)
|
|
next if mrbc_build_dir && prereq.start_with?(mrbc_build_dir)
|
|
file prereq => presym.list_path
|
|
end
|
|
|
|
gensym_task.enhance([presym.list_path])
|
|
end
|