import gclient_utils
import os

path = gclient_utils.FindGclientRoot(os.getcwd())
execfile(os.path.join(path, 'src', 'dart', 'tools', 'deps', 'dartium.deps', 'DEPS.chromium')) # Include proper Chromium DEPS.

# Now we need to override some settings and add some new ones.

vars.update({
  "chromium_url": "http://src.chromium.org/svn",
  "dartium_base": "http://src.chromium.org",
  "dartium_chromium_branch": "master",
  "dartium_chromium_commit": "62a7524d4f71c9e0858d24b0aa1bbff3a2d09bff",
  "chromium_base_revision": "297060",
  "dartium_webkit_branch": "/blink/branches/dart/2171_3/dartium",
  "dartium_webkit_revision": "199763",

  "args_tag": "@0.13.0",
  "barback_rev" : "@29ee90dbcf77cfd64632fa2797a4c8a4f29a4b51",
  "charcode_tag": "@1.1.0",
  "collection_rev": "@1da9a07f32efa2ba0c391b289e2037391e31da0e",
  "crypto_rev" : "@2df57a1e26dd88e8d0614207d4b062c73209917d",
  "csslib_tag" : "@0.12.0",
  "glob_rev": "@704cf75e4f26b417505c5c611bdaacd8808467dd",
  "html_tag" : "@0.12.1+1",
  "http_rev" : "@9b93e1542c753090c50b46ef1592d44bc858bfe7",
  "http_multi_server_tag" : "@1.3.2",
  "http_parser_rev" : "@8b179e36aba985208e4c5fb15cfddd386b6370a4",
  "http_throttle_rev" : "@a81f08be942cdd608883c7b67795c12226abc235",
  "json_rpc_2_rev": "@a38eefd116d910199de205f962af92fed87c164c",
  "logging_rev": "@85d83e002670545e9039ad3985f0018ab640e597",
  "matcher_tag": "@0.12.0",
  "mime_rev": "@75890811d4af5af080351ba8a2853ad4c8df98dd",
  "metatest_rev": "@e5aa8e4e19fc4188ac2f6d38368a47d8f07c3df1",
  "oauth2_rev": "@1bff41f4d54505c36f2d1a001b83b8b745c452f5",
  "observatory_pub_packages_rev": "@cdc4b3d4c15b9c0c8e7702dff127b440afbb7485",
  "package_config_tag": "@0.1.3",
  "path_rev": "@b657c0854d1cf41c014986fa9d2321f1173df805",
  "plugin_tag": "@0.1.0",
  "pool_rev": "@22e12aeb16ad0b626900dbe79e4a25391ddfb28c",
  "pub_rev": "@9d707158fedc86fc2b02f62cdfe804902b098d9d",
  "pub_semver_tag": "@1.2.0",
  "shelf_rev": "@1e87b79b21ac5e6fa2f93576d6c06eaa65285ef4",
  "shelf_web_socket_rev": "@ff170cec2c0e4e5722cdf47c557be63b5035a602",
  "source_span_rev": "@42501132e43599a151ba6727d340e44442f86c05",
  "stack_trace_tag": "@1.2.1",
  "string_scanner_rev": "@3e7617d6f74ba382e9b6130b1cc12091d89a9bc5",
  "test_tag": "@0.12.1",
  "unittest_tag": "@0.11.6",
  "utf_rev": "@1f55027068759e2d52f2c12de6a57cce5f3c5ee6",
  "watcher_tag": "@0.9.5",
  "yaml_rev": "@563a5ffd4a800a2897b8f4dd6b19f2a370df2f2b",
  "zlib_rev": "@c3d0a6190f2f8c924a05ab6cc97b8f975bddd33f",
  "web_components_rev": "@0e636b534d9b12c9e96f841e6679398e91a986ec",

  "co19_rev": "@801",
  "fake_async_rev": "@38614",
})

