From da940b12d8879f31c9b7de516818cd310accaa91 Mon Sep 17 00:00:00 2001 From: Will Drewry Date: Fri, 23 Oct 2015 09:04:07 -0700 Subject: Revert "Merge "brunch: first cut at portable product directories" into mnc-brillo-dev" The merged change was missing some local fixes. Reverting! This reverts commit 1b79007e6f03ee14d73bc88405c44bd32cf108ca, reversing changes made to 61b6b12079b8afcac153bc0f37a88a7316fea3ff. BUG=25148498 --- brunch/lib/commands/product/envsetup.py | 8 +++--- brunch/lib/commands/product/reconfig.py | 1 + brunch/lib/core/config.py | 2 +- brunch/lib/core/product.py | 17 ++++-------- brunch/lib/core/product_templates.py | 46 ++++----------------------------- 5 files changed, 15 insertions(+), 59 deletions(-) diff --git a/brunch/lib/commands/product/envsetup.py b/brunch/lib/commands/product/envsetup.py index 18dfd82..27bcbcf 100644 --- a/brunch/lib/commands/product/envsetup.py +++ b/brunch/lib/commands/product/envsetup.py @@ -37,15 +37,13 @@ class Envsetup(clicommand.Command): # TODO(wad): Add 'shell' argument to select a non-sh format. def Run(self, args): - # As product_path will end up in the shell environment, we can't - # rely on a relative path being safe for reinvocation. - product_path = os.path.abspath(args.product_path) - store = config.ProductStore(product_path) + # TODO(wad) Check version difference. + store = config.ProductStore(args.product_path) if not store.complete(): # TODO(wad) what's the best way to recover for a user here? print "Product data store is incomplete. Product must be recreated." return 1 - env = product.Environment(store, product_path) + env = product.Environment(store) if args.generate is False: print env.environment() else: diff --git a/brunch/lib/commands/product/reconfig.py b/brunch/lib/commands/product/reconfig.py index eb340c3..c0bc135 100644 --- a/brunch/lib/commands/product/reconfig.py +++ b/brunch/lib/commands/product/reconfig.py @@ -58,6 +58,7 @@ class Reconfig(clicommand.Command): if not store.buildtype: store.buildtype = 'eng' if not store.type: store.type = 'empty' + store.path = args.product_path store.bdk_version = util.GetBDKVersion() # Repopulate the envsetup.sh file. diff --git a/brunch/lib/core/config.py b/brunch/lib/core/config.py index e565ede..050924f 100644 --- a/brunch/lib/core/config.py +++ b/brunch/lib/core/config.py @@ -121,7 +121,7 @@ class UserStore(Store): class ProductStore(Store): REQUIRED_PROPS = [ 'name', 'device', 'manufacturer', \ - 'buildtype', 'bdk_version', 'type' ] + 'buildtype', 'path', 'bdk_version', 'type' ] OPTIONAL_PROPS = [ 'java' ] PREFIX = 'product_' diff --git a/brunch/lib/core/product.py b/brunch/lib/core/product.py index 7a9812c..0c9b94c 100644 --- a/brunch/lib/core/product.py +++ b/brunch/lib/core/product.py @@ -120,14 +120,10 @@ class ProductCreator(object): class Environment(object): """This class is used to generate a shell environment meant to streamline the use of the BDK while keeping it familiar to Android device developers. - - Note: None of the templates other than ENVSETUP should contain 's. If they - do, it will break during sourcing of envsetup.sh. """ - def __init__(self, config, product_dir=util.GetProductDir()): + def __init__(self, config): self._config = config - self._product_dir = product_dir def banner(self): """Return the banner to be printed after envsetup.sh is sourced""" @@ -149,17 +145,15 @@ class Environment(object): return product_templates.ENV_EXPORTS.substitute( self._config.dict(), bdk_path=bdk_path, - product_path=self._product_dir, brunch_path=os.path.join(bdk_path, 'tools', 'bdk', 'brunch'), - target_out=os.path.join(self._product_dir, 'out', + target_out=os.path.join(self._config.path, 'out', 'out-%s' % (self._config.device), 'target', 'product', self._config.device) ) def aliases(self): """Wrap brunch commands with shell functions""" - return product_templates.ENV_ALIASES.substitute( - self._config.dict(), product_path=self._product_dir) + return product_templates.ENV_ALIASES.substitute(self._config.dict()) def environment(self): """Returns a complete shell environment for product development""" @@ -169,7 +163,6 @@ class Environment(object): """Generates a file which will run brunch product envsetup""" bdk_path = util.GetBDKPath() bdk_version = util.GetBDKVersion() - with open(os.path.join(self._product_dir, 'envsetup.sh'), 'w') as f: + with open(os.path.join(self._config.path, 'envsetup.sh'), 'w') as f: f.write(product_templates.ENVSETUP.substitute( - self._config.dict(), bdk_path=bdk_path, - product_path=self._product_dir)) + self._config.dict(), bdk_path=bdk_path)) diff --git a/brunch/lib/core/product_templates.py b/brunch/lib/core/product_templates.py index d81045a..ea64286 100644 --- a/brunch/lib/core/product_templates.py +++ b/brunch/lib/core/product_templates.py @@ -124,49 +124,13 @@ provision() { """) -# Inside this template, brunch is re-called to export an updated -# environment. To do so, the output is packed into an fd and then -# source'd by the shell. The approach is messier than using <() -# in order to avoid a specific bashism and keep this part dash clean. -# That is yet to be a requirement across all the scripts, though. 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 - 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 - return 1 - fi - - # Make sure we're in the root of a product. - # If the user explicitly exported a PRODUCT_PATH, then fail if it is wrong. - if test -n "$${PRODUCT_PATH}" && \ - ! test -e "$${PRODUCT_PATH}/.brunch_product.db"; then - echo "Cannot find a product at PRODUCT_PATH: $${PRODUCT_PATH}" 1>&2 - return 1 - fi - # Otherwise, use the default or check the cwd. - local product_path="$${PRODUCT_PATH:-${product_path}}" - if ! test -e "$${product_path}/.brunch_product.db"; then - echo "Checking current directory for a valid product . . ." 1>&2 - product_path=$$PWD - if ! test -e "$${product_path}/.brunch_product.db"; then - echo "Please source envsetup.sh from the product directory " 1>&2 - echo "or set a valid PRODUCT_PATH in the environment." 1>&2 - return 1 - fi - fi - - # Find a free file descriptor and use it rather than a tempfile. - fd=$$((`ls /dev/fd/ | sort -n | tail -1` + 1)) - eval 'exec '$$fd'< "$$t" + source $$t + rm $$t } _envsetup_load """) -- cgit v1.2.3