Bug 1483228 - [mozboot] Simplify get_state_dir()'s return value r=nalexander
authorAndrew Halberstadt <ahalberstadt@mozilla.com>
Mon, 04 Feb 2019 20:52:31 +0000
changeset 456712 205bf106e08444305d188c45b573e62cfc8b1cdc
parent 456711 59e2f15b38f535cad66e768dacce723499342f46
child 456713 c64aeee4b5e01464d7ab7f2dfd24ecb9914e51db
push id35504
push usercsabou@mozilla.com
push dateTue, 05 Feb 2019 21:57:12 +0000
treeherdermozilla-central@1e374e23c02f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1483228 - [mozboot] Simplify get_state_dir()'s return value r=nalexander mozboot.util.get_state_dir() returns a tuple of (<path>, <bool). The bool denotes whether or not the state dir came from an environment variable. But this value is only used in a single place, and is very easy to test for anyway. It's not worth the added complexity it imposes on all other consumers of this function. Let's just make this function return the path. Differential Revision: https://phabricator.services.mozilla.com/D15723
--- a/build/mach_bootstrap.py
+++ b/build/mach_bootstrap.py
@@ -259,17 +259,17 @@ def bootstrap(topsrcdir, mozilla_dir=Non
         # We don't use a sigil here because we treat all arguments as potentially relative
         # paths, so we'd like to get them back as they were specified.
         paths[mozpath.normpath(os.getcwd())] = ''
         data = gather_telemetry(command=handler.name, success=(result == 0),
                                 start_time=start_time, end_time=end_time,
                                 mach_context=context, substs=substs,
         if data:
-            telemetry_dir = os.path.join(get_state_dir()[0], 'telemetry')
+            telemetry_dir = os.path.join(get_state_dir(), 'telemetry')
             except OSError as e:
                 if e.errno != errno.EEXIST:
             outgoing_dir = os.path.join(telemetry_dir, 'outgoing')
@@ -279,33 +279,33 @@ def bootstrap(topsrcdir, mozilla_dir=Non
             with open(os.path.join(outgoing_dir, str(uuid.uuid4()) + '.json'),
                       'w') as f:
                 json.dump(data, f, sort_keys=True)
         if should_skip_telemetry_submission(handler):
             return True
-        state_dir, _ = get_state_dir()
+        state_dir = get_state_dir()
         machpath = os.path.join(instance.topsrcdir, 'mach')
         with open(os.devnull, 'wb') as devnull:
             subprocess.Popen([sys.executable, machpath, 'python',
                               os.path.join(topsrcdir, 'build',
                              stdout=devnull, stderr=devnull)
     def populate_context(context, key=None):
         if key is None:
         if key == 'state_dir':
-            state_dir, is_environ = get_state_dir()
-            if is_environ:
+            state_dir = get_state_dir()
+            if state_dir == os.environ.get('MOZBUILD_STATE_PATH'):
                 if not os.path.exists(state_dir):
                     print('Creating global state directory from environment variable: %s'
                           % state_dir)
                     os.makedirs(state_dir, mode=0o770)
                 if not os.path.exists(state_dir):
                     if not os.environ.get('MOZ_AUTOMATION'):
@@ -335,17 +335,17 @@ def bootstrap(topsrcdir, mozilla_dir=Non
     if 'MACH_MAIN_PID' not in os.environ:
         os.environ[b'MACH_MAIN_PID'] = str(os.getpid()).encode('ascii')
     driver = mach.main.Mach(os.getcwd())
     driver.populate_context_handler = populate_context
     if not driver.settings_paths:
         # default global machrc location
-        driver.settings_paths.append(get_state_dir()[0])
+        driver.settings_paths.append(get_state_dir())
     # always load local repository configuration
     for category, meta in CATEGORIES.items():
         driver.define_category(category, meta['short'], meta['long'],
     repo = resolve_repository()
--- a/python/mozboot/mozboot/bootstrap.py
+++ b/python/mozboot/mozboot/bootstrap.py
@@ -336,17 +336,17 @@ class Bootstrapper(object):
             return ''
     # The state directory code is largely duplicated from mach_bootstrap.py.
     # We can't easily import mach_bootstrap.py because the bootstrapper may
     # run in self-contained mode and only the files in this directory will
     # be available. We /could/ refactor parts of mach_bootstrap.py to be
     # part of this directory to avoid the code duplication.
     def try_to_create_state_dir(self):
-        state_dir, _ = get_state_dir()
+        state_dir = get_state_dir()
         if not os.path.exists(state_dir):
             should_create_state_dir = True
             if not self.instance.no_interactive:
                 choice = self.instance.prompt_int(
--- a/python/mozboot/mozboot/util.py
+++ b/python/mozboot/mozboot/util.py
@@ -5,18 +5,12 @@
 from __future__ import absolute_import
 import os
 def get_state_dir():
     """Obtain path to a directory to hold state.
-    Returns a tuple of the path and a bool indicating whether the
-    value came from an environment variable.
+    Returns:
+        A path to the state dir (str)
-    state_user_dir = os.path.expanduser('~/.mozbuild')
-    state_env_dir = os.environ.get('MOZBUILD_STATE_PATH')
-    if state_env_dir:
-        return state_env_dir, True
-    else:
-        return state_user_dir, False
+    return os.environ.get('MOZBUILD_STATE_PATH', os.path.expanduser('~/.mozbuild'))
--- a/python/mozbuild/mozbuild/nodeutil.py
+++ b/python/mozbuild/mozbuild/nodeutil.py
@@ -20,17 +20,17 @@ NPM_MIN_VERSION = StrictVersion("5.6.0")
 def find_node_paths():
     """ Determines the possible paths for node executables.
     Returns a list of paths, which includes the build state directory.
     # Also add in the location to which `mach bootstrap` or
     # `mach artifact toolchain` installs clang.
-    mozbuild_state_dir, _ = get_state_dir()
+    mozbuild_state_dir = get_state_dir()
     if platform.system() == "Windows":
         mozbuild_node_path = os.path.join(mozbuild_state_dir, 'node')
         mozbuild_node_path = os.path.join(mozbuild_state_dir, 'node', 'bin')
     # We still fallback to the PATH, since on OSes that don't have toolchain
     # artifacts available to download, Node may be coming from $PATH.
--- a/testing/raptor/mach_commands.py
+++ b/testing/raptor/mach_commands.py
@@ -66,17 +66,17 @@ class RaptorRunner(MozbuildObject):
         """Make sure benchmarks are linked to the proper location in the objdir.
         Benchmarks can either live in-tree or in an external repository. In the latter
         case also clone/update the repository if necessary.
         print("Updating external benchmarks from {}".format(BENCHMARK_REPOSITORY))
         # Set up the external repo
-        external_repo_path = os.path.join(get_state_dir()[0], 'performance-tests')
+        external_repo_path = os.path.join(get_state_dir(), 'performance-tests')
             subprocess.check_output(['git', '--version'])
         except Exception as ex:
             print("Git is not available! Please install git and "
                   "ensure it is included in the terminal path")
             raise ex
--- a/testing/web-platform/manifestupdate.py
+++ b/testing/web-platform/manifestupdate.py
@@ -44,17 +44,17 @@ def create_parser():
         default=True, help="Just download the manifest, don't update")
         "--config", action="store", dest="config_path", default=None,
         help="Path to wptrunner config file")
         "--rewrite-config", action="store_true", default=False,
         help="Force the local configuration to be regenerated")
-        "--cache-root", action="store", default=os.path.join(get_state_dir()[0], "cache", "wpt"),
+        "--cache-root", action="store", default=os.path.join(get_state_dir(), "cache", "wpt"),
         help="Path to use for the metadata cache")
     return p
 def ensure_kwargs(kwargs):
     _kwargs = vars(create_parser().parse_args([]))
--- a/tools/tryselect/preset.py
+++ b/tools/tryselect/preset.py
@@ -6,17 +6,17 @@ from __future__ import absolute_import, 
 import ConfigParser
 import os
 import subprocess
 from mozboot.util import get_state_dir
-CONFIG_PATH = os.path.join(get_state_dir()[0], "autotry.ini")
+CONFIG_PATH = os.path.join(get_state_dir(), "autotry.ini")
 def list_presets(section=None):
     config = ConfigParser.RawConfigParser()
     data = []
     if config.read([CONFIG_PATH]):
         sections = [section] if section else config.sections()
--- a/tools/tryselect/push.py
+++ b/tools/tryselect/push.py
@@ -40,18 +40,18 @@ ERROR please commit changes before conti
 here = os.path.abspath(os.path.dirname(__file__))
 build = MozbuildObject.from_environment(cwd=here)
 vcs = get_repository_object(build.topsrcdir)
 topsrcdir_hash = hashlib.sha256(os.path.abspath(build.topsrcdir)).hexdigest()
-history_path = os.path.join(get_state_dir()[0], 'history', topsrcdir_hash, 'try_task_configs.json')
-old_history_path = os.path.join(get_state_dir()[0], 'history', 'try_task_configs.json')
+history_path = os.path.join(get_state_dir(), 'history', topsrcdir_hash, 'try_task_configs.json')
+old_history_path = os.path.join(get_state_dir(), 'history', 'try_task_configs.json')
 def write_task_config(try_task_config):
     config_path = os.path.join(vcs.path, 'try_task_config.json')
     with open(config_path, 'w') as fh:
         json.dump(try_task_config, fh, indent=4, separators=(',', ': '), sort_keys=True)
     return config_path
--- a/tools/tryselect/selectors/coverage.py
+++ b/tools/tryselect/selectors/coverage.py
@@ -25,17 +25,17 @@ from ..cli import BaseTryParser
 from ..tasks import generate_tasks, filter_tasks_by_paths, resolve_tests_by_suite
 from ..push import push_to_try
 here = os.path.abspath(os.path.dirname(__file__))
 build = MozbuildObject.from_environment(cwd=here)
 vcs = get_repository_object(build.topsrcdir)
 root_hash = hashlib.sha256(os.path.abspath(build.topsrcdir)).hexdigest()
-cache_dir = os.path.join(get_state_dir()[0], 'cache', root_hash, 'chunk_mapping')
+cache_dir = os.path.join(get_state_dir(), 'cache', root_hash, 'chunk_mapping')
 if not os.path.isdir(cache_dir):
 CHUNK_MAPPING_FILE = os.path.join(cache_dir, 'chunk_mapping.sqlite')
 CHUNK_MAPPING_TAG_FILE = os.path.join(cache_dir, 'chunk_mapping_tag.json')
 # Maps from platform names in the chunk_mapping sqlite database to respective
 # substrings in task names.
--- a/tools/tryselect/selectors/fuzzy.py
+++ b/tools/tryselect/selectors/fuzzy.py
@@ -131,17 +131,17 @@ def fzf_bootstrap(update=False):
     The bootstrap works by cloning the fzf repository and running the included
     `install` script. If update is True, we will pull the repository and re-run
     the install script.
     fzf_bin = find_executable('fzf')
     if fzf_bin and not update:
         return fzf_bin
-    fzf_path = os.path.join(get_state_dir()[0], 'fzf')
+    fzf_path = os.path.join(get_state_dir(), 'fzf')
     if update and not os.path.isdir(fzf_path):
         print("fzf installed somewhere other than {}, please update manually".format(fzf_path))
     def get_fzf():
         return find_executable('fzf', os.path.join(fzf_path, 'bin'))
     if update:
--- a/tools/tryselect/tasks.py
+++ b/tools/tryselect/tasks.py
@@ -53,22 +53,22 @@ def invalidate(cache, root):
     if tmod > cmod:
 def generate_tasks(params, full, root):
     params = params or "project=mozilla-central"
     # Try to delete the old taskgraph cache directory.
-    old_cache_dir = os.path.join(get_state_dir()[0], 'cache', 'taskgraph')
+    old_cache_dir = os.path.join(get_state_dir(), 'cache', 'taskgraph')
     if os.path.isdir(old_cache_dir):
     root_hash = hashlib.sha256(os.path.abspath(root)).hexdigest()
-    cache_dir = os.path.join(get_state_dir()[0], 'cache', root_hash, 'taskgraph')
+    cache_dir = os.path.join(get_state_dir(), 'cache', root_hash, 'taskgraph')
     # Cleanup old cache files
     for path in glob.glob(os.path.join(cache_dir, '*_set')):
     attr = 'full_task_graph' if full else 'target_task_graph'
     cache = os.path.join(cache_dir, attr)