Help with mapping rake dependencies

I am writing a Rakefile for a C ++ project. I want it to automatically identify #includes, forcing to rebuild object files that depend on the modified source files. I have a working solution, but I think it could be better. I am looking for offers for:

  • Suggestions for improving my function.
  • Libraries, gems, or tools that do the work for me
  • Links to cool C ++ Rakefiles that I have to check out that do similar things

Here is what I still have. This is a function that returns a list of dependencies defined by the source file. I am loading the source file for this object file and I need a list of files that will force me to rebuild my object file.

def find_deps( file )
  deps = Array.new
  # Find all include statements
  cmd = "grep -r -h -E \"#include\" #{file}"
  includes = `#{cmd}`
  includes.each do |line|
    dep = line[ /\.\/(\w+\/)*\w+\.(cpp|h|hpp)/ ]
    unless dep.nil?
      deps << dep # Add the dependency to the list
      deps += find_deps( dep )
    end
  end
  return deps
end

, :

#include "./Path/From/Top/Level/To/My/File.h" // For top-level files like main.cpp 
#include "../../../Path/From/Top/To/My/File.h" // Otherwise

, include . , .

+3
2

gcc, Make, :

g++ -M -MM -MF - inputfile.cpp

. man gcc info gcc.

+6

, , #include. #includes. ( -I). ( ). , .

(. @greyfade) , dirs.


: . " " Rakefile , make .

+3
source

Source: https://habr.com/ru/post/1734434/


All Articles