我有一个帮助程序类,它扫描我的整个项目目录并收集源文件和相应(目标)对象文件的列表。扫描源目录后,定义了编译任务的依赖关系,如下所示。为Rake任务指定文件先决条件
CLEAN.include(FileList[obj_dir + '**/*.o'])
CLOBBER.include(FileList[exe_dir + '**/*.exe'])
$proj = DirectoryParser.new(src_dir)
$proj.source_files.each do |source_file|
file source_file.obj_file do
sh "gcc -c ..."
end
end
$proj.obj_files.each do |obj_file|
task :compile => obj_file
end
task :compile do
end
由于$proj
是全球性的,DirectoryParser.new()的任何任务,被称为包括clean
和clobber
时被调用。这使得clean
和clobber
任务变慢,这是不可取的。
为了解决这个问题,我将所有生成的文件依赖项都移动到默认任务中。这使得我的clean
和clobber
任务更快,但是,我现在无法独立调用我的编译或链接任务。
CLEAN.include(FileList[obj_dir + '**/*.o'])
CLOBBER.include(FileList[exe_dir + '**/*.exe'])
task :compile => $proj.source_files do # Throws error!
end
task :default => do
$proj = DirectoryParser.new(src_dir)
$proj.source_files.each do |source_file|
file source_file.obj_file do
sh "gcc -c ..."
end
end
$proj.obj_files.each do |obj_file|
task :compile => obj_file
end
... compile
... link
... execute
end
我该如何解决这个问题?我相信有人以前遇到过类似的问题。我会很感激任何帮助。
我已决定保留上述相同的解决方案,花费的时间比我想要的要长一些。除非有人提出更好的解决方案? – thegreendroid