Przeglądaj źródła

Move reclient cache dir to gclient root to avoid wipeout on gn clean

This speeds up small builds as we will still persist the credential
cache and it will speed up all builds as we will keep the deps cache
and compiler info cache.

Bug: b/278498980
Change-Id: I2fe26395a7493c461860b34ef3f109b2147abb5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4454889
Reviewed-by: Junji Watanabe <jwata@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Ben Segall <bentekkie@google.com>
Ben Segall 2 lat temu
rodzic
commit
7a0fe8bf3c
3 zmienionych plików z 38 dodań i 3 usunięć
  1. 27 1
      reclient_helper.py
  2. 1 0
      tests/OWNERS
  3. 10 2
      tests/ninja_reclient_test.py

+ 27 - 1
reclient_helper.py

@@ -71,10 +71,36 @@ def find_ninja_out_dir(args):
   return '.'
   return '.'
 
 
 
 
+def find_cache_dir(tmp_dir):
+  """Helper to find the correct cache directory for a build.
+
+  tmp_dir should be a build specific temp directory within the out directory.
+
+  If this is called from within a gclient checkout, the cache dir will be:
+  <gclient_root>/.reproxy_cache/md5(tmp_dir)/
+  If this is not called from within a gclient checkout, the cache dir will be:
+  tmp_dir/cache
+  """
+  gclient_root = gclient_paths.FindGclientRoot(os.getcwd())
+  if gclient_root:
+    return os.path.join(gclient_root, '.reproxy_cache',
+                        hashlib.md5(tmp_dir.encode()).hexdigest())
+  return os.path.join(tmp_dir, 'cache')
+
+
 def set_reproxy_path_flags(out_dir, make_dirs=True):
 def set_reproxy_path_flags(out_dir, make_dirs=True):
   """Helper to setup the logs and cache directories for reclient.
   """Helper to setup the logs and cache directories for reclient.
 
 
   Creates the following directory structure if make_dirs is true:
   Creates the following directory structure if make_dirs is true:
+  If in a gclient checkout
+  out_dir/
+    .reproxy_tmp/
+      logs/
+  <gclient_root>
+    .reproxy_cache/
+      md5(out_dir/.reproxy_tmp)/
+
+  If not in a gclient checkout
   out_dir/
   out_dir/
     .reproxy_tmp/
     .reproxy_tmp/
       logs/
       logs/
@@ -92,7 +118,7 @@ def set_reproxy_path_flags(out_dir, make_dirs=True):
   """
   """
   tmp_dir = os.path.abspath(os.path.join(out_dir, '.reproxy_tmp'))
   tmp_dir = os.path.abspath(os.path.join(out_dir, '.reproxy_tmp'))
   log_dir = os.path.join(tmp_dir, 'logs')
   log_dir = os.path.join(tmp_dir, 'logs')
-  cache_dir = os.path.join(tmp_dir, 'cache')
+  cache_dir = find_cache_dir(tmp_dir)
   if make_dirs:
   if make_dirs:
     os.makedirs(tmp_dir, exist_ok=True)
     os.makedirs(tmp_dir, exist_ok=True)
     os.makedirs(log_dir, exist_ok=True)
     os.makedirs(log_dir, exist_ok=True)

+ 1 - 0
tests/OWNERS

@@ -2,3 +2,4 @@ per-file autoninja_test.py=brucedawson@chromium.org
 per-file autoninja_test.py=tikuta@chromium.org
 per-file autoninja_test.py=tikuta@chromium.org
 per-file ninjalog_uploader_test.py=tikuta@chromium.org
 per-file ninjalog_uploader_test.py=tikuta@chromium.org
 per-file ninja_reclient_test.py=file://BUILD_OWNERS
 per-file ninja_reclient_test.py=file://BUILD_OWNERS
+per-file ninja_reclient_test.py=file://RECLIENT_OWNERS

+ 10 - 2
tests/ninja_reclient_test.py

@@ -56,7 +56,11 @@ class NinjaReclientTest(trial_dir.TestCase):
         os.path.isdir(os.path.join(self.root_dir, "out", "a", ".reproxy_tmp")))
         os.path.isdir(os.path.join(self.root_dir, "out", "a", ".reproxy_tmp")))
     self.assertTrue(
     self.assertTrue(
         os.path.isdir(
         os.path.isdir(
-            os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "cache")))
+            os.path.join(
+                self.root_dir, ".reproxy_cache",
+                hashlib.md5(
+                    os.path.join(self.root_dir, "out", "a",
+                                 ".reproxy_tmp").encode()).hexdigest())))
     self.assertTrue(
     self.assertTrue(
         os.path.isdir(
         os.path.isdir(
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs")))
             os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs")))
@@ -68,7 +72,11 @@ class NinjaReclientTest(trial_dir.TestCase):
         os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
         os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "logs"))
     self.assertEqual(
     self.assertEqual(
         os.environ.get('RBE_cache_dir'),
         os.environ.get('RBE_cache_dir'),
-        os.path.join(self.root_dir, "out", "a", ".reproxy_tmp", "cache"))
+        os.path.join(
+            self.root_dir, ".reproxy_cache",
+            hashlib.md5(
+                os.path.join(self.root_dir, "out", "a",
+                             ".reproxy_tmp").encode()).hexdigest()))
     if sys.platform.startswith('win'):
     if sys.platform.startswith('win'):
       self.assertEqual(
       self.assertEqual(
           os.environ.get('RBE_server_address'),
           os.environ.get('RBE_server_address'),