#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys
from utils import commit
from utils import mojo_root_dir
from utils import system

dirs_to_clone = [
  "mojo/edk",
  "mojo/public",
  "mojo/services/public",
  "mojo/services/accessibility/public",
  "mojo/services/clipboard/public",
  "mojo/services/content_handler/public",
  "mojo/services/geometry/public",
  "mojo/services/gpu/public",
  "mojo/services/input_events/public",
  "mojo/services/native_viewport/public",
  "mojo/services/navigation/public",
  "mojo/services/network/public",
  "mojo/services/surfaces/public",
  "mojo/services/view_manager/public",
  "mojo/services/window_manager/public",
]

def rev(source_dir, chromium_dir):
  src_commit = system(["git", "show-ref", "HEAD", "-s"], cwd=source_dir).strip()

  for d in dirs_to_clone:
    if os.path.exists(os.path.join(chromium_dir, d)):
      print "removing directory %s" % d
      system(["git", "rm", "-r", d], cwd=chromium_dir)
    print "cloning directory %s" % d
    files = system(["git", "ls-files", d], cwd=source_dir)
    for f in files.splitlines():
      # Don't copy presubmit files over since the code is read-only on the
      # chromium side.
      if os.path.basename(f) == "PRESUBMIT.py":
        continue
      dest_path = os.path.join(chromium_dir, f)
      system(["mkdir", "-p", os.path.dirname(dest_path)])
      system(["cp", os.path.join(source_dir, f), dest_path])
    os.chdir(chromium_dir)
    system(["git", "add", d], cwd=chromium_dir)

  with open("mojo/public/VERSION", "w") as version_file:
    version_file.write(src_commit)
  system(["git", "add", "mojo/public/VERSION"], cwd=chromium_dir)
  commit("Update mojo sdk to rev " + src_commit, cwd=chromium_dir)

if len(sys.argv) != 2:
  print "usage: rev_sdk.py <chromium source dir>"
  sys.exit(1)

rev(mojo_root_dir, sys.argv[1])

#!/usr/bin/env python
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os
import sys
from utils import commit
from utils import mojo_root_dir
from utils import system

dirs_to_clone = [
  "mojo/edk",
  "mojo/public",
  "mojo/services/public",
  "mojo/services/accessibility/public",
  "mojo/services/clipboard/public",
  "mojo/services/content_handler/public",
  "mojo/services/geometry/public",
  "mojo/services/gpu/public",
  "mojo/services/input_events/public",
  "mojo/services/native_viewport/public",
  "mojo/services/navigation/public",
  "mojo/services/network/public",
  "mojo/services/surfaces/public",
  "mojo/services/view_manager/public",
  "mojo/services/window_manager/public",
]

cloned_dir_prefixes = {
  "mojo/edk" : "third_party/mojo/src",
  "mojo/public" : "third_party/mojo/src",
}

def rev(source_dir, chromium_dir):
  src_commit = system(["git", "show-ref", "HEAD", "-s"], cwd=source_dir).strip()

  for input_dir in dirs_to_clone:
    prefix_in_chromium = cloned_dir_prefixes.get(input_dir, "")
    dest_dir = os.path.join(prefix_in_chromium, input_dir)
    if os.path.exists(os.path.join(chromium_dir, dest_dir)):
      print "removing directory %s" % dest_dir
      system(["git", "rm", "-r", dest_dir], cwd=chromium_dir)
    print "cloning directory %s into %s" % (input_dir, dest_dir)
    files = system(["git", "ls-files", input_dir], cwd=source_dir)
    for f in files.splitlines():
      # Don't copy presubmit files over since the code is read-only on the
      # chromium side.
      if os.path.basename(f) == "PRESUBMIT.py":
        continue
      dest_path = os.path.join(chromium_dir, prefix_in_chromium, f)
      system(["mkdir", "-p", os.path.dirname(dest_path)])
      system(["cp", os.path.join(source_dir, f), dest_path])
    os.chdir(chromium_dir)
    system(["git", "add", dest_dir], cwd=chromium_dir)

  mojo_public_dest_dir = os.path.join(cloned_dir_prefixes.get("mojo/public"),
                                      "mojo/public")
  version_filename = os.path.join(mojo_public_dest_dir, "VERSION")
  with open(version_filename, "w") as version_file:
    version_file.write(src_commit)
  system(["git", "add", version_filename], cwd=chromium_dir)
  commit("Update mojo sdk to rev " + src_commit, cwd=chromium_dir)

if len(sys.argv) != 2:
  print "usage: rev_sdk.py <chromium source dir>"
  sys.exit(1)

rev(mojo_root_dir, sys.argv[1])

Update rev_sdk.py to roll Mojo SDK/EDK into their new Chromium locations