Remove sdks from archive path.

Looks like this works: https://ci.chromium.org/ui/p/flutter/builders/prod.shadow/Mac%20builder_cache/3/overview

Change-Id: I530c30f5f82884011d8fe7fd8c4387fd7b9c9980
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/54110
Reviewed-by: Yusuf Mohsinally <mohsinally@google.com>
Commit-Queue: Ricardo Amador <ricardoamador@google.com>
Reviewed-by: Keyong Han <keyonghan@google.com>
diff --git a/recipes/engine_v2/cache.expected/basic.json b/recipes/engine_v2/cache.expected/basic.json
index 4a0ea0f..ad4feb7 100644
--- a/recipes/engine_v2/cache.expected/basic.json
+++ b/recipes/engine_v2/cache.expected/basic.json
@@ -256,6 +256,19 @@
       "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
       "--json-output",
       "/path/to/tmp/json",
+      "rmtree",
+      "[CACHE]/builder/fake"
+    ],
+    "infra_step": true,
+    "name": "Removing path [CACHE]/builder/fake from archive"
+  },
+  {
+    "cmd": [
+      "vpython3",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
       "copy",
       "RECIPE_MODULE[recipe_engine::cas]/resources/infra.sha1",
       "/path/to/tmp/"
diff --git a/recipes/engine_v2/cache.py b/recipes/engine_v2/cache.py
index edb0cb5..0d1a5d4 100644
--- a/recipes/engine_v2/cache.py
+++ b/recipes/engine_v2/cache.py
@@ -3,12 +3,9 @@
 # found in the LICENSE file.
 
 DEPS = [
-    'flutter/cache',
-    'flutter/repo_util',
-    'recipe_engine/path',
-    'recipe_engine/properties',
-    'recipe_engine/file',
-    'recipe_engine/json',
+    'flutter/cache', 'flutter/repo_util', 'recipe_engine/path',
+    'recipe_engine/properties', 'recipe_engine/file', 'recipe_engine/json',
+    'recipe_engine/step'
 ]
 
 
@@ -25,19 +22,31 @@
   cache_root = api.properties.get('cache_root', 'CACHE')
   cache_ttl = api.properties.get('cache_ttl', 3600 * 4)
   cache_name = api.properties.get('cache_name')
+
   if api.cache.requires_refresh(cache_name):
     api.repo_util.engine_checkout(builder_root, env, env_prefixes)
     paths = [
         api.path[cache_root].join(p)
         for p in api.properties.get('cache_paths', [])
     ]
+
+    api.path.mock_add_directory(api.path['cache'].join('builder', 'fake'))
+    ignore_paths = [
+        api.path[cache_root].join(p)
+        for p in api.properties.get('ignore_cache_paths', [])
+    ]
+
+    for p in ignore_paths:
+      if api.path.exists(p):
+        api.file.rmtree(f'Removing path {p} from archive', p)
+
     api.cache.write(cache_name, paths, cache_ttl)
 
 
 def GenTests(api):
   yield api.test(
       'basic',
-      api.properties(cache_root='cache', cache_paths=['builder', 'git']),
+      api.properties(cache_root='cache', cache_paths=['builder', 'git'], ignore_cache_paths=['builder/fake']),
       api.step_data(
           'gsutil cat',
           stdout=api.json.output({}),