From e6861b5aa6d182938676d6381f8d645cbdae45ba Mon Sep 17 00:00:00 2001 From: Ari Hausman-Cohen Date: Wed, 11 Nov 2015 16:12:25 -0800 Subject: Merging tools and core. Moved tools/bdk_root into core/util, moved tools/popen to core/popen. Also abstracted brunch location away from bdk location so that it's easier to exctract brunch as a standalone in the future. BUG: 24944997, 24873929 Change-Id: I0b95d5fc71bc751645f5c4348bada1ceca20ca4b --- brunch/lib/DESIGN.md | 4 +- brunch/lib/bsp/package.py | 2 +- brunch/lib/bsp/status.py | 5 +- brunch/lib/commands/product/build.py | 6 +-- brunch/lib/core/popen.py | 27 ++++++++++ brunch/lib/core/product.py | 4 +- brunch/lib/core/product_templates.py | 8 +-- brunch/lib/core/util.py | 13 ++++- brunch/lib/metrics/data_types/brillo_ga_hits.py | 4 +- .../lib/metrics/data_types/generalized_ga/hit.py | 6 +-- brunch/lib/tools/__init__.py | 17 ------- brunch/lib/tools/bdk_root.py | 31 ------------ brunch/lib/tools/popen.py | 27 ---------- brunch/lib/tools/setup.py | 58 ---------------------- 14 files changed, 55 insertions(+), 157 deletions(-) create mode 100644 brunch/lib/core/popen.py delete mode 100644 brunch/lib/tools/__init__.py delete mode 100644 brunch/lib/tools/bdk_root.py delete mode 100644 brunch/lib/tools/popen.py delete mode 100644 brunch/lib/tools/setup.py diff --git a/brunch/lib/DESIGN.md b/brunch/lib/DESIGN.md index a579e1e..b305a81 100644 --- a/brunch/lib/DESIGN.md +++ b/brunch/lib/DESIGN.md @@ -5,11 +5,11 @@ brunch/ lib/ # python top level package cli/ # Cli package commands/ # Sub command logic + core/ # package for general tools and setup logic productspec/ # package for product spec logic metrics/ # package for metrics bsp/ # package for bsp downloading - tools/ # package for helpers - product # package for product managment + product/ # package for product managment brunch.py # main python entry point brunch # shell script entry point diff --git a/brunch/lib/bsp/package.py b/brunch/lib/bsp/package.py index af562f2..6f9490d 100644 --- a/brunch/lib/bsp/package.py +++ b/brunch/lib/bsp/package.py @@ -26,7 +26,7 @@ import sys import uuid import status -from tools import popen +from core import popen PACKAGE_KEY_TYPE = 'package_type' PACKAGE_KEY_NAME = 'name' diff --git a/brunch/lib/bsp/status.py b/brunch/lib/bsp/status.py index d10fc8d..07fac7a 100644 --- a/brunch/lib/bsp/status.py +++ b/brunch/lib/bsp/status.py @@ -18,8 +18,7 @@ import os import package as package_types -from tools import bdk_root -from tools import popen +from core import util # Statuses should be numbered low to high, where a higher status # of a single package within a BSP dominates a lower status @@ -53,7 +52,7 @@ def CheckDeviceStatus(device_manifest): INSTALLED if the BSP has no packages. """ status = INSTALLED - install_root = bdk_root.BDKRoot() + install_root = util.GetBDKPath() for package in device_manifest["packages"]: status = max(status, package.Status(install_root)) diff --git a/brunch/lib/commands/product/build.py b/brunch/lib/commands/product/build.py index d1a856a..49016ed 100644 --- a/brunch/lib/commands/product/build.py +++ b/brunch/lib/commands/product/build.py @@ -42,7 +42,7 @@ class Build(clicommand.Command): help='Arguments to pass through to make') def Run(self, args): - sdk_path = util.GetBDKPath() + sdk_path = util.GetDevToolsPath() store = config.ProductFileStore(args.product_path) @@ -72,14 +72,14 @@ class Build(clicommand.Command): if args.submodule == True: print "Building submodule only . . ." - ret = os.system('make -f %s/tools/bdk/build/wrap-product.mk %s ' \ + ret = os.system('make -f %s/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' % + ret = os.system('cd %s;make -f %s/build/wrap-product.mk %s BUILDTYPE=%s %s' % (args.product_path, sdk_path, no_java, args.buildtype, util.AsShellArgs(args.make_args))) diff --git a/brunch/lib/core/popen.py b/brunch/lib/core/popen.py new file mode 100644 index 0000000..10b4cbe --- /dev/null +++ b/brunch/lib/core/popen.py @@ -0,0 +1,27 @@ +# +# Copyright (C) 2015 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""Popen wrapper object.""" + +import subprocess + +class Popener(object): + """A wrapper class for Popen.""" + + def PopenPiped(self, args): + """A wrapper around Popen with stdout/stderr pipes.""" + return subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) diff --git a/brunch/lib/core/product.py b/brunch/lib/core/product.py index 1e64e78..88333a7 100644 --- a/brunch/lib/core/product.py +++ b/brunch/lib/core/product.py @@ -142,7 +142,9 @@ class Environment(object): """Generates a file which will run brunch product envsetup""" bdk_path = util.GetBDKPath() bdk_version = util.GetBDKVersion() + tools_path = util.GetDevToolsPath() with open(os.path.join(self._product_dir, 'envsetup.sh'), 'w') as f: f.write(product_templates.ENVSETUP.substitute( self._config.dict(), bdk_path=bdk_path, - product_path=self._product_dir)) + product_path=self._product_dir, + tools_path=tools_path)) diff --git a/brunch/lib/core/product_templates.py b/brunch/lib/core/product_templates.py index 27df9bc..0f46a27 100644 --- a/brunch/lib/core/product_templates.py +++ b/brunch/lib/core/product_templates.py @@ -110,10 +110,9 @@ ENVSETUP = string.Template("""\ _envsetup_load() { # Allow the environment to override the BDK path. local bdk="$${BDK_PATH:-${bdk_path}}" - if ! test -x "$${bdk}/tools/bdk/brunch/brunch"; then + if ! test -e "$${bdk}/build/core/main.mk"; then echo "The BDK cannot be found." 1>&2 - echo "Please supply its path in the BDK_PATH environment variable or " 1>&2 - echo "run 'brunch product reconfig'" 1>&2 + echo "Please supply its path in the BDK_PATH environment variable." 1>&2 return 1 fi @@ -137,9 +136,10 @@ _envsetup_load() { fi # Find a free file descriptor and use it rather than a tempfile. + local bdk_tools="$${BDK_TOOLS_PATH:-${tools_path}}" fd=$$((`ls /dev/fd/ | sort -n | tail -1` + 1)) eval 'exec '$$fd'<