Run dartfmt when invoking git cl format.

If the repository has third_party/dart-sdk/ unpacked, use that to
format dart files modified in the current patch.

BUG=459376
R=maruel@chromium.org, zra@google.com

Review URL: https://codereview.chromium.org/933383002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294179 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 96989a9..f80cd78 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -662,15 +662,8 @@
   raise Error('Unknown platform: ' + sys.platform)
 
 
-def GetBuildtoolsPath():
-  """Returns the full path to the buildtools directory.
-  This is based on the root of the checkout containing the current directory."""
-
-  # Overriding the build tools path by environment is highly unsupported and may
-  # break without warning.  Do not rely on this for anything important.
-  override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
-  if override is not None:
-    return override
+def GetPrimarySolutionPath():
+  """Returns the full path to the primary solution. (gclient_root + src)"""
 
   gclient_root = FindGclientRoot(os.getcwd())
   if not gclient_root:
@@ -691,9 +684,24 @@
 
   # Some projects' top directory is not named 'src'.
   source_dir_name = GetGClientPrimarySolutionName(gclient_root) or 'src'
-  buildtools_path = os.path.join(gclient_root, source_dir_name, 'buildtools')
+  return os.path.join(gclient_root, source_dir_name)
+
+
+def GetBuildtoolsPath():
+  """Returns the full path to the buildtools directory.
+  This is based on the root of the checkout containing the current directory."""
+
+  # Overriding the build tools path by environment is highly unsupported and may
+  # break without warning.  Do not rely on this for anything important.
+  override = os.environ.get('CHROMIUM_BUILDTOOLS_PATH')
+  if override is not None:
+    return override
+
+  primary_solution = GetPrimarySolutionPath()
+  buildtools_path = os.path.join(primary_solution, 'buildtools')
   if not os.path.exists(buildtools_path):
     # Buildtools may be in the gclient root.
+    gclient_root = FindGclientRoot(os.getcwd())
     buildtools_path = os.path.join(gclient_root, 'buildtools')
   return buildtools_path