Bug 1474869 - Move taskgraph cache files to topsrcdir/.cache. draft
authorTudor-Gabriel Vîjială <tvijiala@mozilla.com>
Thu, 02 Aug 2018 12:34:02 +0100
changeset 825866 a9a808e1fb7428fc10f0278f8648bf6575a899e1
parent 825800 bd79b07f57a34e0d8fe01bdc3f34815d77c01444
push id118192
push userbmo:tvijiala@mozilla.com
push dateThu, 02 Aug 2018 14:34:31 +0000
bugs1474869
milestone63.0a1
Bug 1474869 - Move taskgraph cache files to topsrcdir/.cache. MozReview-Commit-ID: HHpygzkD3VF
.hgignore
tools/tryselect/preset.py
tools/tryselect/tasks.py
tools/tryselect/test/setup.sh
--- a/.hgignore
+++ b/.hgignore
@@ -181,8 +181,11 @@ subinclude:servo/.hgignore
 # https://bz.mercurial-scm.org/show_bug.cgi?id=5322
 ^comm/
 
 # Ignore various raptor performance framework files
 ^testing/raptor/.raptor-venv
 ^testing/raptor/raptor-venv
 ^testing/raptor/raptor/tests/.*.json
 ^testing/raptor/webext/raptor/auto_gen_test_config.js
+
+# Ignore tryselect cache
+^.cache/
--- a/tools/tryselect/preset.py
+++ b/tools/tryselect/preset.py
@@ -3,20 +3,22 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import ConfigParser
 import os
 import subprocess
 
-from mozboot.util import get_state_dir
+from mozbuild.base import MozbuildObject
 
 
-CONFIG_PATH = os.path.join(get_state_dir()[0], "autotry.ini")
+here = os.path.abspath(os.path.dirname(__file__))
+build = MozbuildObject.from_environment(cwd=here)
+CONFIG_PATH = os.path.join(build.topsrcdir, ".cache", "autotry.ini")
 
 
 def list_presets(section=None):
     config = ConfigParser.RawConfigParser()
 
     data = []
     if config.read([CONFIG_PATH]):
         sections = [section] if section else config.sections()
@@ -58,12 +60,15 @@ def save(section, name, data):
     config = ConfigParser.RawConfigParser()
     config.read([CONFIG_PATH])
 
     if not config.has_section(section):
         config.add_section(section)
 
     config.set(section, name, data)
 
+    if not os.path.isfile(CONFIG_PATH):
+        if not os.path.isdir(os.path.dirname(CONFIG_PATH)):
+            os.makedirs(os.path.dirname(CONFIG_PATH))
     with open(CONFIG_PATH, "w") as f:
         config.write(f)
 
     print('preset saved, run with: --preset={}'.format(name))
--- a/tools/tryselect/tasks.py
+++ b/tools/tryselect/tasks.py
@@ -2,17 +2,16 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
 import os
 import sys
 
-from mozboot.util import get_state_dir
 from mozbuild.base import MozbuildObject
 from mozpack.files import FileFinder
 
 import taskgraph
 from taskgraph.generator import TaskGraphGenerator
 from taskgraph.parameters import (
     ParameterMismatch,
     load_parameters_file,
@@ -44,17 +43,17 @@ def invalidate(cache, root):
 
     if tmod > cmod:
         os.remove(cache)
 
 
 def generate_tasks(params, full, root):
     params = params or "project=mozilla-central"
 
-    cache_dir = os.path.join(get_state_dir()[0], 'cache', 'taskgraph')
+    cache_dir = os.path.join(build.topsrcdir, '.cache', 'taskgraph')
     attr = 'full_task_set' if full else 'target_task_set'
     cache = os.path.join(cache_dir, attr)
 
     invalidate(cache, root)
     if os.path.isfile(cache):
         with open(cache, 'r') as fh:
             return fh.read().splitlines()
 
--- a/tools/tryselect/test/setup.sh
+++ b/tools/tryselect/test/setup.sh
@@ -1,18 +1,19 @@
 export topsrcdir=$TESTDIR/../../../
 export MOZBUILD_STATE_PATH=$TMP/mozbuild
+mkdir -p $MOZBUILD_STATE_PATH
 
 export MACHRC=$TMP/machrc
 cat > $MACHRC << EOF
 [try]
 default=syntax
 EOF
 
-cachedir=$MOZBUILD_STATE_PATH/cache/taskgraph
+cachedir=$topsrcdir/.cache/taskgraph
 mkdir -p $cachedir
 
 cat > $cachedir/target_task_set << EOF
 test/foo-opt
 test/foo-debug
 build-baz
 EOF