Gerrit_plugins: Add support for VERSION file
Currently plugin version is always retrieved from underlying Git
repository with git describe command. Add support for VERSION file
in case the Git repository doesn't exist yet, or plugin authors
prefer to expose their plugin version through VERSION file (as
Gerrit itself).
Format of VERSION file is the same as for Gerrit core: it must be
valid python file, that is sourced by BUCK and include
PLUGIN_VERSION = 42
Change-Id: Iba511a9fcf16b4324d7ba2cd4c131d89b564582c
diff --git a/gerrit_plugin.bucklet b/gerrit_plugin.bucklet
index e27acb8..0e7fc32 100644
--- a/gerrit_plugin.bucklet
+++ b/gerrit_plugin.bucklet
@@ -62,7 +62,15 @@
type = 'plugin',
visibility = ['PUBLIC']):
from multiprocessing import cpu_count
- mf_cmd = 'v=$(git describe --always HEAD) && '
+ from os import path
+ ROOT = get_base_path()
+ if path.exists(path.join(ROOT, 'VERSION')):
+ include_defs('//' + path.join(ROOT, 'VERSION'))
+ mf_cmd = 'v=%s && ' % PLUGIN_VERSION
+ elif path.exists(path.join(ROOT, '.git')):
+ mf_cmd = 'v=$(git describe --always HEAD) && '
+ else: # cannot retrieve plugin version, guessing '1.0'
+ mf_cmd = 'v=1.0 && '
mf_cmd += 'echo "Manifest-Version: 1.0" >$OUT && '
mf_cmd += 'echo "Gerrit-ApiType: %s" >>$OUT && ' % type
mf_cmd += 'echo "Implementation-Version: $v" >>$OUT && '