Fix *.d parsing with gcc 9.3.0

Before this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  rake aborted!
  Don't know how to build task '/home/foo/mruby/build/host/src/gc.o' (See the list of available tasks with `rake --tasks`)
  ...

After this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  CC    src/gc.c -> build/host/src/gc.o
  ...

With gcc 9.3.0 on Ubuntu 20.04, build/host/src/array.d looks like:

  /build/host/src/array.o: /src/array.c \
   /include/mruby.h /include/mrbconf.h \
   /include/mruby/common.h \
   ...
   /include/mruby/range.h \
   /src/value_array.h

and it has been parsed to:

  [
                                           # /src/array.c missing
    "/include/mruby.h /include/mrbconf.h", # incorrectly parsed
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]

After this change, *.d will be parsed correctly.

  [
    "/src/array.c",
    "/include/mruby.h",
    "/include/mrbconf.h",
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]
parent 5bfb70e9
......@@ -139,6 +139,15 @@ module MRuby
# /include/mruby/value.h \
# /src/value_array.h
#
# ==== Without <tt>-MP</tt> compiler flag (gcc (Ubuntu 9.3.0-10ubuntu2) 9.3.0)
#
# /build/host/src/array.o: /src/array.c \
# /include/mruby.h /include/mrbconf.h \
# /include/mruby/common.h \
# ...
# /include/mruby/range.h \
# /src/value_array.h
#
# ==== With <tt>-MP</tt> compiler flag
#
# /build/host/src/array.o: \
......@@ -155,11 +164,18 @@ module MRuby
#
def get_dependencies(file)
file = file.ext('d') unless File.extname(file) == '.d'
deps = []
if File.exist?(file)
File.foreach(file){|line| deps << $1 if /^ +(.*?)(?: *\\)?$/ =~ line}
deps.uniq!
end
return [MRUBY_CONFIG] unless File.exist?(file)
deps = "".gsub("\\\n ", "").split("\n").map do |dep_line|
# dep_line:
# - "/build/host/src/array.o: /src/array.c /include/mruby/common.h ..."
# - ""
# - "/include/mruby/common.h:"
dep_line.scan(/^\S+:\s+(.+)$/).flatten.map { |s| s.split(' ') }.flatten
# => ["/src/array.c", "/include/mruby/common.h" , ...]
# []
# []
end.flatten.uniq
deps << MRUBY_CONFIG
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment