Debian Codegraph @

tool/update-deps

raw
1 #!/usr/bin/ruby
2
3 # tool/update-deps verify makefile dependencies.
4
5 # Requirements:
6 # gcc 4.5 (for -save-temps=obj option)
7 # GNU make (for -p option)
8 #
9 # Warning: ccache (and similar tools) must be disabled for
10 # -save-temps=obj to work properly.
11 #
12 # Usage:
13 # 1. Compile ruby with -save-temps=obj option.
14 # Ex. ./configure debugflags='-save-temps=obj -g' && make all golf
15 # 2. Run tool/update-deps to show dependency problems.
16 # Ex. ./ruby tool/update-deps
17 # 3. Use --fix to fix makefiles.
18 # Ex. ./ruby tool/update-deps --fix
19 #
20 # Other usages:
21 # * Fix makefiles using previously detected dependency problems
22 # Ex. ruby tool/update-deps --actual-fix [file]
23 # "ruby tool/update-deps --fix" is the same as "ruby tool/update-deps | ruby tool/update-deps --actual-fix".
24
25 require 'optparse'
26 require 'stringio'
27 require 'pathname'
28 require 'open3'
29 require 'pp'
30
31 # When out-of-place build, files may be built in source directory or
32 # build directory.
33 # Some files are always built in the source directory.
34 # Some files are always built in the build directory.
35 # Some files are built in the source directory for tarball but build directory for repository (svn).
36
37 =begin
38 How to build test directories.
39
40 VER=2.2.0
41 REV=48577
42 tar xf ruby-$VER-r$REV.tar.xz
43 cp -a ruby-$VER-r$REV tarball_source_dir_original
44 mv ruby-$VER-r$REV tarball_source_dir_after_build
45 svn co -q -r$REV https://svn.ruby-lang.org/repos/ruby/trunk ruby
46 (cd ruby; autoconf)
47 cp -a ruby repo_source_dir_original
48 mv ruby repo_source_dir_after_build
49 mkdir tarball_build_dir repo_build_dir tarball_install_dir repo_install_dir
50 (cd tarball_build_dir; ../tarball_source_dir_after_build/configure --prefix=$(cd ../tarball_install_dir; pwd) && make all golf install) > tarball.log 2>&1
51 (cd repo_build_dir; ../repo_source_dir_after_build/configure --prefix=$(cd ../repo_install_dir; pwd) && make all golf install) > repo.log 2>&1
52 ruby -rpp -rfind -e '
53 ds = %w[
54 repo_source_dir_original
55 repo_source_dir_after_build
56 repo_build_dir
57 tarball_source_dir_original
58 tarball_source_dir_after_build
59 tarball_build_dir
60 ]
61 files = {}
62 ds.each {|d|
63 files[d] = {}
64 Dir.chdir(d) { Find.find(".") {|f| files[d][f] = true if %r{\.(c|h|inc|dmyh)\z} =~ f } }
65 }
66 result = {}
67 files_union = files.values.map {|h| h.keys }.flatten.uniq.sort
68 files_union.each {|f|
69 k = files.map {|d,h| h[f] ? d : nil }.compact.sort
70 next if k == %w[repo_source_dir_after_build repo_source_dir_original tarball_source_dir_after_build tarball_source_dir_original]
71 next if k == %w[repo_build_dir tarball_build_dir] && File.basename(f) == "extconf.h"
72 result[k] ||= []
73 result[k] << f
74 }
75 result.each {|k,v|
76 k.each {|d|
77 puts d
78 }
79 v.each {|f|
80 puts " " + f.sub(%r{\A\./}, "")
81 }
82 puts
83 }
84 ' | tee compare.log
85 =end
86
87 # Files built in the source directory.
88 # They can be referenced as $(top_srcdir)/filename.
89 # % ruby -e 'def g(d) Dir.chdir(d) { Dir["**/*.{c,h,inc,dmyh}"] } end; puts((g("repo_source_dir_after_build") - g("repo_source_dir_original")).sort)'
90 FILES_IN_SOURCE_DIRECTORY = %w[
91 ]
92
93 # Files built in the build directory (except extconf.h).
94 # They can be referenced as $(topdir)/filename.
95 # % ruby -e 'def g(d) Dir.chdir(d) { Dir["**/*.{c,h,inc,dmyh}"] } end; puts(g("tarball_build_dir").reject {|f| %r{/extconf.h\z} =~ f }.sort)'
96 FILES_IN_BUILD_DIRECTORY = %w[
97 encdb.h
98 ext/etc/constdefs.h
99 ext/socket/constdefs.c
100 ext/socket/constdefs.h
101 probes.h
102 transdb.h
103 verconf.h
104 ]
105
106 # They are built in the build directory if the source is obtained from the repository.
107 # However they are pre-built for tarball and they exist in the source directory extracted from the tarball.
108 # % ruby -e 'def g(d) Dir.chdir(d) { Dir["**/*.{c,h,inc,dmyh}"] } end; puts((g("repo_build_dir") & g("tarball_source_dir_original")).sort)'
109 FILES_NEED_VPATH = %w[
110 ext/rbconfig/sizeof/sizes.c
111 ext/ripper/eventids1.c
112 ext/ripper/eventids2table.c
113 ext/ripper/ripper.c
114 ext/ripper/ripper_init.c
115 golf_prelude.c
116 id.c
117 id.h
118 insns.inc
119 insns_info.inc
120 known_errors.inc
121 lex.c
122 miniprelude.c
123 newline.c
124 node_name.inc
125 optinsn.inc
126 optunifs.inc
127 parse.c
128 parse.h
129 probes.dmyh
130 revision.h
131 vm.inc
132 vmtc.inc
133
134 enc/trans/big5.c
135 enc/trans/chinese.c
136 enc/trans/emoji.c
137 enc/trans/emoji_iso2022_kddi.c
138 enc/trans/emoji_sjis_docomo.c
139 enc/trans/emoji_sjis_kddi.c
140 enc/trans/emoji_sjis_softbank.c
141 enc/trans/escape.c
142 enc/trans/gb18030.c
143 enc/trans/gbk.c
144 enc/trans/iso2022.c
145 enc/trans/japanese.c
146 enc/trans/japanese_euc.c
147 enc/trans/japanese_sjis.c
148 enc/trans/korean.c
149 enc/trans/single_byte.c
150 enc/trans/utf8_mac.c
151 enc/trans/utf_16_32.c
152
153 prism/api_node.c
154 prism/ast.h
155 prism/node.c
156 prism/prettyprint.c
157 prism/serialize.c
158 prism/token_type.c
159 prism/version.h
160 ]
161
162 # Multiple files with same filename.
163 # It is not good idea to refer them using VPATH.
164 # Files in FILES_SAME_NAME_INC is referenced using $(hdrdir).
165 # Files in FILES_SAME_NAME_TOP is referenced using $(top_srcdir).
166
167 FILES_SAME_NAME_INC = %w[
168 include/ruby.h
169 include/ruby/ruby.h
170 include/ruby/version.h
171 ]
172
173 FILES_SAME_NAME_TOP = %w[
174 version.h
175 ]
176
177 # Files that may or may not exist on CI for some reason.
178 # Windows build generally seems to have missing dependencies.
179 UNSTABLE_FILES = %r{\Awin32/[^/]+\.o\z}
180
181 # Other source files exist in the source directory.
182
183 def in_makefile(target, source)
184 target = target.to_s
185 source = source.to_s
186 case target
187 when %r{\A[^/]*\z}, %r{\Acoroutine/}, %r{\Aprism/}
188 target2 = "#{target.sub(/\.o\z/, '.$(OBJEXT)')}"
189 case source
190 when *FILES_IN_SOURCE_DIRECTORY then source2 = "$(top_srcdir)/#{source}"
191 when *FILES_IN_BUILD_DIRECTORY then source2 = "{$(VPATH)}#{source}" # VPATH is not used now but it may changed in future.
192 when *FILES_NEED_VPATH then source2 = "{$(VPATH)}#{source}"
193 when *FILES_SAME_NAME_INC then source2 = "$(hdrdir)/#{source.sub(%r{\Ainclude/},'')}"
194 when *FILES_SAME_NAME_TOP then source2 = "$(top_srcdir)/#{source}"
195 when 'thread_pthread.c' then source2 = '{$(VPATH)}thread_$(THREAD_MODEL).c'
196 when 'thread_pthread.h' then source2 = '{$(VPATH)}thread_$(THREAD_MODEL).h'
197 when %r{\A[^/]*\z} then source2 = "{$(VPATH)}#{File.basename source}"
198 when %r{\A\.ext/include/[^/]+/ruby/} then source2 = "{$(VPATH)}#{$'}"
199 when %r{\Ainclude/ruby/} then source2 = "{$(VPATH)}#{$'}"
200 when %r{\Aenc/} then source2 = "{$(VPATH)}#{$'}"
201 when %r{\Amissing/} then source2 = "{$(VPATH)}#{$'}"
202 when %r{\Accan/} then source2 = "$(CCAN_DIR)/#{$'}"
203 when %r{\Adefs/} then source2 = "{$(VPATH)}#{source}"
204 when %r{\Acoroutine/} then source2 = "{$(VPATH)}$(COROUTINE_H)"
205 else source2 = "$(top_srcdir)/#{source}"
206 end
207 ["common.mk", target2, source2]
208 when %r{\Aenc/}
209 target2 = "#{target.sub(/\.o\z/, '.$(OBJEXT)')}"
210 case source
211 when *FILES_IN_SOURCE_DIRECTORY then source2 = "$(top_srcdir)/#{source}"
212 when *FILES_IN_BUILD_DIRECTORY then source2 = source
213 when *FILES_NEED_VPATH then source2 = source
214 when *FILES_SAME_NAME_INC then source2 = "$(hdrdir)/#{source.sub(%r{\Ainclude/},'')}"
215 when *FILES_SAME_NAME_TOP then source2 = "$(top_srcdir)/#{source}"
216 when %r{\A\.ext/include/[^/]+/ruby/} then source2 = $'
217 when %r{\Ainclude/ruby/} then source2 = $'
218 when %r{\Aenc/unicode/[\d.]+/} then source2 = '$(UNICODE_HDR_DIR)/' + $'
219 when %r{\Aenc/} then source2 = source
220 else source2 = "$(top_srcdir)/#{source}"
221 end
222 ["enc/depend", target2, source2]
223 when %r{\Aext/}
224 targetdir = File.dirname(target)
225 unless File.exist?("#{targetdir}/extconf.rb")
226 warn "warning: not found: #{targetdir}/extconf.rb"
227 end
228 target2 = File.basename(target)
229 relpath = Pathname(source).relative_path_from(Pathname(target).dirname).to_s
230 case source
231 when *FILES_IN_SOURCE_DIRECTORY then source2 = "$(top_srcdir)/#{source}"
232 when *FILES_IN_BUILD_DIRECTORY then source2 = relpath
233 when *FILES_NEED_VPATH then source2 = "{$(VPATH)}#{File.basename source}"
234 when *FILES_SAME_NAME_INC then source2 = "$(hdrdir)/#{source.sub(%r{\Ainclude/},'')}"
235 when *FILES_SAME_NAME_TOP then source2 = "$(top_srcdir)/#{source}"
236 when %r{\A\.ext/include/[^/]+/ruby/} then source2 = "$(arch_hdrdir)/ruby/#{$'}"
237 when %r{\Ainclude/} then source2 = "$(hdrdir)/#{$'}"
238 when %r{\A#{Regexp.escape targetdir}/extconf\.h\z} then source2 = "$(RUBY_EXTCONF_H)"
239 when %r{\A#{Regexp.escape targetdir}/} then source2 = $'
240 when %r{\A#{Regexp.escape File.dirname(targetdir)}/} then source2 = "$(srcdir)/../#{$'}"
241 else source2 = "$(top_srcdir)/#{source}"
242 end
243 ["#{File.dirname(target)}/depend", target2, source2]
244 # Files that may or may not exist on CI for some reason.
245 # Windows build generally seems to have missing dependencies.
246 when UNSTABLE_FILES
247 warn "warning: ignoring: #{target}"
248 else
249 raise "unexpected target: #{target}"
250 end
251 end
252
253 DEPENDENCIES_SECTION_START_MARK = "\# AUTOGENERATED DEPENDENCIES START\n"
254 DEPENDENCIES_SECTION_END_MARK = "\# AUTOGENERATED DEPENDENCIES END\n"
255
256 def init_global
257 ENV['LC_ALL'] = 'C'
258 if mkflag0 = ENV['GNUMAKEFLAGS'] and (mkflag = mkflag0.sub(/(\A|\s+)-j\d*(?=\s+|\z)/, '')) != mkflag0
259 mkflag.strip!
260 ENV['GNUMAKEFLAGS'] = mkflag
261 end
262
263 $opt_fix = false
264 $opt_a = false
265 $opt_actual_fix = false
266 $i_not_found = false
267 end
268
269 def optionparser
270 op = OptionParser.new
271 op.banner = 'Usage: ruby tool/update-deps'
272 op.def_option('-a', 'show valid dependencies') { $opt_a = true }
273 op.def_option('--fix') { $opt_fix = true }
274 op.def_option('--actual-fix') { $opt_actual_fix = true }
275 op
276 end
277
278 def read_make_deps(cwd)
279 dependencies = {}
280 make_p, make_p_stderr, make_p_status = Open3.capture3("make -p all miniruby exe/ruby golf")
281 File.open('update-deps.make.out.log', 'w') {|f| f.print make_p }
282 File.open('update-deps.make.err.log', 'w') {|f| f.print make_p_stderr }
283 if !make_p_status.success?
284 puts make_p_stderr
285 raise "make failed"
286 end
287 dirstack = [cwd]
288 curdir = nil
289 make_p.scan(%r{Entering\ directory\ ['`](.*)'|
290 ^\#\ (GNU\ Make)\ |
291 ^CURDIR\ :=\ (.*)|
292 ^([/0-9a-zA-Z._-]+):(.*)\n((?:\#.*\n)*)|
293 ^\#\ (Finished\ Make\ data\ base\ on)\ |
294 Leaving\ directory\ ['`](.*)'}x) {
295 directory_enter = $1
296 data_base_start = $2
297 data_base_curdir = $3
298 rule_target = $4
299 rule_sources = $5
300 rule_desc = $6
301 data_base_end = $7
302 directory_leave = $8
303 #p $~
304 if directory_enter
305 enter_dir = Pathname(directory_enter)
306 #p [:enter, enter_dir]
307 dirstack.push enter_dir
308 elsif data_base_start
309 curdir = nil
310 elsif data_base_curdir
311 curdir = Pathname(data_base_curdir)
312 elsif rule_target && rule_sources && rule_desc &&
313 /Modification time never checked/ !~ rule_desc # This pattern match eliminates rules which VPATH is not expanded.
314 target = rule_target
315 deps = rule_sources
316 deps = deps.scan(%r{[/0-9a-zA-Z._-]+})
317 deps.delete_if {|dep| /\.time\z/ =~ dep} # skip timestamp
318 next if /\.o\z/ !~ target.to_s
319 next if /libyjit.o\z/ =~ target.to_s # skip YJIT Rust object (no corresponding C source)
320 next if /\.bundle\// =~ target.to_s
321 next if /\A\./ =~ target.to_s # skip rules such as ".c.o"
322 #p [curdir, target, deps]
323 dir = curdir || dirstack.last
324 dependencies[dir + target] ||= []
325 dependencies[dir + target] |= deps.map {|dep| dir + dep }
326 elsif data_base_end
327 curdir = nil
328 elsif directory_leave
329 leave_dir = Pathname(directory_leave)
330 #p [:leave, leave_dir]
331 if leave_dir != dirstack.last
332 warn "unexpected leave_dir : #{dirstack.last.inspect} != #{leave_dir.inspect}"
333 end
334 dirstack.pop
335 end
336 }
337 dependencies
338 end
339
340 #def guess_compiler_wd(filename, hint0)
341 # hint = hint0
342 # begin
343 # guess = hint + filename
344 # if guess.file?
345 # return hint
346 # end
347 # hint = hint.parent
348 # end while hint.to_s != '.'
349 # raise ArgumentError, "can not find #{filename} (hint: #{hint0})"
350 #end
351
352 def read_single_cc_deps(path_i, cwd, fn_o)
353 files = {}
354 compiler_wd = nil
355 path_i.each_line {|line|
356 next if /\A\# \d+ "(.*)"/ !~ line
357 dep = $1
358
359 next if %r{\A<.*>\z} =~ dep # omit <command-line>, etc.
360 next if /\.e?rb\z/ =~ dep
361 # gcc emits {# 1 "/absolute/directory/of/the/source/file//"} at 2nd line.
362 if /\/\/\z/ =~ dep
363 compiler_wd = Pathname(dep.sub(%r{//\z}, ''))
364 next
365 end
366
367 files[dep] = true
368 }
369 compiler_wd ||= fn_o.to_s.start_with?("enc/") ? cwd : path_i.parent
370
371 deps = []
372 files.each_key {|dep|
373 dep = Pathname(dep)
374 if dep.relative?
375 dep = compiler_wd + dep
376 end
377 if !dep.file?
378 warn "warning: file not found: #{dep}"
379 next
380 end
381 next if !dep.to_s.start_with?(cwd.to_s) # omit system headers.
382 deps << dep
383 }
384 if deps.include?(cwd + "probes.h")
385 deps << (cwd + "probes.dmyh")
386 end
387 deps
388 end
389
390 def read_cc_deps(cwd)
391 deps = {}
392 Pathname.glob('**/*.o').sort.each {|fn_o|
393 fn_i = fn_o.sub_ext('.i')
394 if !fn_i.exist?
395 next if fn_o.sub_ext('.S').exist?
396 warn "warning: not found: #{fn_i}"
397 $i_not_found = true
398 next
399 end
400 path_o = cwd + fn_o
401 path_i = cwd + fn_i
402 deps[path_o] = read_single_cc_deps(path_i, cwd, fn_o)
403 }
404 deps
405 end
406
407 def concentrate(dependencies, cwd)
408 deps = {}
409 dependencies.keys.sort.each {|target|
410 sources = dependencies[target]
411 target = target.relative_path_from(cwd)
412 sources = sources.map {|s|
413 rel = s.relative_path_from(cwd)
414 rel
415 }
416 if %r{\A\.\.(/|\z)} =~ target.to_s
417 warn "warning: out of tree target: #{target}"
418 next
419 end
420 sources = sources.reject {|s|
421 if %r{\A\.\.(/|\z)} =~ s.to_s
422 warn "warning: out of tree source: #{s}"
423 true
424 elsif %r{/\.time\z} =~ s.to_s
425 true
426 else
427 false
428 end
429 }
430 deps[target] = sources
431 }
432 deps
433 end
434
435 def sort_paths(paths)
436 paths.sort_by {|t|
437 ary = t.to_s.split(%r{/})
438 ary.map.with_index {|e, i| i == ary.length-1 ? [0, e] : [1, e] } # regular file first, directories last.
439 }
440 end
441
442 def show_deps(tag, deps)
443 targets = sort_paths(deps.keys)
444 targets.each {|t|
445 sources = sort_paths(deps[t])
446 sources.each {|s|
447 puts "#{tag} #{t}: #{s}"
448 }
449 }
450 end
451
452 def detect_dependencies(out=$stdout)
453 cwd = Pathname.pwd
454 make_deps = read_make_deps(cwd)
455 #pp make_deps
456 make_deps = concentrate(make_deps, cwd)
457 #pp make_deps
458 cc_deps = read_cc_deps(cwd)
459 #pp cc_deps
460 cc_deps = concentrate(cc_deps, cwd)
461 #pp cc_deps
462 return make_deps, cc_deps
463 end
464
465 def compare_deps(make_deps, cc_deps, out=$stdout)
466 targets = make_deps.keys | cc_deps.keys
467
468 makefiles = {}
469
470 make_lines_hash = {}
471 make_deps.each {|t, sources|
472 sources.each {|s|
473 makefile, t2, s2 = in_makefile(t, s)
474 makefiles[makefile] = true
475 make_lines_hash[makefile] ||= Hash.new(false)
476 make_lines_hash[makefile]["#{t2}: #{s2}"] = true
477 }
478 }
479
480 cc_lines_hash = {}
481 cc_deps.each {|t, sources|
482 sources.each {|s|
483 makefile, t2, s2 = in_makefile(t, s)
484 makefiles[makefile] = true
485 cc_lines_hash[makefile] ||= Hash.new(false)
486 cc_lines_hash[makefile]["#{t2}: #{s2}"] = true
487 }
488 }
489
490 makefiles.keys.compact.sort.each {|makefile|
491 cc_lines = cc_lines_hash[makefile] || Hash.new(false)
492 make_lines = make_lines_hash[makefile] || Hash.new(false)
493 content = begin
494 File.read(makefile)
495 rescue Errno::ENOENT
496 ''
497 end
498 if /^#{Regexp.escape DEPENDENCIES_SECTION_START_MARK}
499 ((?:.*\n)*)
500 #{Regexp.escape DEPENDENCIES_SECTION_END_MARK}/x =~ content
501 pre_post_part = [$`, $']
502 current_lines = Hash.new(false)
503 $1.each_line {|line| current_lines[line.chomp] = true }
504 (cc_lines.keys | current_lines.keys | make_lines.keys).sort.each {|line|
505 status = [cc_lines[line], current_lines[line], make_lines[line]]
506 case status
507 when [true, true, true]
508 # no problem
509 when [true, true, false]
510 out.puts "warning #{makefile} : #{line} (make doesn't detect written dependency)"
511 when [true, false, true]
512 out.puts "add_auto #{makefile} : #{line} (harmless)" # This is automatically updatable.
513 when [true, false, false]
514 out.puts "add_auto #{makefile} : #{line} (harmful)" # This is automatically updatable.
515 when [false, true, true]
516 out.puts "del_cc #{makefile} : #{line}" # Not automatically updatable because build on other OS may need the dependency.
517 when [false, true, false]
518 out.puts "del_cc #{makefile} : #{line} (Curious. make doesn't detect this dependency.)" # Not automatically updatable because build on other OS may need the dependency.
519 when [false, false, true]
520 out.puts "del_make #{makefile} : #{line}" # Not automatically updatable because the dependency is written manually.
521 else
522 raise "unexpected status: #{status.inspect}"
523 end
524 }
525 else
526 (cc_lines.keys | make_lines.keys).sort.each {|line|
527 status = [cc_lines[line], make_lines[line]]
528 case status
529 when [true, true]
530 # no problem
531 when [true, false]
532 out.puts "add_manual #{makefile} : #{line}" # Not automatically updatable because makefile has no section to update automatically.
533 when [false, true]
534 out.puts "del_manual #{makefile} : #{line}" # Not automatically updatable because makefile has no section to update automatically.
535 else
536 raise "unexpected status: #{status.inspect}"
537 end
538 }
539 end
540 }
541 end
542
543 def prepare_build
544 unless File.exist?("Makefile")
545 if File.exist?("autogen.sh")
546 system("./autogen.sh")
547 elsif !File.exist?("configure")
548 system("autoreconf", "-i", "-s")
549 end
550 system("./configure", "-q", "--enable-load-relative", "--prefix=/.",
551 "--disable-install-doc", "debugflags=-save-temps=obj -g")
552 end
553 end
554
555 def main_show(out=$stdout)
556 prepare_build
557 make_deps, cc_deps = detect_dependencies(out)
558 compare_deps(make_deps, cc_deps, out)
559 end
560
561 def extract_deplines(problems)
562 adds = {}
563 others = {}
564 problems.each_line {|line|
565 case line
566 when /\Aadd_auto (\S+) : ((\S+): (\S+))/
567 (adds[$1] ||= []) << [line, "#{$2}\n"]
568 when /\A(?:del_cc|del_make|add_manual|del_manual|warning) (\S+) : /
569 (others[$1] ||= []) << line
570 else
571 raise "unexpected line: #{line.inspect}"
572 end
573 }
574 return adds, others
575 end
576
577 def main_actual_fix(problems)
578 adds, others = extract_deplines(problems)
579 (adds.keys | others.keys).sort.each {|makefile|
580 content = begin
581 File.read(makefile)
582 rescue Errno::ENOENT
583 nil
584 end
585
586 if content &&
587 /^#{Regexp.escape DEPENDENCIES_SECTION_START_MARK}
588 ((?:.*\n)*)
589 #{Regexp.escape DEPENDENCIES_SECTION_END_MARK}/x =~ content
590 pre_dep_post = [$`, $1, $']
591 else
592 pre_dep_post = nil
593 end
594
595 if pre_dep_post && adds[makefile]
596 pre_lines, dep_lines, post_lines = pre_dep_post
597 dep_lines = dep_lines.lines.to_a
598 add_lines = adds[makefile].map(&:last)
599 new_lines = (dep_lines | add_lines).sort.uniq
600 new_content = [
601 pre_lines,
602 DEPENDENCIES_SECTION_START_MARK,
603 *new_lines,
604 DEPENDENCIES_SECTION_END_MARK,
605 post_lines
606 ].join
607 if content != new_content
608 puts "modified: #{makefile}"
609 tmp_makefile = "#{makefile}.new.#{$$}"
610 File.write(tmp_makefile, new_content)
611 File.rename tmp_makefile, makefile
612 (add_lines - dep_lines).each {|line| puts " added #{line}" }
613 else
614 puts "not modified: #{makefile}"
615 end
616 if others[makefile]
617 others[makefile].each {|line| puts " #{line}" }
618 end
619 else
620 if pre_dep_post
621 puts "no additional lines: #{makefile}"
622 elsif content
623 puts "no dependencies section: #{makefile}"
624 else
625 puts "no makefile: #{makefile}"
626 end
627 if adds[makefile]
628 puts " warning: dependencies section was exist at previous phase."
629 end
630 if adds[makefile]
631 adds[makefile].map(&:first).each {|line| puts " #{line}" }
632 end
633 if others[makefile]
634 others[makefile].each {|line| puts " #{line}" }
635 end
636 end
637 }
638 end
639
640 def main_fix
641 problems = StringIO.new
642 main_show(problems)
643 main_actual_fix(problems.string)
644 end
645
646 def run
647 op = optionparser
648 op.parse!(ARGV)
649 if $opt_actual_fix
650 main_actual_fix(ARGF.read)
651 elsif $opt_fix
652 main_fix
653 else
654 main_show
655 end
656 end
657
658 init_global
659 run
660 if $i_not_found
661 warn "warning: missing *.i files, see help in #$0 and ensure ccache is disabled"
662 end