Skip to content

Commit ebf4527

Browse files
legendecasaduh95
authored andcommitted
tools: update inspector_protocol roller
Fix the inspector_protocol/roll.py to fit node source directory structure. `roll.py` reads the `deps/v8/thrid_party/inspector_protocol/README.v8` to get the revision of the inspector_protocol that V8 depends on, and updates the local version to match. V8's copy of inspector_protocol modifies the namespace of `crdtp` library and does not export the symbols. So it can not be used outside of V8. PR-URL: #56649 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 5dd08d1 commit ebf4527

File tree

1 file changed

+43
-39
lines changed

1 file changed

+43
-39
lines changed

tools/inspector_protocol/roll.py

+43-39
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,22 @@
1818
'code_generator.py',
1919
'concatenate_protocols.py',
2020
'convert_protocol_to_json.py',
21-
'encoding/encoding.h',
22-
'encoding/encoding.cc',
23-
'encoding/encoding_test.cc',
21+
'crdtp/*',
2422
'inspector_protocol.gni',
2523
'inspector_protocol.gypi',
2624
'lib/*',
2725
'pdl.py',
2826
'templates/*',
2927
]
3028

29+
REVISION_LINE_PREFIX = 'Revision: '
3130

3231
def RunCmd(cmd):
3332
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
3433
(stdoutdata, stderrdata) = p.communicate()
3534
if p.returncode != 0:
3635
raise Exception('%s: exit status %d', str(cmd), p.returncode)
37-
return stdoutdata
36+
return stdoutdata.decode('utf-8')
3837

3938

4039
def CheckRepoIsClean(path, suffix):
@@ -48,25 +47,18 @@ def CheckRepoIsClean(path, suffix):
4847
raise Exception('%s does not end with /%s' % (path, suffix))
4948

5049

51-
def CheckRepoIsNotAtMasterBranch(path):
50+
def CheckRepoIsNotAtMainBranch(path):
5251
os.chdir(path)
5352
stdout = RunCmd(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip()
54-
if stdout == 'master':
55-
raise Exception('%s is at master branch - refusing to copy there.' % path)
56-
57-
58-
def CheckRepoIsV8Checkout(path):
59-
os.chdir(path)
60-
if (RunCmd(['git', 'config', '--get', 'remote.origin.url']).strip() !=
61-
'https://chromium.googlesource.com/v8/v8.git'):
62-
raise Exception('%s is not a proper V8 checkout.' % path)
53+
if stdout == 'main':
54+
raise Exception('%s is at main branch - refusing to copy there.' % path)
6355

6456

6557
def CheckRepoIsInspectorProtocolCheckout(path):
6658
os.chdir(path)
67-
if (RunCmd(['git', 'config', '--get', 'remote.origin.url']).strip() !=
68-
'https://chromium.googlesource.com/deps/inspector_protocol.git'):
69-
raise Exception('%s is not a proper inspector_protocol checkout.' % path)
59+
revision = RunCmd(['git', 'config', '--get', 'remote.origin.url']).strip()
60+
if (revision != 'https://chromium.googlesource.com/deps/inspector_protocol.git'):
61+
raise Exception('%s is not a proper inspector_protocol checkout: %s' % (path, revision))
7062

7163

7264
def FindFilesToSyncIn(path):
@@ -83,21 +75,34 @@ def FilesAreEqual(path1, path2):
8375
open(path1).read() == open(path2).read())
8476

8577

78+
def ReadV8IPRevision(node_src_path):
79+
lines = open(os.path.join(node_src_path, 'deps/v8/third_party/inspector_protocol/README.v8')).readlines()
80+
for line in lines:
81+
line = line.strip()
82+
if line.startswith(REVISION_LINE_PREFIX):
83+
return line[len(REVISION_LINE_PREFIX):]
84+
raise Exception('No V8 inspector protocol revision found')
85+
86+
def CheckoutRevision(path, revision):
87+
os.chdir(path)
88+
return RunCmd(['git', 'checkout', revision])
89+
90+
8691
def GetHeadRevision(path):
8792
os.chdir(path)
8893
return RunCmd(['git', 'rev-parse', 'HEAD'])
8994

9095

