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 REPOSITORIES = [ [""], |
| 15 ["testing", "gtest"], |
| 16 ["third_party", "jinja2"], |
| 17 ["third_party", "markupsafe"] ] |
| 18 |
| 19 DELETE_FROM_GITIGNORE = [ "/base", |
| 20 "/testing/gtest" ] |
| 21 |
| 22 ADD_TO_GITIGNORE = [ "/testing/gtest/*", |
| 23 "!/testing/gtest/include", |
| 24 "/testing/gtest/include/*", |
| 25 "!/testing/gtest/include/gtest", |
| 26 "/testing/gtest/include/gtest/*", |
| 27 "!/testing/gtest/include/gtest/gtest_prod.h", |
| 28 "!/third_party/jinja2", |
| 29 "!/third_party/markupsafe" ] |
| 30 |
| 31 def RunGclient(path): |
| 32 assert os.path.isdir(path) |
| 33 print ">> Running gclient sync" |
| 34 subprocess.call("gclient sync --nohooks", cwd=path, shell=True) |
| 35 |
| 36 def UninitGit(path): |
| 37 target = os.path.join(path, ".git") |
| 38 if os.path.isdir(target): |
| 39 print ">> Cleaning up %s" % path |
| 40 shutil.rmtree(target) |
| 41 |
| 42 def UpdateTarget(repository, options): |
| 43 source = os.path.join(options.v8_path, *repository) |
| 44 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) |
| 45 print ">> Updating target directory %s" % target |
| 46 print ">> from active branch at %s" % source |
| 47 # Remove possible remnants of previous incomplete runs. |
| 48 UninitGit(target) |
| 49 |
| 50 git_commands = [ |
| 51 "git init", # initialize target repo |
| 52 "git remote add origin %s" % source, # point to the source repo |
| 53 "git fetch origin HEAD", # sync to the current branch |
| 54 "git reset --hard FETCH_HEAD", # reset to the current branch |
| 55 "git clean -fd" # delete removed files |
| 56 ] |
| 57 try: |
| 58 for command in git_commands: |
| 59 subprocess.call(command, cwd=target, shell=True) |
| 60 except: |
| 61 raise |
| 62 finally: |
| 63 UninitGit(target) |
| 64 print |
| 65 |
| 66 def UpdateGitIgnore(options): |
| 67 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") |
| 68 assert os.path.isfile(file_name) |
| 69 print ">> Updating .gitignore with lines" |
| 70 with open(file_name) as gitignore: |
| 71 content = gitignore.readlines() |
| 72 content = [x.strip() for x in content] |
| 73 for x in DELETE_FROM_GITIGNORE: |
| 74 if x in content: |
| 75 print "- %s" % x |
| 76 content.remove(x) |
| 77 for x in ADD_TO_GITIGNORE: |
| 78 if x not in content: |
| 79 print "+ %s" % x |
| 80 content.append(x) |
| 81 content.sort(key=lambda x: x[1:] if x.startswith("!") else x) |
| 82 with open(file_name, "w") as gitignore: |
| 83 for x in content: |
| 84 gitignore.write("%s\n" % x) |
| 85 |
| 86 def ParseOptions(args): |
| 87 parser = argparse.ArgumentParser(description="Update V8 in Node.js") |
| 88 parser.add_argument("v8_path", help="Path to V8 checkout") |
| 89 parser.add_argument("node_path", help="Path to Node.js checkout") |
| 90 parser.add_argument("--gclient", dest="gclient", |
| 91 action="store_true", help="Run gclient sync") |
| 92 options = parser.parse_args(args) |
| 93 assert os.path.isdir(options.v8_path) |
| 94 options.v8_path = os.path.abspath(options.v8_path) |
| 95 assert os.path.isdir(options.node_path) |
| 96 options.node_path = os.path.abspath(options.node_path) |
| 97 return options |
| 98 |
| 99 def Main(args): |
| 100 options = ParseOptions(args) |
| 101 if options.gclient: |
| 102 RunGclient(options.v8_path) |
| 103 for repo in REPOSITORIES: |
| 104 UpdateTarget(repo, options) |
| 105 UpdateGitIgnore(options) |
| 106 |
| 107 if __name__ == "__main__": |
| 108 Main(sys.argv[1:]) |
OLD | NEW |