diff options
author | Ari Hausman-Cohen <arihc@google.com> | 2015-10-26 22:12:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-10-26 22:12:31 +0000 |
commit | f099f71bde81d4b428dd6e3210c37a012e060557 (patch) | |
tree | 4f3d83e828529577e0cf9ab41b971928e722833a | |
parent | 4e181654d757b14b40fb5b888ac9f6d634c025c7 (diff) | |
parent | e7af44c08837fa50eddc1300877f18bce08274ad (diff) | |
download | bdk-f099f71bde81d4b428dd6e3210c37a012e060557.tar.gz |
Merge "Moving build metrics into brunch product build." into mnc-brillo-dev
-rw-r--r-- | brunch/lib/commands/product/build.py | 30 | ||||
-rw-r--r-- | brunch/lib/core/config.py | 25 |
2 files changed, 55 insertions, 0 deletions
diff --git a/brunch/lib/commands/product/build.py b/brunch/lib/commands/product/build.py index 9509b17..cfbba79 100644 --- a/brunch/lib/commands/product/build.py +++ b/brunch/lib/commands/product/build.py @@ -18,10 +18,13 @@ import argparse import os +import time from cli import clicommand from core import config from core import util +from metrics.data_types import brillo_ga_hits +from metrics import send_hits class Build(clicommand.Command): """Build a product project from the current directory""" @@ -58,15 +61,42 @@ class Build(clicommand.Command): # Don't pass along the first '--' since it was meant for argparse. args.make_args.count('--') and args.make_args.remove('--') + # If user options haven't been set up yet, do so. + # TODO(arihc): move this to install script instead of here. + user_store = config.UserStore() + if not user_store.complete(): + user_store.initialize() + + envcmd = 'make' + start_time = time.time() + if args.submodule == True: print "Building submodule only . . ." ret = os.system('make -f %s/tools/bdk/build/wrap-product.mk %s ' \ 'HERE="%s" ENVCMD=mm BUILDTYPE=%s %s' % (sdk_path, no_java, os.getcwd(), args.buildtype, util.AsShellArgs(args.make_args))) + envcmd = 'mm' else: # Change to the product path and build the whole product. ret = os.system('cd %s;make -f %s/tools/bdk/build/wrap-product.mk %s BUILDTYPE=%s %s' % (args.product_path, sdk_path, no_java, args.buildtype, util.AsShellArgs(args.make_args))) + + end_time = time.time() + build_time = int(end_time - start_time) + + # Determine the envcmd for reporting purposes + for arg in args.make_args: + split_arg = arg.split('=') + if split_arg[0] == 'ENVCMD' and len(split_arg) > 1: + envcmd = split_arg[1] + + # TODO(arihc): also check for not --help, since this is what build_time > 0 + # is primarily checking for, and the wrapper runs lunch first, + # making basically all builds > 0 time. + if user_store.metrics_opt_in != '0' and ret == 0 and build_time > 0: + send_hits.SendHitAndRetries(brillo_ga_hits.BuildTiming(envcmd, + build_time)) + return util.GetExitCode(ret) diff --git a/brunch/lib/core/config.py b/brunch/lib/core/config.py index e565ede..123eede 100644 --- a/brunch/lib/core/config.py +++ b/brunch/lib/core/config.py @@ -16,6 +16,8 @@ import os import sqlite3 +import sys +import uuid import util @@ -118,6 +120,29 @@ class UserStore(Store): def __init__(self, table='user', file_path=util.USER_DB): super(UserStore, self).__init__(table, file_path) + def initialize(self, opt_in=None): + """Sets up the user store. + + Prompts the user for information when necessary. + """ + # Check for opt in + print ("To help improve the quality of this product, we collect\n" + "anonymized data on how the BDK is used. You may choose to opt out\n" + "of this collection now (by choosing 'N' at the below prompt),\n" + "or at any point in the future by running the following command:\n" + " brunch config metrics disable") + while opt_in is None: + print 'Do you want to help improve the Project Brillo BDK?' + print '(Y/n) ', + sys.stdout.flush() + choice = sys.stdin.readline().strip().upper() + if not choice or choice == 'Y': + opt_in = True + elif choice == 'N': + opt_in = False + self.metrics_opt_in = opt_in + + self.uid = str(uuid.uuid4()) class ProductStore(Store): REQUIRED_PROPS = [ 'name', 'device', 'manufacturer', \ |