Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright 2017 the V8 project 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. | |
| 5 | |
| 6 import argparse | |
| 7 import os | |
| 8 import shutil | |
| 9 import subprocess | |
| 10 import sys | |
| 11 | |
| 12 TARGET_SUBDIR = os.path.join("deps", "v8") | |
| 13 | |
| 14 SUB_REPOSITORIES = [ ["testing", "gtest"], | |
| 15 ["third_party", "jinja2"], | |
|
Michael Achenbach
2017/03/16 11:29:19
Why isn't base/trace_event/common added here? It's
| |
| 16 ["third_party", "markupsafe"] ] | |
| 17 | |
| 18 DELETE_FROM_GITIGNORE = [ "/base", | |
| 19 "/testing/gtest" ] | |
| 20 | |
| 21 # Node.js requires only a single header file from gtest to build V8. | |
| 22 # Both jinja2 and markupsafe are required to generate part of the inspector. | |
| 23 ADD_TO_GITIGNORE = [ "/testing/gtest/*", | |
| 24 "!/testing/gtest/include", | |
| 25 "/testing/gtest/include/*", | |
| 26 "!/testing/gtest/include/gtest", | |
| 27 "/testing/gtest/include/gtest/*", | |
| 28 "!/testing/gtest/include/gtest/gtest_prod.h", | |
| 29 "!/third_party/jinja2", | |
| 30 "!/third_party/markupsafe" ] | |
| 31 | |
| 32 def RunGclient(path): | |
| 33 assert os.path.isdir(path) | |
| 34 print ">> Running gclient sync" | |
| 35 subprocess.check_call("gclient sync --nohooks", cwd=path, shell=True) | |
| 36 | |
| 37 def UninitGit(path): | |
| 38 target = os.path.join(path, ".git") | |
| 39 if os.path.isdir(target): | |
| 40 print ">> Cleaning up %s" % path | |
| 41 shutil.rmtree(target) | |
| 42 | |
| 43 def UpdateTarget(repository, options): | |
| 44 source = os.path.join(options.v8_path, *repository) | |
| 45 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) | |
| 46 print ">> Updating target directory %s" % target | |
| 47 print ">> from active branch at %s" % source | |
| 48 if not os.path.exists(target): | |
| 49 os.makedirs(target) | |
| 50 # Remove possible remnants of previous incomplete runs. | |
| 51 UninitGit(target) | |
| 52 | |
| 53 git_commands = [ | |
| 54 "git init", # initialize target repo | |
| 55 "git remote add origin %s" % source, # point to the source repo | |
| 56 "git fetch origin HEAD", # sync to the current branch | |
| 57 "git reset --hard FETCH_HEAD", # reset to the current branch | |
| 58 "git clean -fd" # delete removed files | |
| 59 ] | |
| 60 try: | |
| 61 for command in git_commands: | |
| 62 subprocess.check_call(command, cwd=target, shell=True); | |
| 63 except: | |
| 64 raise | |
| 65 finally: | |
| 66 UninitGit(target) | |
| 67 | |
| 68 def UpdateGitIgnore(options): | |
| 69 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") | |
| 70 assert os.path.isfile(file_name) | |
| 71 print ">> Updating .gitignore with lines" | |
| 72 with open(file_name) as gitignore: | |
| 73 content = gitignore.readlines() | |
| 74 content = [x.strip() for x in content] | |
| 75 for x in DELETE_FROM_GITIGNORE: | |
| 76 if x in content: | |
| 77 print "- %s" % x | |
| 78 content.remove(x) | |
| 79 for x in ADD_TO_GITIGNORE: | |
| 80 if x not in content: | |
| 81 print "+ %s" % x | |
| 82 content.append(x) | |
| 83 content.sort(key=lambda x: x[1:] if x.startswith("!") else x) | |
| 84 with open(file_name, "w") as gitignore: | |
| 85 for x in content: | |
| 86 gitignore.write("%s\n" % x) | |
| 87 | |
| 88 def ParseOptions(args): | |
| 89 parser = argparse.ArgumentParser(description="Update V8 in Node.js") | |
| 90 parser.add_argument("v8_path", help="Path to V8 checkout") | |
| 91 parser.add_argument("node_path", help="Path to Node.js checkout") | |
| 92 parser.add_argument("--gclient", dest="gclient", | |
| 93 action="store_true", help="Run gclient sync") | |
| 94 options = parser.parse_args(args) | |
| 95 assert os.path.isdir(options.v8_path) | |
| 96 options.v8_path = os.path.abspath(options.v8_path) | |
| 97 assert os.path.isdir(options.node_path) | |
| 98 options.node_path = os.path.abspath(options.node_path) | |
| 99 return options | |
| 100 | |
| 101 def Main(args): | |
| 102 options = ParseOptions(args) | |
| 103 if options.gclient: | |
| 104 RunGclient(options.v8_path) | |
| 105 # Update main V8 repository. | |
| 106 UpdateTarget([""], options) | |
| 107 # Patch .gitignore before updating sub-repositories. | |
| 108 UpdateGitIgnore(options) | |
| 109 for repo in SUB_REPOSITORIES: | |
| 110 UpdateTarget(repo, options) | |
| 111 | |
| 112 if __name__ == "__main__": | |
| 113 Main(sys.argv[1:]) | |
| OLD | NEW |