def massage_deps(deps):
  for key, value in deps.items():
    if value is None: continue

    if value.startswith('/trunk'):
      deps[key] = Var("chromium_url") + value
      continue

    if value.startswith(Var("webkit_trunk")):
      path, revision = value.split('@') # and svn revision.
      path = path[len(Var("webkit_trunk")):]  # Strip WebKit repo.
      value = (Var("dartium_base") + Var("dartium_webkit_branch") + path +
               '@' + Var("dartium_webkit_revision"))
      deps[key] = value
      continue

massage_deps(deps)
for os_deps in deps_os.values():
  massage_deps(os_deps)

deps.update({
  "src":
    Var("chromium_git") + "/dart/dartium/src.git" + "@" +
        Var("dartium_chromium_commit"),

  "src/third_party/WebKit":
    Var("dartium_base") + Var("dartium_webkit_branch") + "@" +
        Var("dartium_webkit_revision"),

  # Needed to run pub.
  "src/dart/third_party/pkg/barback":
      "https://github.com/dart-lang/barback.git" + Var("barback_rev"),
  "src/dart/third_party/pkg/crypto":
      "https://github.com/dart-lang/crypto.git" + Var("crypto_rev"),
  "src/dart/third_party/pkg/csslib":
      "https://github.com/dart-lang/csslib.git" + Var("csslib_tag"),
  "src/dart/third_party/pkg/collection":
      "https://github.com/dart-lang/collection.git" + Var("collection_rev"),
  "src/dart/third_party/pkg/glob":
      "https://github.com/dart-lang/glob.git" + Var("glob_rev"),
  "src/dart/third_party/pkg/html":
      "https://github.com/dart-lang/html.git" + Var("html_tag"),
  "src/dart/third_party/pkg/json_rpc_2":
      "https://github.com/dart-lang/json_rpc_2.git" + Var("json_rpc_2_rev"),
  "src/dart/third_party/pkg/http":
      "https://github.com/dart-lang/http.git" + Var("http_rev"),
  "src/dart/third_party/pkg/http_multi_server":
      "https://github.com/dart-lang/http_multi_server.git" +
      Var("http_multi_server_tag"),
  "src/dart/third_party/pkg/http_parser":
      "https://github.com/dart-lang/http_parser.git" + Var("http_parser_rev"),
  "src/dart/third_party/pkg/http_throttle":
      "https://github.com/dart-lang/http_throttle.git" + Var("http_throttle_rev"),
  "src/dart/third_party/pkg/logging":
      "https://github.com/dart-lang/logging.git" + Var("logging_rev"),
  "src/dart/third_party/pkg/mime":
      "https://github.com/dart-lang/mime.git" + Var("mime_rev"),
  "src/dart/third_party/pkg/oauth2":
    "https://github.com/dart-lang/oauth2.git" + Var("oauth2_rev"),
  "src/dart/third_party/pkg/plugin":
      "https://github.com/dart-lang/plugin.git" + Var("plugin_tag"),
  "src/dart/third_party/pkg/pool":
      "https://github.com/dart-lang/pool.git" + Var("pool_rev"),
  "src/dart/third_party/pkg/pub":
      "https://github.com/dart-lang/pub.git" + Var("pub_rev"),
  "src/dart/third_party/pkg/pub_semver":
      "https://github.com/dart-lang/pub_semver.git" + Var("pub_semver_tag"),
  "src/dart/third_party/pkg/shelf":
      "https://github.com/dart-lang/shelf.git" + Var("shelf_rev"),
  "src/dart/third_party/pkg/shelf_web_socket":
      "https://github.com/dart-lang/shelf_web_socket.git" +
      Var("shelf_web_socket_rev"),
  "src/dart/third_party/pkg/utf":
      "https://github.com/dart-lang/utf.git" + Var("utf_rev"),
  "src/dart/third_party/pkg/watcher":
      "https://github.com/dart-lang/watcher.git" + Var("watcher_tag"),
  "src/dart/third_party/pkg/yaml":
      "https://github.com/dart-lang/yaml.git" + Var("yaml_rev"),

  "src/dart/third_party/pkg/args":
      "https://github.com/dart-lang/args.git" + Var("args_tag"),
  "src/dart/third_party/pkg/charcode":
      "https://github.com/dart-lang/charcode.git" + Var("charcode_tag"),
  "src/dart/third_party/pkg/http_parser":
      "https://github.com/dart-lang/http_parser.git" + Var("http_parser_rev"),
  "src/dart/third_party/pkg/matcher":
      "https://github.com/dart-lang/matcher.git" + Var("matcher_tag"),
  "src/dart/third_party/pkg/metatest":
      "https://github.com/dart-lang/metatest.git" + Var("metatest_rev"),
  "src/dart/third_party/observatory_pub_packages":
      "https://github.com/dart-lang/observatory_pub_packages.git"
      + Var("observatory_pub_packages_rev"),
  "src/dart/third_party/pkg/path":
      "https://github.com/dart-lang/path.git" + Var("path_rev"),
  "src/dart/third_party/pkg/package_config":
      "https://github.com/dart-lang/package_config.git" +
      Var("package_config_tag"),
  "src/dart/third_party/pkg/source_span":
      "https://github.com/dart-lang/source_span.git" + Var("source_span_rev"),
  "src/dart/third_party/pkg/stack_trace":
      "https://github.com/dart-lang/stack_trace.git" + Var("stack_trace_tag"),
  "src/dart/third_party/pkg/string_scanner":
      "https://github.com/dart-lang/string_scanner.git" +
      Var("string_scanner_rev"),
  "src/dart/third_party/pkg/test":
      "https://github.com/dart-lang/test.git" + Var("test_tag"),
  # TODO(sigmund): should be src/dart/third_party/pkg/unittest (dartbug.com/21949)
  "src/dart/pkg/unittest":
      "https://github.com/dart-lang/test.git" + Var("unittest_tag"),
  "src/dart/third_party/pkg/web_components":
      "https://github.com/dart-lang/web-components.git" +
      Var("web_components_rev"),

  "src/dart/third_party/WebCore":
    "http://dart.googlecode.com/svn/third_party/WebCore",

  "src/dart/third_party/pkg/fake_async":
    "http://dart.googlecode.com/svn/third_party/fake_async" +
    Var("fake_async_rev"),

  "src/dart/tests/co19/src": ((Var("googlecode_url") % "co19") +
    "/trunk/co19/tests/co19/src" + Var("co19_rev")),

  "src/dart/third_party/zlib":
      Var("chromium_git") + "/chromium/src/third_party/zlib.git" +
      Var("zlib_rev"),
})

