bzr version-info for C/C++
Lalo Martins
lalo.martins at gmail.com
Thu Oct 4 20:12:43 BST 2007
Also spracht Lukáš Lalinský (Thu, 04 Oct 2007
17:54:45 +0200):
> Here is a simple plugin that exports the basic info as preprocessor
> macros. I haven't implemented --include-history and
> --include-file-revisions, because I'm not sure what would be the best
> structure for it. If somebody has an idea, I can add it and make a patch
> against bzr from it.
In the spirit of free software :-) I think this would look better (and
run marginally faster, but that's not important) with dict interpolation.
--- cut ---
from bzrlib.version_info_formats import (
create_date_str,
VersionInfoBuilder,
register_builder,
)
_c_version_template = '''\
/* This file is automatitally generated by "bzr version-info"
It uses the current working tree to determine the revision.
So don't edit it.
*/
#define VERSION_INFO_BRANCH_NICK "%(branch_nick)s"
#define VERSION_INFO_BUILD_DATE "%(build_date)s"
#define VERSION_INFO_DATE "%(date)s"
#define VERSION_INFO_REVNO %(revno)d
#define VERSION_INFO_REVISION_ID "%(revision_id)s"
#define VERSION_INFO_CLEAN %(clean)d
'''
def encode_str(val):
return val.replace('"', '\"')
class CVersionInfoBuilder(VersionInfoBuilder):
"""Create a version file which is a C source module."""
def generate(self, to_file):
info = {
'build_date': encode_str(create_date_str()),
'revno': None,
'revision_id': None,
'branch_nick': encode_str(self._branch.nick),
'clean': -1,
'date': None
}
revision_id = self._get_revision_id()
if revision_id is None:
info['revno'] = 0
else:
info['revno'] = self._branch.revision_id_to_revno(revision_id)
info['revision_id'] = encode_str(revision_id)
rev = self._branch.repository.get_revision(revision_id)
info['date'] = encode_str(create_date_str(rev.timestamp,
rev.timezone))
if self._check or self._include_file_revs:
self._extract_file_revisions()
if self._check:
if self._clean:
info['clean'] = 1
else:
info['clean'] = 0
to_file.write(_c_version_template % info)
if self._include_history:
to_file.write('/* revisions not implemented */\n\n')
else:
to_file.write('/* revisions not implemented */\n\n')
if self._include_file_revs:
to_file.write('/* file_revisions not implemented */\n\n')
else:
to_file.write('/* file_revisions not implemented */\n\n')
register_builder('c',
'bzrlib.plugins.version_info_format_c',
'CVersionInfoBuilder')
--- cut ---
best,
Lalo Martins
--
So many of our dreams at first seem impossible,
then they seem improbable, and then, when we
summon the will, they soon become inevitable.
-----
personal: http://lalo.hystericalraisins.net/
technical: http://www.hystericalraisins.net/
GNU: never give up freedom http://www.gnu.org/
More information about the bazaar
mailing list