9196
def main(argv):
9297
parser = argparse.ArgumentParser(description=(
93-
"Rolls the inspector_protocol project (upstream) into V8's "
94-
"third_party (downstream)."))
98+
"Rolls the inspector_protocol project (upstream) into node's "
99+
"tools/inspector_protocol (downstream)."))
95100
parser.add_argument("--ip_src_upstream",
96101
help="The inspector_protocol (upstream) tree.",
97102
default="~/ip/src")
98-
parser.add_argument("--v8_src_downstream",
99-
help="The V8 src tree.",
100-
default="~/v8/v8")
103+
parser.add_argument("--node_src_downstream",
104+
help="The nodejs/node src tree.",
105+
default="~/nodejs/node")
101106
parser.add_argument('--force', dest='force', action='store_true',
102107
help=("Whether to carry out the modifications "
103108
"in the destination tree."))
@@ -106,17 +111,22 @@ def main(argv):
106111
args = parser.parse_args(argv)
107112
upstream = os.path.normpath(os.path.expanduser(args.ip_src_upstream))
108113
downstream = os.path.normpath(os.path.expanduser(
109-
args.v8_src_downstream))
114+
args.node_src_downstream))
110115
CheckRepoIsClean(upstream, '/src')
111-
CheckRepoIsClean(downstream, '/v8')
116+
CheckRepoIsClean(downstream, '/node')
112117
CheckRepoIsInspectorProtocolCheckout(upstream)
113-
CheckRepoIsV8Checkout(downstream)
114-
# Check that the destination Git repo isn't at the master branch - it's
115-
# generally a bad idea to check into the master branch, so we catch this
118+
# Check that the destination Git repo isn't at the main branch - it's
119+
# generally a bad idea to check into the main branch, so we catch this
116120
# common pilot error here early.
117-
CheckRepoIsNotAtMasterBranch(downstream)
121+
CheckRepoIsNotAtMainBranch(downstream)
122+
123+
# Read V8's inspector_protocol revision
124+
v8_ip_revision = ReadV8IPRevision(downstream)
125+
print('Checking out %s into %s ...' % (upstream, v8_ip_revision))
126+
CheckoutRevision(upstream, v8_ip_revision)
127+
118128
src_dir = upstream
119-
dest_dir = os.path.join(downstream, 'third_party/inspector_protocol')
129+
dest_dir = os.path.join(downstream, 'tools/inspector_protocol')
120130
print('Rolling %s into %s ...' % (src_dir, dest_dir))
121131
src_files = set(FindFilesToSyncIn(src_dir))
122132
dest_files = set(FindFilesToSyncIn(dest_dir))
@@ -137,22 +147,16 @@ def main(argv):
137147
print('You said --force ... as you wish, modifying the destination.')
138148
for f in to_add + to_copy:
139149
contents = open(os.path.join(src_dir, f)).read()
140-
contents = contents.replace(
141-
'INSPECTOR_PROTOCOL_ENCODING_ENCODING_H_',
142-
'V8_INSPECTOR_PROTOCOL_ENCODING_ENCODING_H_')
143-
contents = contents.replace(
144-
'namespace inspector_protocol_encoding',
145-
'namespace v8_inspector_protocol_encoding')
146150
open(os.path.join(dest_dir, f), 'w').write(contents)
147151
shutil.copymode(os.path.join(src_dir, f), os.path.join(dest_dir, f))
148152
for f in to_delete:
149153
os.unlink(os.path.join(dest_dir, f))
150154
head_revision = GetHeadRevision(upstream)
151-
lines = open(os.path.join(dest_dir, 'README.v8')).readlines()
152-
f = open(os.path.join(dest_dir, 'README.v8'), 'w')
155+
lines = open(os.path.join(dest_dir, 'README.node')).readlines()
156+
f = open(os.path.join(dest_dir, 'README.node'), 'w')
153157
for line in lines:
154-
if line.startswith('Revision: '):
155-
f.write('Revision: %s' % head_revision)
158+
if line.startswith(REVISION_LINE_PREFIX):
159+
f.write(f'{REVISION_LINE_PREFIX}{head_revision}')
156160
else:
157161
f.write(line)
158162
f.close()

0 commit comments

Comments
 (0)