| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 the V8 project authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import argparse | 6 import argparse |
| 7 import os | 7 import os |
| 8 import shutil | 8 import shutil |
| 9 import subprocess | 9 import subprocess |
| 10 import sys | 10 import sys |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 "/testing/gtest/include/*", | 27 "/testing/gtest/include/*", |
| 28 "!/testing/gtest/include/gtest", | 28 "!/testing/gtest/include/gtest", |
| 29 "/testing/gtest/include/gtest/*", | 29 "/testing/gtest/include/gtest/*", |
| 30 "!/testing/gtest/include/gtest/gtest_prod.h", | 30 "!/testing/gtest/include/gtest/gtest_prod.h", |
| 31 "!/third_party/jinja2", | 31 "!/third_party/jinja2", |
| 32 "!/third_party/markupsafe" ] | 32 "!/third_party/markupsafe" ] |
| 33 | 33 |
| 34 def RunGclient(path): | 34 def RunGclient(path): |
| 35 assert os.path.isdir(path) | 35 assert os.path.isdir(path) |
| 36 print ">> Running gclient sync" | 36 print ">> Running gclient sync" |
| 37 subprocess.check_call("gclient sync --nohooks", cwd=path, shell=True) | 37 subprocess.check_call(["gclient", "sync", "--nohooks"], cwd=path) |
| 38 | 38 |
| 39 def UninitGit(path): | 39 def UninitGit(path): |
| 40 target = os.path.join(path, ".git") | 40 target = os.path.join(path, ".git") |
| 41 if os.path.isdir(target): | 41 if os.path.isdir(target): |
| 42 print ">> Cleaning up %s" % path | 42 print ">> Cleaning up %s" % path |
| 43 shutil.rmtree(target) | 43 shutil.rmtree(target) |
| 44 | 44 |
| 45 def UpdateTarget(repository, options): | 45 def UpdateTarget(repository, options): |
| 46 source = os.path.join(options.v8_path, *repository) | 46 source = os.path.join(options.v8_path, *repository) |
| 47 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) | 47 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) |
| 48 print ">> Updating target directory %s" % target | 48 print ">> Updating target directory %s" % target |
| 49 print ">> from active branch at %s" % source | 49 print ">> from active branch at %s" % source |
| 50 if not os.path.exists(target): | 50 if not os.path.exists(target): |
| 51 os.makedirs(target) | 51 os.makedirs(target) |
| 52 # Remove possible remnants of previous incomplete runs. | 52 # Remove possible remnants of previous incomplete runs. |
| 53 UninitGit(target) | 53 UninitGit(target) |
| 54 | 54 |
| 55 git_commands = [ | 55 git_commands = [ |
| 56 "git init", # initialize target repo | 56 ["git", "init"], # initialize target repo |
| 57 "git remote add origin %s" % source, # point to the source repo | 57 ["git", "remote", "add", "origin", source], # point to the source repo |
| 58 "git fetch origin HEAD", # sync to the current branch | 58 ["git", "fetch", "origin", "HEAD"], # sync to the current branch |
| 59 "git reset --hard FETCH_HEAD", # reset to the current branch | 59 ["git", "reset", "--hard", "FETCH_HEAD"], # reset to the current branch |
| 60 "git clean -fd" # delete removed files | 60 ["git", "clean", "-fd"], # delete removed files |
| 61 ] | 61 ] |
| 62 try: | 62 try: |
| 63 for command in git_commands: | 63 for command in git_commands: |
| 64 subprocess.check_call(command, cwd=target, shell=True); | 64 subprocess.check_call(command, cwd=target) |
| 65 except: | 65 except: |
| 66 raise | 66 raise |
| 67 finally: | 67 finally: |
| 68 UninitGit(target) | 68 UninitGit(target) |
| 69 | 69 |
| 70 def UpdateGitIgnore(options): | 70 def UpdateGitIgnore(options): |
| 71 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") | 71 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") |
| 72 assert os.path.isfile(file_name) | 72 assert os.path.isfile(file_name) |
| 73 print ">> Updating .gitignore with lines" | 73 print ">> Updating .gitignore with lines" |
| 74 with open(file_name) as gitignore: | 74 with open(file_name) as gitignore: |
| 75 content = gitignore.readlines() | 75 content = gitignore.readlines() |
| 76 content = [x.strip() for x in content] | 76 content = [x.strip() for x in content] |
| 77 for x in DELETE_FROM_GITIGNORE: | 77 for x in DELETE_FROM_GITIGNORE: |
| 78 if x in content: | 78 if x in content: |
| 79 print "- %s" % x | 79 print "- %s" % x |
| 80 content.remove(x) | 80 content.remove(x) |
| 81 for x in ADD_TO_GITIGNORE: | 81 for x in ADD_TO_GITIGNORE: |
| 82 if x not in content: | 82 if x not in content: |
| 83 print "+ %s" % x | 83 print "+ %s" % x |
| 84 content.append(x) | 84 content.append(x) |
| 85 content.sort(key=lambda x: x[1:] if x.startswith("!") else x) | 85 content.sort(key=lambda x: x[1:] if x.startswith("!") else x) |
| 86 with open(file_name, "w") as gitignore: | 86 with open(file_name, "w") as gitignore: |
| 87 for x in content: | 87 for x in content: |
| 88 gitignore.write("%s\n" % x) | 88 gitignore.write("%s\n" % x) |
| 89 | 89 |
| 90 def CreateCommit(options): |
| 91 print ">> Creating commit." |
| 92 # Find git hash from source. |
| 93 githash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"], |
| 94 cwd=options.v8_path).strip() |
| 95 # Create commit at target. |
| 96 git_commands = [ |
| 97 ["git", "checkout", "-b", "update_v8_to_%s" % githash], # new branch |
| 98 ["git", "add", "."], # add files |
| 99 ["git", "commit", "-m", "Update V8 to %s" % githash] # new commit |
| 100 ] |
| 101 for command in git_commands: |
| 102 subprocess.check_call(command, cwd=options.node_path) |
| 103 |
| 90 def ParseOptions(args): | 104 def ParseOptions(args): |
| 91 parser = argparse.ArgumentParser(description="Update V8 in Node.js") | 105 parser = argparse.ArgumentParser(description="Update V8 in Node.js") |
| 92 parser.add_argument("v8_path", help="Path to V8 checkout") | 106 parser.add_argument("v8_path", help="Path to V8 checkout") |
| 93 parser.add_argument("node_path", help="Path to Node.js checkout") | 107 parser.add_argument("node_path", help="Path to Node.js checkout") |
| 94 parser.add_argument("--gclient", dest="gclient", | 108 parser.add_argument("--gclient", action="store_true", help="Run gclient sync") |
| 95 action="store_true", help="Run gclient sync") | 109 parser.add_argument("--commit", action="store_true", help="Create commit") |
| 96 options = parser.parse_args(args) | 110 options = parser.parse_args(args) |
| 97 assert os.path.isdir(options.v8_path) | 111 assert os.path.isdir(options.v8_path) |
| 98 options.v8_path = os.path.abspath(options.v8_path) | 112 options.v8_path = os.path.abspath(options.v8_path) |
| 99 assert os.path.isdir(options.node_path) | 113 assert os.path.isdir(options.node_path) |
| 100 options.node_path = os.path.abspath(options.node_path) | 114 options.node_path = os.path.abspath(options.node_path) |
| 101 return options | 115 return options |
| 102 | 116 |
| 103 def Main(args): | 117 def Main(args): |
| 104 options = ParseOptions(args) | 118 options = ParseOptions(args) |
| 105 if options.gclient: | 119 if options.gclient: |
| 106 RunGclient(options.v8_path) | 120 RunGclient(options.v8_path) |
| 107 # Update main V8 repository. | 121 # Update main V8 repository. |
| 108 UpdateTarget([""], options) | 122 UpdateTarget([""], options) |
| 109 # Patch .gitignore before updating sub-repositories. | 123 # Patch .gitignore before updating sub-repositories. |
| 110 UpdateGitIgnore(options) | 124 UpdateGitIgnore(options) |
| 111 for repo in SUB_REPOSITORIES: | 125 for repo in SUB_REPOSITORIES: |
| 112 UpdateTarget(repo, options) | 126 UpdateTarget(repo, options) |
| 127 if options.commit: |
| 128 CreateCommit(options) |
| 113 | 129 |
| 114 if __name__ == "__main__": | 130 if __name__ == "__main__": |
| 115 Main(sys.argv[1:]) | 131 Main(sys.argv[1:]) |
| OLD | NEW |