Use "= delete" for DISALLOW_COPY and DISALLOW_ASSIGN.
[chromium-blink-merge.git] / mojo / tools / rev_sdk.py
blob15812c5a7464a4678111fa66c9675d0905d7c62c
1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Tool to roll Mojo into Chromium. See:
7 https://github.com/domokit/mojo/wiki/Rolling-code-between-chromium-and-mojo#mojo---chromium-updates-sdk--edk
8 """
10 import os
11 import sys
12 from utils import commit
13 from utils import chromium_root_dir
14 from utils import system
16 sdk_prefix_in_chromium = "third_party/mojo/src"
17 sdk_dirs_to_clone = [
18 "mojo/edk",
19 "mojo/public",
20 "nacl_bindings",
23 sdk_dirs_to_not_clone = [
24 "mojo/public/cpp/application",
25 "mojo/public/interfaces/application",
26 "third_party/mojo/src/mojo/public/java/application",
29 # Individual files to preserve within the target repository during roll. These
30 # are relative to |sdk_prefix_in_chromium| but are not maintained in the mojo
31 # repository.
32 preserved_chromium_files = [
33 "mojo/edk/DEPS",
34 "mojo/public/DEPS",
35 "mojo/public/platform/nacl/DEPS",
36 "nacl_bindings/DEPS",
39 # A dictionary mapping dirs to clone to their destination locations in Chromium.
40 dirs_to_clone = {}
42 for sdk_dir in sdk_dirs_to_clone:
43 sdk_dir_in_chromium = os.path.join(sdk_prefix_in_chromium, sdk_dir)
44 dirs_to_clone[sdk_dir] = sdk_dir_in_chromium
46 def rev(source_dir, chromium_dir):
47 src_commit = system(["git", "show-ref", "HEAD", "-s"], cwd=source_dir).strip()
49 for input_dir, dest_dir in dirs_to_clone.iteritems():
50 if os.path.exists(os.path.join(chromium_dir, dest_dir)):
51 print "removing directory %s" % dest_dir
52 system(["git", "rm", "-r", dest_dir], cwd=chromium_dir)
53 print "cloning directory %s into %s" % (input_dir, dest_dir)
54 files = system(["git", "ls-files", input_dir], cwd=source_dir)
55 for f in files.splitlines():
56 # Don't copy presubmit files over since the code is read-only on the
57 # chromium side.
58 if os.path.basename(f) == "PRESUBMIT.py":
59 continue
61 exclude = False
62 for excluded in sdk_dirs_to_not_clone:
63 if f.startswith(excluded):
64 exclude = True
65 break
66 if exclude:
67 continue
69 # Clone |f| into Chromium under |dest_dir| at its location relative to
70 # |input_dir|.
71 f_relpath = os.path.relpath(f, input_dir)
72 dest_path = os.path.join(chromium_dir, dest_dir, f_relpath)
73 system(["mkdir", "-p", os.path.dirname(dest_path)])
74 system(["cp", os.path.join(source_dir, f), dest_path])
75 os.chdir(chromium_dir)
76 system(["git", "add", dest_dir], cwd=chromium_dir)
78 mojo_public_dest_dir = os.path.join(sdk_prefix_in_chromium, "mojo/public")
79 version_filename = os.path.join(mojo_public_dest_dir, "VERSION")
80 with open(version_filename, "w") as version_file:
81 version_file.write(src_commit)
82 system(["git", "add", version_filename], cwd=chromium_dir)
84 # Reset preserved files that were blown away.
85 for rel_path in preserved_chromium_files:
86 preserved_path = os.path.join(sdk_prefix_in_chromium, rel_path)
87 system(["git", "reset", "--", preserved_path])
88 system(["git", "checkout", preserved_path])
90 commit("Update mojo sdk to rev " + src_commit, cwd=chromium_dir)
92 if len(sys.argv) != 2:
93 print "usage: rev_sdk.py <mojo source dir>"
94 sys.exit(1)
96 rev(sys.argv[1], chromium_root_dir)