From eb8da51256c6c464b0bd2c418070d1183d93c9af Mon Sep 17 00:00:00 2001 From: Christian Aistleitner Date: Wed, 29 Jul 2015 15:01:31 +0200 Subject: [PATCH] For plugins, run 'git describe' from their BUCK directory Thereby, we allow plugins to provide more than just one plugin (e.g.: as javamelody does), and we get correct 'git describe' output when cloning plugins under different names or more than once. Change-Id: I7afe621265b3424ef78271e3bbeeca22b2cf4cf8 --- tools/default.defs | 7 ++++++- tools/git.defs | 6 +++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/default.defs b/tools/default.defs index 1857f90f43..fd907ba4b1 100644 --- a/tools/default.defs +++ b/tools/default.defs @@ -20,6 +20,8 @@ include_defs('//tools/java_doc.defs') include_defs('//tools/java_sources.defs') include_defs('//tools/git.defs') import copy +import traceback +import os # Set defaults on java rules: # - Add AutoValue annotation processing support. @@ -131,7 +133,10 @@ def gerrit_plugin( type = 'plugin', visibility = ['PUBLIC']): from multiprocessing import cpu_count - mf_cmd = 'v=%s;' % git_describe(name) + tb = traceback.extract_stack() + calling_BUCK_file = tb[-2][0] + calling_BUCK_dir = os.path.abspath(os.path.dirname(calling_BUCK_file)) + mf_cmd = 'v=%s;' % git_describe(calling_BUCK_dir) if manifest_file: mf_src = [manifest_file] mf_cmd += 'sed "s:@VERSION@:$v:g" $SRCS >$OUT' diff --git a/tools/git.defs b/tools/git.defs index 0247e32b18..859f1730cb 100644 --- a/tools/git.defs +++ b/tools/git.defs @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -def git_describe(plugin = None): +def git_describe(directory = None): import subprocess cmd = ['git', 'describe', '--always', '--match', 'v[0-9].*', '--dirty'] - if not plugin or plugin == '${pluginName}': + if not directory: p = subprocess.Popen(cmd, stdout = subprocess.PIPE) else: - p = subprocess.Popen(cmd, stdout = subprocess.PIPE, cwd = 'plugins/%s' % plugin) + p = subprocess.Popen(cmd, stdout = subprocess.PIPE, cwd = directory) v = p.communicate()[0].strip() r = p.returncode if r != 0: