aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcompiler_wrapper/build.py15
-rwxr-xr-xcompiler_wrapper/bundle.py7
2 files changed, 17 insertions, 5 deletions
diff --git a/compiler_wrapper/build.py b/compiler_wrapper/build.py
index af3064e9..6b647714 100755
--- a/compiler_wrapper/build.py
+++ b/compiler_wrapper/build.py
@@ -10,6 +10,7 @@ from __future__ import print_function
import argparse
import os.path
+import re
import subprocess
import sys
@@ -45,8 +46,18 @@ def calc_go_args(args, version):
def read_version(build_dir):
- with open(os.path.join(build_dir, 'VERSION'), 'r') as r:
- return r.read()
+ version_path = os.path.join(build_dir, 'VERSION')
+ if os.path.exists(version_path):
+ with open(version_path, 'r') as r:
+ return r.read()
+
+ last_commit_msg = subprocess.check_output(
+ ['git', '-C', build_dir, 'log', '-1', '--pretty=%B'])
+ # Use last found change id to support reverts as well.
+ change_ids = re.findall(r'Change-Id: (\w+)', last_commit_msg)
+ if not change_ids:
+ sys.exit("Couldn't find Change-Id in last commit message.")
+ return change_ids[-1]
def main():
diff --git a/compiler_wrapper/bundle.py b/compiler_wrapper/bundle.py
index 63757f78..c1fa53e0 100755
--- a/compiler_wrapper/bundle.py
+++ b/compiler_wrapper/bundle.py
@@ -33,10 +33,11 @@ def copy_files(input_dir, output_dir):
def read_change_id(input_dir):
last_commit_msg = subprocess.check_output(
['git', '-C', input_dir, 'log', '-1', '--pretty=%B'])
- match = re.search('Change-Id: (\\w+)', last_commit_msg)
- if not match:
+ # Use last found change id to support reverts as well.
+ change_ids = re.findall(r'Change-Id: (\w+)', last_commit_msg)
+ if not change_ids:
sys.exit("Couldn't find Change-Id in last commit message.")
- return match.group(1)
+ return change_ids[-1]
def write_readme(input_dir, output_dir, change_id):