让protobuf生成器支持时间戳检查 (二)

2014-11-23 22:57:33 · 作者: · 浏览: 13
orter(&source_tree, &error_collector);

vector parsed_files;


if ( time_stamp_filename_ != "" )
CheckFileStamp( time_stamp_filename_ );
加黑部分为添加的代码, 这里是检查时间戳的入口

同时,我们还需要添加命令行解析开关, 这里在

bool CommandLineInterface::InterpretArgument(const string& name,
const string& value) {

函数中,找到:

} else if (name == "--error_format") {
if (value == "gcc") {
error_format_ = ERROR_FORMAT_GCC;
} else if (value == "msvs") {
error_format_ = ERROR_FORMAT_MSVS;
} else {
cerr << "Unknown error format: " << value << endl;
return false;
}

}
else if ( name == "--timestampfile" ){
time_stamp_filename_ = value;
}
else if (name == "--plugin") {
if (plugin_prefix_.empty()) {
cerr << "This compiler does not support plugins." << endl;
return false;
}
加黑部分为解析开关

之后在头文件中添加声明代码:

// Time stamp function
void ReadTimeStampFile( const string& timestampfile );

void WriteTimeStampFile( const string& timestampfile );

bool NeedGenerate( const std::string& filename );

void CheckFileStamp( const string& timestampfile );

typedef std::map time_stamp_map; // proto file name as key, timestamp as value
time_stamp_map time_stamp_map_;
string time_stamp_filename_;

此文来自战魂小筑