Add script to update relevant changes to Node.js.

NOTRY=true

R=franzih@chromium.org, machenbach@chromium.org, ofrobots@google.com

Review-Url: https://codereview.chromium.org/2744663005
Cr-Commit-Position: refs/heads/master@{#43764}
This commit is contained in:
yangguo 2017-03-14 01:26:12 -07:00 committed by Commit bot
parent 2cd2f5feff
commit f52a483305
20 changed files with 227 additions and 0 deletions

View File

@ -0,0 +1,91 @@
#!/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 os
import shutil
import subprocess
import sys
import tempfile
import unittest
import update_node
# Base paths.
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
TEST_DATA = os.path.join(BASE_DIR, 'testdata')
# Expectations.
EXPECTED_GITIGNORE = """
/testing/gtest/*
!/testing/gtest/include
/testing/gtest/include/*
!/testing/gtest/include/gtest
/testing/gtest/include/gtest/*
!/testing/gtest/include/gtest/gtest_prod.h
!/third_party/jinja2
!/third_party/markupsafe
/unrelated
"""
ADDED_FILES = [
'v8_new',
'new/v8_new',
'baz/v8_new',
'testing/gtest/gtest_new',
'testing/gtest/new/gtest_new',
'testing/gtest/baz/gtest_new',
]
REMOVED_FILES = [
'delete_me',
'baz/delete_me',
'testing/gtest/delete_me',
'testing/gtest/baz/delete_me',
]
def gitify(path):
files = os.listdir(path)
subprocess.check_call(['git', 'init'], cwd=path)
subprocess.check_call(['git', 'add'] + files, cwd=path)
subprocess.check_call(['git', 'commit', '-m="Initial"'], cwd=path)
class TestUpdateNode(unittest.TestCase):
def setUp(self):
self.workdir = tempfile.mkdtemp(prefix='tmp_test_node_')
def tearDown(self):
shutil.rmtree(self.workdir)
def testUpdate(self):
v8_cwd = os.path.join(self.workdir, 'v8')
gtest_cwd = os.path.join(self.workdir, 'v8', 'testing', 'gtest')
node_cwd = os.path.join(self.workdir, 'node')
# Set up V8 test fixture.
shutil.copytree(src=os.path.join(TEST_DATA, 'v8'), dst=v8_cwd)
gitify(v8_cwd)
for repository in update_node.SUB_REPOSITORIES:
gitify(os.path.join(v8_cwd, *repository))
# Set up node test fixture (no git repo required).
shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd)
# Run update script.
update_node.Main([v8_cwd, node_cwd])
# Check expectations.
with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f:
actual_gitignore = f.read()
self.assertEquals(EXPECTED_GITIGNORE.strip(), actual_gitignore.strip())
for f in ADDED_FILES:
added_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/'))
self.assertTrue(os.path.exists(added_file))
for f in REMOVED_FILES:
removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/'))
self.assertFalse(os.path.exists(removed_file))
if __name__ == "__main__":
unittest.main()

View File

@ -0,0 +1,7 @@
/unrelated
/testing/gtest/*
!/testing/gtest/include
/testing/gtest/include/*
!/testing/gtest/include/gtest
/testing/gtest/include/gtest/*
!/testing/gtest/include/gtest/gtest_prod.h

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

2
tools/release/testdata/v8/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/unrelated
/testing/gtest

1
tools/release/testdata/v8/baz/v8_foo vendored Normal file
View File

@ -0,0 +1 @@
...

1
tools/release/testdata/v8/baz/v8_new vendored Normal file
View File

@ -0,0 +1 @@
...

1
tools/release/testdata/v8/new/v8_new vendored Normal file
View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

@ -0,0 +1 @@
...

View File

1
tools/release/testdata/v8/v8_foo vendored Normal file
View File

@ -0,0 +1 @@
...

1
tools/release/testdata/v8/v8_new vendored Normal file
View File

@ -0,0 +1 @@
...

113
tools/release/update_node.py Executable file
View File

@ -0,0 +1,113 @@
#!/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
import sys
TARGET_SUBDIR = os.path.join("deps", "v8")
SUB_REPOSITORIES = [ ["testing", "gtest"],
["third_party", "jinja2"],
["third_party", "markupsafe"] ]
DELETE_FROM_GITIGNORE = [ "/base",
"/testing/gtest" ]
# Node.js requires only a single header file from gtest to build V8.
# Both jinja2 and markupsafe are required to generate part of the inspector.
ADD_TO_GITIGNORE = [ "/testing/gtest/*",
"!/testing/gtest/include",
"/testing/gtest/include/*",
"!/testing/gtest/include/gtest",
"/testing/gtest/include/gtest/*",
"!/testing/gtest/include/gtest/gtest_prod.h",
"!/third_party/jinja2",
"!/third_party/markupsafe" ]
def RunGclient(path):
assert os.path.isdir(path)
print ">> Running gclient sync"
subprocess.check_call("gclient sync --nohooks", cwd=path, shell=True)
def UninitGit(path):
target = os.path.join(path, ".git")
if os.path.isdir(target):
print ">> Cleaning up %s" % path
shutil.rmtree(target)
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" % target
print ">> from active branch at %s" % source
if not os.path.exists(target):
os.makedirs(target)
# Remove possible remnants of previous incomplete runs.
UninitGit(target)
git_commands = [
"git init", # initialize target repo
"git remote add origin %s" % source, # point to the source repo
"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.check_call(command, cwd=target, shell=True);
except:
raise
finally:
UninitGit(target)
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) as gitignore:
content = gitignore.readlines()
content = [x.strip() for x in content]
for x in DELETE_FROM_GITIGNORE:
if x in content:
print "- %s" % x
content.remove(x)
for x in ADD_TO_GITIGNORE:
if x not in content:
print "+ %s" % x
content.append(x)
content.sort(key=lambda x: x[1:] if x.startswith("!") else x)
with open(file_name, "w") as gitignore:
for x in content:
gitignore.write("%s\n" % x)
def ParseOptions(args):
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(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(args):
options = ParseOptions(args)
if options.gclient:
RunGclient(options.v8_path)
# Update main V8 repository.
UpdateTarget([""], options)
# Patch .gitignore before updating sub-repositories.
UpdateGitIgnore(options)
for repo in SUB_REPOSITORIES:
UpdateTarget(repo, options)
if __name__ == "__main__":
Main(sys.argv[1:])