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: