Bug 1474869 - Fix mach try fuzzy when using multiple source checkouts. r=ahal
MozReview-Commit-ID: Dz9EOClembh
--- a/tools/tryselect/tasks.py
+++ b/tools/tryselect/tasks.py
@@ -1,15 +1,17 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# 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 hashlib
import os
+import shutil
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
@@ -44,17 +46,23 @@ 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')
+ # Try to delete the old taskgraph cache directory.
+ old_cache_dir = os.path.join(get_state_dir()[0], 'cache', 'taskgraph')
+ if os.path.isdir(old_cache_dir):
+ shutil.rmtree(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')
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
@@ -2,17 +2,20 @@ export topsrcdir=$TESTDIR/../../../
export MOZBUILD_STATE_PATH=$TMP/mozbuild
export MACHRC=$TMP/machrc
cat > $MACHRC << EOF
[try]
default=syntax
EOF
-cachedir=$MOZBUILD_STATE_PATH/cache/taskgraph
+calculate_hash='import hashlib, os, sys
+print hashlib.sha256(os.path.abspath(sys.argv[1])).hexdigest()'
+roothash=$(python -c "$calculate_hash" "$topsrcdir")
+cachedir=$MOZBUILD_STATE_PATH/cache/$roothash/taskgraph
mkdir -p $cachedir
cat > $cachedir/target_task_set << EOF
test/foo-opt
test/foo-debug
build-baz
EOF