Remove root_dir variable from DEPS + enforce rename.

Update DEPS to no longer have the root_dir variable.
Add a script that detects if the user have a solution named
'trunk' and explains what needs to be done to change it to 'src'.

The reason for this change is that bot_update doesn't support
custom_vars in solutions and Chrome infra is trying to get
rid of them entirely in the future.

The bots are already using a solution named 'src' so they
won't run into this error during runhooks.

BUG=3534
TESTED=Ran the script with a .gclient containing a solution
named 'trunk' and one named 'src'. Also tested the presence
of the custom_vars dict and not.

R=andrew@webrtc.org, hinoka@chromium.org

Review URL: https://webrtc-codereview.appspot.com/30619004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@7405 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/DEPS b/DEPS
index 0222752..17d5d40 100644
--- a/DEPS
+++ b/DEPS
@@ -4,9 +4,6 @@
 # instead.
 
 vars = {
-  # Override root_dir in your .gclient's custom_vars to specify a custom root
-  # folder name.
-  "root_dir": "trunk",
   "extra_gyp_flag": "-Dextra_gyp_flag=0",
 
   # Use this googlecode_url variable only if there is an internal mirror for it.
@@ -20,16 +17,16 @@
 deps = {
   # When rolling gflags, also update deps/third_party/webrtc/webrtc.DEPS/DEPS
   # in Chromium's repo.
-  Var("root_dir") + "/third_party/gflags/src":
+  "src/third_party/gflags/src":
     (Var("googlecode_url") % "gflags") + "/trunk/src@84",
 
-  Var("root_dir") + "/third_party/junit/":
+  "src/third_party/junit/":
     (Var("googlecode_url") % "webrtc") + "/deps/third_party/junit@3367",
 }
 
 deps_os = {
   "win": {
-    Var("root_dir") + "/third_party/winsdk_samples/src":
+    "src/third_party/winsdk_samples/src":
       (Var("googlecode_url") % "webrtc") + "/deps/third_party/winsdk_samples_v71@3145",
   },
 }
@@ -55,17 +52,23 @@
 
 hooks = [
   {
+    # Check for legacy named top-level dir (named 'trunk').
+    "name": "check_root_dir_name",
+    "pattern": ".",
+    "action": ["python", "-u", "src/check_root_dir.py"],
+  },
+  {
     # Clone chromium and its deps.
     "name": "sync chromium",
     "pattern": ".",
-    "action": ["python", "-u", Var("root_dir") + "/sync_chromium.py",
+    "action": ["python", "-u", "src/sync_chromium.py",
                "--target-revision", Var("chromium_revision")],
   },
   {
     # Create links to shared dependencies in Chromium.
     "name": "setup_links",
     "pattern": ".",
-    "action": ["python", Var("root_dir") + "/setup_links.py"],
+    "action": ["python", "src/setup_links.py"],
   },
   {
     # Download test resources, i.e. video and audio files from Google Storage.
@@ -76,13 +79,13 @@
                "--num_threads=10",
                "--no_auth",
                "--bucket", "chromium-webrtc-resources",
-               Var("root_dir") + "/resources"],
+               "src/resources"],
   },
   {
     # A change to a .gyp, .gypi, or to GYP itself should run the generator.
     "name": "gyp",
     "pattern": ".",
-    "action": ["python", Var("root_dir") + "/webrtc/build/gyp_webrtc",
+    "action": ["python", "src/webrtc/build/gyp_webrtc",
                Var("extra_gyp_flag")],
   },
 ]
diff --git a/check_root_dir.py b/check_root_dir.py
new file mode 100755
index 0000000..57a6e6d
--- /dev/null
+++ b/check_root_dir.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+"""Checks for legacy root directory and instructs the user how to upgrade."""
+
+import os
+import sys
+
+SOLUTION_ROOT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                 os.pardir)
+MESSAGE = """\
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+                      A C T I O N     R E Q I R E D
+@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
+
+It looks like you have a legacy checkout where the solution's top-level
+directory is named 'trunk'. From now on, it must be named 'src'.
+
+What you need to do is to:
+
+1. Edit your .gclient file and change the solution name from 'trunk' to 'src'
+2. Rename your 'trunk' directory to 'src'
+3. Re-run gclient sync (or gclient runhooks)"""
+
+
+def main():
+  gclient_filename = os.path.join(SOLUTION_ROOT_DIR, '.gclient')
+  config_dict = {}
+  try:
+    with open(gclient_filename, 'rb') as gclient_file:
+      exec(gclient_file, config_dict)
+    for solution in config_dict.get('solutions', []):
+      if solution['name'] == 'trunk':
+        print MESSAGE
+        if solution.get('custom_vars', {}).get('root_dir'):
+          print ('4. Optional: Remove your "root_dir" entry from the '
+                 'custom_vars dictionary of the solution.')
+
+        # Remove the gclient cache file to avoid an error on the next sync.
+        entries_file = os.path.join(SOLUTION_ROOT_DIR, '.gclient_entries')
+        if os.path.exists(entries_file):
+          os.unlink(entries_file)
+        return 1
+    return 0
+  except Exception as e:
+    print >> sys.stderr, "Error while parsing .gclient: ", e
+    return 1
+
+
+if __name__ == '__main__':
+  sys.exit(main())