[英]Preprocessor Timestamp
Is it possible to generate an embedded Unix timestamp via a preprocessor macro?是否可以通过预处理器宏生成嵌入式 Unix 时间戳?
For instance: #define VERSION_EXPIRE __TIMESTAMP__
例如: #define VERSION_EXPIRE __TIMESTAMP__
The reason for this is, that i have beta versions and i want to generate an expire timestamp on compile time (in a special build configuration).这样做的原因是,我有 beta 版本,我想在编译时生成一个过期时间戳(在特殊的构建配置中)。
I've solved it as follows:我已经解决了它如下:
#define VERSION_TIMESTAMP __DATE__" "__TIME__"\x0"
In some other class在其他一些班级
+ (NSDate *)versionExpiresInDays:(NSUInteger)days {
NSString *dateString = [NSString stringWithUTF8String:VERSION_TIMESTAMP];
NSLocale *enLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSDate *compiledOn = [NSDate dateWithNaturalLanguageString:dateString locale:enLocale];
return [compiledOn dateByAddingTimeInterval:days*24*60*60];
}
If you'd use versioning software like svn
or git
you may have automatic replacement of strings like $Id: $
or $Date: $
by the id or date of the particular version of the file (svn) or of the "HEAD" release (git).如果您使用svn
或git
类的版本控制软件,您可能会自动替换$Id: $
或$Date: $
类的字符串,其中包含特定版本的文件 (svn) 或“HEAD”版本的 id 或日期(吉特)。
Edit: For git
you can extract the sources编辑:对于git
您可以提取源
git archive --format=zip -9 -o project.zip HEAD file1 file2...
To replace certain strings during that process you have to tell git in .gitattributes
that you want to have things substituted:要在该过程中替换某些字符串,您必须在.gitattributes
中告诉 git 您想要替换的内容:
file* export-subst
For the syntax of what and how terms between "$...$", please refer to the formats in the man page of git-log
.关于 "$...$" 之间的 what 和 how 术语的语法,请参考git-log
手册页中的格式。 Just as examples I have in my code就像我在代码中的例子
#define P99_VERSION_DATE "$Format:%cd$"
#define P99_VERSION_ID "$Format:%H$"
Which in the distribution version of the file is文件的分发版本中的哪个是
#define P99_VERSION_DATE "Thu Oct 7 23:38:43 2010 +0200"
#define P99_VERSION_ID "6f9740a6808ff50f42d24bb7b5234a904f84e6fe"
Add a custom build step before preprocessing that uses sed to replace __TIMESTAMP__
with date
.在使用 sed 将__TIMESTAMP__
替换为date
预处理之前添加自定义构建步骤。 The easiest way to do this is to tell Xcode to use a makefile .最简单的方法是告诉 Xcode 使用 makefile 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.