我有一个帮助程序类,它扫描我的整个项目目录并收集源文件列表和相应的(目标)目标文件。编译任务的依赖是在扫描源码目录后定义的,如下图。
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
and clobber
。这使得clean
andclobber
任务变慢,这是不可取的。
为了解决这个问题,我将所有文件依赖项的生成都移到了默认任务中。这使我的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
我该如何解决这个问题?我相信有人以前遇到过类似的问题。我会很感激任何帮助。