aboutsummaryrefslogtreecommitdiff
path: root/compiler_wrapper/bundle.py
diff options
context:
space:
mode:
authorTobias Bosch <tbosch@google.com>2019-07-19 09:01:32 -0700
committerTobias Bosch <tbosch@google.com>2019-08-13 18:41:38 +0000
commitb30a1ed8f990b24980ca5c6ceeaedfb806c48521 (patch)
tree38d6ce5bf0b09ff26ddbace5eb718e774ff70eca /compiler_wrapper/bundle.py
parentd2067bc7aafa9b7c9b13e0c932277ea296eff86a (diff)
downloadtoolchain-utils-b30a1ed8f990b24980ca5c6ceeaedfb806c48521.tar.gz
Use static go build and allow to bundle sources.
This allows to copy the bundled sources to a ChromeOS / Android package, including the build script, and then build from there without a dependency on toolchain-utils itself. BUG=chromium:773875 TEST=unit test Change-Id: Ie9fc4bb93d556684db5fa59f4829ce257f86e023 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/1709826 Tested-by: Tobias Bosch <tbosch@google.com> Reviewed-by: George Burgess <gbiv@chromium.org>
Diffstat (limited to 'compiler_wrapper/bundle.py')
-rwxr-xr-xcompiler_wrapper/bundle.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/compiler_wrapper/bundle.py b/compiler_wrapper/bundle.py
new file mode 100755
index 00000000..44799b6f
--- /dev/null
+++ b/compiler_wrapper/bundle.py
@@ -0,0 +1,59 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+# Copyright 2019 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Build script that copies the go sources to a build destination."""
+
+from __future__ import print_function
+
+import argparse
+import os.path
+import re
+import shutil
+import subprocess
+import sys
+
+
+def parse_args():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('output_dir')
+ return parser.parse_args()
+
+
+def copy_files(input_dir, output_dir):
+ for filename in os.listdir(input_dir):
+ if ((filename.endswith('.go') and not filename.endswith('_test.go')) or
+ filename == 'build'):
+ shutil.copy(
+ os.path.join(input_dir, filename), os.path.join(output_dir, filename))
+
+
+def read_change_id():
+ last_commit_msg = subprocess.check_output(['git', 'log', '-1', '--pretty=%B'])
+ match = re.search('Change-Id: (\\w+)', last_commit_msg)
+ if not match:
+ sys.exit('Couldn\'t find Change-Id in last commit message.')
+ return match.group(1)
+
+
+def write_readme(input_dir, output_dir, change_id):
+ with open(os.path.join(input_dir, 'bundle.README'), 'r') as r, \
+ open(os.path.join(output_dir, 'README'), 'w') as w:
+ content = r.read()
+ w.write(content.format(change_id=change_id))
+
+
+def main():
+ args = parse_args()
+ change_id = read_change_id()
+ shutil.rmtree(args.output_dir, ignore_errors=True)
+ os.makedirs(args.output_dir)
+ input_dir = os.path.dirname(__file__)
+ copy_files(input_dir, args.output_dir)
+ write_readme(input_dir, args.output_dir, change_id)
+
+
+if __name__ == '__main__':
+ main()