Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: tools/release/update_node.py

Issue 2744663005: Add script to update relevant changes to Node.js. (Closed)
Patch Set: address comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
11 TARGET_SUBDIR = os.path.join("deps", "v8")
12
13 REPOSITORIES = [ [""],
14 ["testing", "gtest"],
15 ["third_party", "jinja2"],
16 ["third_party", "markupsafe"] ]
17
18 DELETE_FROM_GITIGNORE = [ "/base",
19 "/testing/gtest" ]
20
21 ADD_TO_GITIGNORE = [ "/testing/gtest/*",
Michael Achenbach 2017/03/13 17:13:20 Maybe add a comment/documentation somewhere what t
Yang 2017/03/14 07:49:00 I added a comment.
22 "!/testing/gtest/include",
23 "/testing/gtest/include/*",
24 "!/testing/gtest/include/gtest",
25 "/testing/gtest/include/gtest/*",
26 "!/testing/gtest/include/gtest/gtest_prod.h",
27 "!/third_party/jinja2",
28 "!/third_party/markupsafe" ]
29
30 def RunGclient(path):
31 assert os.path.isdir(path)
32 print ">> Running gclient sync"
33 subprocess.call("gclient sync --nohooks", cwd=path, shell=True)
34
35 def UninitGit(path):
36 target = os.path.join(path, ".git")
37 if os.path.isdir(target):
38 print ">> Cleaning up %s" % path
39 shutil.rmtree(target)
40
41 def UpdateTarget(repository, options):
42 source = os.path.join(options.v8_path, *repository)
43 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository)
44 print ">> Updating target directory %s" % target
45 print ">> from active branch at %s" % source
46 # Remove possible remnants of previous incomplete runs.
47 UninitGit(target)
48
49 git_commands = [
50 "git init", # initialize target repo
51 "git remote add origin %s" % source, # point to the source repo
52 "git fetch origin HEAD", # sync to the current branch
53 "git reset --hard FETCH_HEAD", # reset to the current branch
54 "git clean -fd" # delete removed files
55 ]
56 try:
57 for command in git_commands:
58 subprocess.call(command, cwd=target, shell=True)
59 except:
60 raise
61 finally:
62 UninitGit(target)
63 print
64
65 def UpdateGitIgnore(options):
66 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore")
67 assert os.path.isfile(file_name)
68 print ">> Updating .gitignore with lines"
69 with open(file_name) as gitignore:
70 content = gitignore.readlines()
71 content = [x.strip() for x in content]
72 for x in DELETE_FROM_GITIGNORE:
73 if x in content:
74 print "- %s" % x
75 content.remove(x)
76 for x in ADD_TO_GITIGNORE:
77 if x not in content:
78 print "+ %s" % x
79 content.append(x)
80 content.sort(key=lambda x: x[1:] if x.startswith("!") else x)
81 with open(file_name, "w") as gitignore:
82 for x in content:
83 gitignore.write("%s\n" % x)
84
85 def ParseOptions():
86 parser = argparse.ArgumentParser(description="Update V8 in Node.js")
87 parser.add_argument("v8_path", help="Path to V8 checkout")
88 parser.add_argument("node_path", help="Path to Node.js checkout")
89 parser.add_argument("--gclient", dest="gclient",
90 action="store_true", help="Run gclient sync")
91 options = parser.parse_args()
92 assert os.path.isdir(options.v8_path)
93 options.v8_path = os.path.abspath(options.v8_path)
94 assert os.path.isdir(options.node_path)
95 options.node_path = os.path.abspath(options.node_path)
96 return options
97
98 def Main():
99 options = ParseOptions()
100 if options.gclient:
101 RunGclient(options.v8_path)
102 for repo in REPOSITORIES:
103 UpdateTarget(repo, options)
104 UpdateGitIgnore(options)
Michael Achenbach 2017/03/13 10:33:23 Possibility for confusion - not sure how it could
Yang 2017/03/14 07:49:00 I don't think .gitignore applies to 'git clean -fd
105
106 if __name__ == "__main__":
107 Main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698