deps_os['win'].update({
  "src/chrome/tools/test/reference_build/chrome_win": None
})
deps_os['mac'].update({
  "src/chrome/tools/test/reference_build/chrome_mac": None
})
deps_os['unix'].update({
  "src/chrome/tools/test/reference_build/chrome_linux": None
})

hooks[0:0] = [{
    "pattern": "dart",
    "action": ["python", "src/dart/tools/dartium/generate_dart_vm_version.py"],
  }]

hooks.append({
  # Set the revision for a lazily downloaded reference build of chromium,
  # with which to run perf tests.
  'name': 'set_reference_build',
  'pattern': '.',
  'action': ['python',
             'src/dart/tools/bots/set_reference_build_revision.py',
             Var('chromium_base_revision')],
})
hooks.append({
  # Peg the blink version number in LASTCHANGE.blink to be the upstream
  # webkit_revision number so that chrome remote devtools pulls assets from
  # the right place.
  "name": "lastchange",
  "pattern": ".",
  "action": ["python", "-c",
      "f=open('src/build/util/LASTCHANGE.blink','w'); f.write('LASTCHANGE=" +
      Var('webkit_revision') + "\\n')" ],
})
hooks.append({
  "name": "checked_in_dart_binaries",
  "pattern": ".",
  "action": [
    "download_from_google_storage",
    "--no_auth",
    "--no_resume",
    "--bucket",
    "dart-dependencies",
    "-d",
    "-r",
    "src/dart/tools/testing/bin",
  ],
})
