Install dependencies on generators installation.

Generators require additional dependencies. An example is jazzy for
generating objective c docs.

Bug: https://github.com/flutter/flutter/issues/81855
Change-Id: Iadd183e5c76a076006b4218c3293924770b87a60
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/32501
Commit-Queue: Godofredo Contreras <godofredoc@google.com>
Reviewed-by: Ricardo Amador <ricardoamador@google.com>
diff --git a/recipes/engine_v2/engine_v2.expected/basic_linux.json b/recipes/engine_v2/engine_v2.expected/basic_linux.json
index 096532e..8a3ccb3 100644
--- a/recipes/engine_v2/engine_v2.expected/basic_linux.json
+++ b/recipes/engine_v2/engine_v2.expected/basic_linux.json
@@ -924,6 +924,19 @@
       "[CACHE]/builder/src/out",
       "--recursive"
     ],
+    "cwd": "[CACHE]/builder",
+    "env": {
+      "ANDROID_HOME": "[CACHE]/builder/third_party/android_tools/sdk",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "ENGINE_CHECKOUT_PATH": "[CACHE]/builder",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "LUCI_WORKDIR": "[START_DIR]",
+      "OS": "linux",
+      "REVISION": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+    },
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -953,6 +966,19 @@
       "engine",
       "--engine-capture-core-dump"
     ],
+    "cwd": "[CACHE]/builder",
+    "env": {
+      "ANDROID_HOME": "[CACHE]/builder/third_party/android_tools/sdk",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "ENGINE_CHECKOUT_PATH": "[CACHE]/builder",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "LUCI_WORKDIR": "[START_DIR]",
+      "OS": "linux",
+      "REVISION": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+    },
     "luci_context": {
       "realm": {
         "name": "proj:try"
diff --git a/recipes/engine_v2/engine_v2.expected/basic_mac.json b/recipes/engine_v2/engine_v2.expected/basic_mac.json
index 6306308..65db1fc 100644
--- a/recipes/engine_v2/engine_v2.expected/basic_mac.json
+++ b/recipes/engine_v2/engine_v2.expected/basic_mac.json
@@ -1078,6 +1078,19 @@
       "[CACHE]/builder/src/out",
       "--recursive"
     ],
+    "cwd": "[CACHE]/builder",
+    "env": {
+      "ANDROID_HOME": "[CACHE]/builder/third_party/android_tools/sdk",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "ENGINE_CHECKOUT_PATH": "[CACHE]/builder",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "LUCI_WORKDIR": "[START_DIR]",
+      "OS": "darwin",
+      "REVISION": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+    },
     "infra_step": true,
     "luci_context": {
       "realm": {
@@ -1107,6 +1120,19 @@
       "engine",
       "--engine-capture-core-dump"
     ],
+    "cwd": "[CACHE]/builder",
+    "env": {
+      "ANDROID_HOME": "[CACHE]/builder/third_party/android_tools/sdk",
+      "DEPOT_TOOLS": "RECIPE_REPO[depot_tools]",
+      "ENGINE_CHECKOUT_PATH": "[CACHE]/builder",
+      "GIT_BRANCH": "",
+      "LUCI_BRANCH": "",
+      "LUCI_CI": "True",
+      "LUCI_PR": "",
+      "LUCI_WORKDIR": "[START_DIR]",
+      "OS": "darwin",
+      "REVISION": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+    },
     "luci_context": {
       "realm": {
         "name": "proj:try"
diff --git a/recipes/engine_v2/engine_v2.py b/recipes/engine_v2/engine_v2.py
index 33f427e..df38902 100644
--- a/recipes/engine_v2/engine_v2.py
+++ b/recipes/engine_v2/engine_v2.py
@@ -27,10 +27,12 @@
 DEPS = [
     'depot_tools/gsutil',
     'flutter/display_util',
+    'flutter/flutter_deps',
     'flutter/repo_util',
     'flutter/osx_sdk',
     'flutter/shard_util_v2',
     'recipe_engine/buildbucket',
+    'recipe_engine/context',
     'recipe_engine/file',
     'recipe_engine/json',
     'recipe_engine/path',
@@ -53,6 +55,7 @@
       url=api.properties.get('git_url'),
       ref=api.properties.get('git_ref')
   )
+
   # Read builds configuration from repository under test.
   config_path = checkout_path.join('ci', 'builders', '%s.json' % config_name)
   builds = api.properties.get('builds')
@@ -108,6 +111,7 @@
     clobber = api.properties.get('clobber', True)
     gclient_vars = api.shard_util_v2.unfreeze_dict(api.properties.get('gclient_variables', {}))
     env, env_prefixes = api.repo_util.engine_environment(full_engine_checkout)
+
     api.repo_util.engine_checkout(
         full_engine_checkout, env, env_prefixes, clobber,
         custom_vars=gclient_vars
@@ -123,9 +127,18 @@
           # If platform is mac we need to run the generator from an xcode context.
           if api.platform.is_mac:
             with api.osx_sdk('ios'):
-              _run_global_generator(api, generator_task, full_engine_checkout)
+              # Install dependencies from within the ios context use
+              # xcode's ruby version.
+              deps = api.properties.get('dependencies', [])
+              api.flutter_deps.required_deps(env, env_prefixes, deps)
+              with api.context(env=env, cwd=full_engine_checkout):
+                _run_global_generator(api, generator_task, full_engine_checkout)
           else:
-            _run_global_generator(api, generator_task, full_engine_checkout)
+            # Install dependencies.
+            deps = api.properties.get('dependencies', [])
+            api.flutter_deps.required_deps(env, env_prefixes, deps)
+            with api.context(env=env, cwd=full_engine_checkout):
+              _run_global_generator(api, generator_task, full_engine_checkout)
     api.file.listdir('Final List checkout', full_engine_checkout.join('src', 'out'), recursive=True)
     api.file.listdir('Final List checkout 2', full_engine_checkout.join('src', 'flutter', 'sky'), recursive=True)
   # Global archives