我需要修复一个由SCON动态生成包含文件的SCons项目。我创建了一个简单的例子来说明这个问题。{
current_time = Command("current_time.h",
None,
"echo '#define CURRENT_TIME' `date +%H%M` > $TARGET")
test = Program("test", "test.cpp", current_time)
# AlwaysBuild(current_time)
与test.cpp
一起:
include <iostream>
#include "current_time.h"
int main() {
std::cout << "the time is: " << CURRENT_TIME << std::endl;
}
当时间改变时,SCON不会重建项目,因为它不是魔术。解决这个问题的一种方法是将AlwaysBuild(current_time)
添加到SCons文件中
在实际项目中,使用AlwaysBuild
重建include文件是相当昂贵的,而且它每天只需要重建一次,因为没有时间,只有日期会改变。那么,如何才能实现每天只重新生成一次文件
解决方案:我创建了一个函数,返回生成的包含文件的内容:
def include_file_contents():
...
return file_contents # str
然后,我将依赖项中的None
替换为Value(include_file_contents())
:
current_time = Command("current_time.h",
Value(include_file_contents()),
"echo '#define CURRENT_TIME' `date +%H%M` > $TARGET")
像这样的方法应该会奏效:
您不应该将当前_time.h作为源。SCON将扫描test.cpp并查找包含的文件
相关问题 更多 >
编程相关推荐