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"], | |
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 if subprocess.call("gclient sync --nohooks", cwd=path, shell=True) != 0: | |
Michael Achenbach
2017/03/14 08:20:25
nit: you can use a check_call to get this behavior
Yang
2017/03/14 08:24:12
Done.
| |
36 raise Exception("'gclient sync' failed.") | |
37 | |
38 def UninitGit(path): | |
39 target = os.path.join(path, ".git") | |
40 if os.path.isdir(target): | |
41 print ">> Cleaning up %s" % path | |
42 shutil.rmtree(target) | |
43 | |
44 def UpdateTarget(repository, options): | |
45 source = os.path.join(options.v8_path, *repository) | |
46 target = os.path.join(options.node_path, TARGET_SUBDIR, *repository) | |
47 print ">> Updating target directory %s" % target | |
48 print ">> from active branch at %s" % source | |
49 if not os.path.exists(target): | |
Michael Achenbach
2017/03/14 08:20:25
just a remark - if we ever add a new folder struct
Yang
2017/03/14 08:24:12
os.makedirs creates folders recursively though.
Michael Achenbach
2017/03/14 08:37:26
You're right! Learned something today. Then there'
| |
50 os.makedirs(target) | |
51 # Remove possible remnants of previous incomplete runs. | |
52 UninitGit(target) | |
53 | |
54 git_commands = [ | |
55 "git init", # initialize target repo | |
56 "git remote add origin %s" % source, # point to the source repo | |
57 "git fetch origin HEAD", # sync to the current branch | |
58 "git reset --hard FETCH_HEAD", # reset to the current branch | |
59 "git clean -fd" # delete removed files | |
60 ] | |
61 try: | |
62 for command in git_commands: | |
63 if subprocess.call(command, cwd=target, shell=True) != 0: | |
64 raise Exception("'%s' failed." % command) | |
65 except: | |
66 raise | |
67 finally: | |
68 UninitGit(target) | |
69 | |
70 def UpdateGitIgnore(options): | |
71 file_name = os.path.join(options.node_path, TARGET_SUBDIR, ".gitignore") | |
72 assert os.path.isfile(file_name) | |
73 print ">> Updating .gitignore with lines" | |
74 with open(file_name) as gitignore: | |
75 content = gitignore.readlines() | |
76 content = [x.strip() for x in content] | |
77 for x in DELETE_FROM_GITIGNORE: | |
78 if x in content: | |
79 print "- %s" % x | |
80 content.remove(x) | |
81 for x in ADD_TO_GITIGNORE: | |
82 if x not in content: | |
83 print "+ %s" % x | |
84 content.append(x) | |
85 content.sort(key=lambda x: x[1:] if x.startswith("!") else x) | |
86 with open(file_name, "w") as gitignore: | |
87 for x in content: | |
88 gitignore.write("%s\n" % x) | |
89 | |
90 def ParseOptions(args): | |
91 parser = argparse.ArgumentParser(description="Update V8 in Node.js") | |
92 parser.add_argument("v8_path", help="Path to V8 checkout") | |
93 parser.add_argument("node_path", help="Path to Node.js checkout") | |
94 parser.add_argument("--gclient", dest="gclient", | |
95 action="store_true", help="Run gclient sync") | |
96 options = parser.parse_args(args) | |
97 assert os.path.isdir(options.v8_path) | |
98 options.v8_path = os.path.abspath(options.v8_path) | |
99 assert os.path.isdir(options.node_path) | |
100 options.node_path = os.path.abspath(options.node_path) | |
101 return options | |
102 | |
103 def Main(args): | |
104 options = ParseOptions(args) | |
105 if options.gclient: | |
106 RunGclient(options.v8_path) | |
107 # Update main V8 repository. | |
108 UpdateTarget([""], options) | |
109 # Patch .gitignore before updating sub-repositories. | |
110 UpdateGitIgnore(options) | |
111 for repo in SUB_REPOSITORIES: | |
112 UpdateTarget(repo, options) | |
113 | |
114 if __name__ == "__main__": | |
115 Main(sys.argv[1:]) | |
OLD | NEW |