in scripts/extract_source.rb [343:431]
def write_out
all_thread_local_variables = []
@symbols_to_output.each do |filename, symbols|
file_thread_local_variables = []
dead_positions = (@file_to_method_and_pos[filename] || {}).dup
symbols.each do |symbol|
next if @mock.key?(symbol)
next if @external_variables.include?(symbol)
alive_pos = dead_positions[symbol]
dead_positions.delete_if { |_,pos| pos == alive_pos }
end
full_code = File.read(filename)
str = "/*--------------------------------------------------------------------\n"
str += " * Symbols referenced in this file:\n"
symbols.each do |symbol|
str += format(" * - %s\n", symbol)
end
str += " *--------------------------------------------------------------------\n"
str += " */\n\n"
next_start_pos = 0
dead_positions.each do |symbol, pos|
fail format("Position overrun for %s in %s, next_start_pos (%d) > file length (%d)", symbol, filename, next_start_pos, full_code.size) if next_start_pos > full_code.size
fail format("Position overrun for %s in %s, dead position pos[0]-1 (%d) > file length (%d)", symbol, filename, pos[0]-1, full_code.size) if pos[0]-1 > full_code.size
str += full_code[next_start_pos...(pos[0]-1)]
skipped_code = full_code[(pos[0]-1)...pos[1]]
if @mock.key?(symbol)
str += "\n" + @mock[symbol] + "\n"
elsif @external_variables.include?(symbol) && symbols.include?(symbol)
file_thread_local_variables << symbol
if skipped_code.include?('static')
str += "\n" + skipped_code.strip.gsub('static', 'static __thread') + "\n"
else
str += "\n__thread " + skipped_code.strip + "\n"
end
else
str += "\n" + skipped_code.scan(/^(
end
next_start_pos = pos[1]
end
str += full_code[next_start_pos..-1]
file_thread_local_variables.each do |variable|
str.gsub!(/(PGDLLIMPORT|extern)\s+(const|volatile)?\s*(\w+)\s+(\*{0,2})
end
all_thread_local_variables += file_thread_local_variables
if special_include_file?(filename)
out_name = File.basename(filename)
else
out_name = filename.gsub(%r{^
end
File.write(@out_path + out_name, str)
end
@include_files_to_output.each do |include_file|
next if special_include_file?(include_file)
if include_file.start_with?(@basepath + 'src/include')
out_file = @out_path + include_file.gsub(%r{^
else
out_file = @out_path + 'include/' + File.basename(include_file)
end
code = File.read(include_file)
all_thread_local_variables.each do |variable|
code.gsub!(/(PGDLLIMPORT|extern)\s+(const|volatile)?\s*(\w+)\s+(\*{0,2})
end
FileUtils.mkdir_p File.dirname(out_file)
File.write(out_file, code)
end
end