Index: tools/release/update_node.py |
diff --git a/tools/release/update_node.py b/tools/release/update_node.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..c3e4bfe199bb71d1483e15f526717392ab7998ee |
--- /dev/null |
+++ b/tools/release/update_node.py |
@@ -0,0 +1,80 @@ |
+#!/usr/bin/env python |
+# Copyright 2017 the V8 project 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 argparse |
+import os |
+import shutil |
+import subprocess |
+ |
+TARGET_SUBDIR = os.path.join("deps", "v8") |
+REPOSITORIES = [ [""], |
+ ["testing", "gtest"], |
+ ["third_party", "jinja2"], |
+ ["third_party", "markupsafe"] ] |
+ |
+def RunGclient(path): |
+ assert os.path.isdir(path) |
+ print ">> Running gclient sync" |
+ subprocess.call("gclient sync --nohooks", |
+ cwd=path, shell=True, stdout=None) |
Michael Achenbach
2017/03/10 13:35:06
nit: stdout=None is the default, can be dropped.
Yang
2017/03/13 08:25:49
Done.
|
+ |
+def UpdateTarget(repository, options): |
+ source = os.path.join(options.v8_path, *repository) |
+ target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) |
+ print ">> Updating target directory %s" % source |
Michael Achenbach
2017/03/10 13:35:05
nit - readability: it's a bit confusing to read "t
Yang
2017/03/13 08:25:49
You are right. It should print target first and so
|
+ print ">> from active branch at %s" % target |
+ git_commands = [ |
Michael Achenbach
2017/03/10 13:35:05
Is there any assumption about the directory state,
Yang
2017/03/13 08:25:49
Done.
|
+ "git init", # initialize target repo |
+ "git remote add origin %s" % source, # point to the source repo |
Michael Achenbach
2017/03/10 13:35:06
Does this work if the git repro in source folder u
Yang
2017/03/13 08:25:49
I'm not familiar with git cache. Isn't it provided
Michael Achenbach
2017/03/13 10:33:23
Not sure if everything works as expected when maki
|
+ "git fetch origin HEAD", # sync to the current branch |
+ "git reset --hard FETCH_HEAD", # reset to the current branch |
+ "git clean -fd" # delete removed files |
+ ] |
+ try: |
+ for command in git_commands: |
+ subprocess.call(command, cwd=target, shell=True, stdout=None) |
Michael Achenbach
2017/03/10 13:35:06
nit: drop stdout, like above
Yang
2017/03/13 08:25:49
Done.
|
+ except: |
+ print ">> Failed!" |
Michael Achenbach
2017/03/10 13:35:06
Do we need this?
Yang
2017/03/13 08:25:49
Removed
|
+ raise |
+ finally: |
+ # Un-init git. |
+ print ">> Cleaning up" |
+ shutil.rmtree(os.path.join(target, ".git")) |
+ |
+def UpdateGitIgnore(options): |
+ file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") |
+ assert os.path.isfile(file_name) |
+ print ">> Updating .gitignore with lines" |
+ with open(file_name, "a") as gitignore: |
Michael Achenbach
2017/03/10 13:35:05
Won't this append over and over again? What if the
Yang
2017/03/13 08:25:49
Done.
|
+ for repository in REPOSITORIES: |
+ sub_repo = "/".join(repository) |
+ if not sub_repo is "": |
+ line = "!/" + sub_repo |
+ print line |
+ gitignore.write(line + "\n") |
+ |
+def ParseOptions(): |
+ parser = argparse.ArgumentParser(description="Update V8 in Node.js") |
+ parser.add_argument("v8_path", help="Path to V8 checkout") |
+ parser.add_argument("node_path", help="Path to Node.js checkout") |
+ parser.add_argument("--gclient", dest="gclient", |
+ action="store_true", help="Run gclient sync") |
+ options = parser.parse_args() |
+ assert os.path.isdir(options.v8_path) |
+ options.v8_path = os.path.abspath(options.v8_path) |
+ assert os.path.isdir(options.node_path) |
+ options.node_path = os.path.abspath(options.node_path) |
+ return options |
+ |
+def Main(): |
+ options = ParseOptions() |
+ if options.gclient: |
+ RunGclient(options.v8_path) |
+ [UpdateTarget(repo, options) for repo in REPOSITORIES] |
Michael Achenbach
2017/03/10 13:35:05
I'm having a one-line fetish too, but maybe here i
Yang
2017/03/13 08:25:49
Done.
|
+ UpdateGitIgnore(options) |
+ |
+if __name__ == "__main__": |
+ Main() |