Add --commit option and some polish to update_node.py.
NOTRY=true R=machenbach@chromium.org BUG=v8:6091 Review-Url: https://codereview.chromium.org/2747123002 Cr-Commit-Position: refs/heads/master@{#43781}
This commit is contained in:
parent
f2bab45967
commit
4c9ba86294
@ -29,6 +29,14 @@ EXPECTED_GITIGNORE = """
|
||||
/unrelated
|
||||
"""
|
||||
|
||||
EXPECTED_GIT_DIFF = """
|
||||
rename deps/v8/baz/{delete_me => v8_new} (100%)
|
||||
rename deps/v8/{delete_me => new/v8_new} (100%)
|
||||
create mode 100644 deps/v8/third_party/jinja2/jinja2
|
||||
create mode 100644 deps/v8/third_party/markupsafe/markupsafe
|
||||
create mode 100644 deps/v8/v8_new
|
||||
"""
|
||||
|
||||
ADDED_FILES = [
|
||||
'v8_new',
|
||||
'new/v8_new',
|
||||
@ -51,7 +59,7 @@ 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)
|
||||
subprocess.check_call(['git', 'commit', '-m', 'Initial'], cwd=path)
|
||||
|
||||
|
||||
class TestUpdateNode(unittest.TestCase):
|
||||
@ -71,11 +79,12 @@ class TestUpdateNode(unittest.TestCase):
|
||||
for repository in update_node.SUB_REPOSITORIES:
|
||||
gitify(os.path.join(v8_cwd, *repository))
|
||||
|
||||
# Set up node test fixture (no git repo required).
|
||||
# Set up node test fixture.
|
||||
shutil.copytree(src=os.path.join(TEST_DATA, 'node'), dst=node_cwd)
|
||||
gitify(os.path.join(node_cwd))
|
||||
|
||||
# Run update script.
|
||||
update_node.Main([v8_cwd, node_cwd])
|
||||
update_node.Main([v8_cwd, node_cwd, "--commit"])
|
||||
|
||||
# Check expectations.
|
||||
with open(os.path.join(node_cwd, 'deps', 'v8', '.gitignore')) as f:
|
||||
@ -87,6 +96,9 @@ class TestUpdateNode(unittest.TestCase):
|
||||
for f in REMOVED_FILES:
|
||||
removed_file = os.path.join(node_cwd, 'deps', 'v8', *f.split('/'))
|
||||
self.assertFalse(os.path.exists(removed_file))
|
||||
gitlog = subprocess.check_output(['git', 'diff', 'master', '--summary'],
|
||||
cwd=node_cwd)
|
||||
self.assertEquals(EXPECTED_GIT_DIFF.strip(), gitlog.strip())
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
@ -34,7 +34,7 @@ ADD_TO_GITIGNORE = [ "/testing/gtest/*",
|
||||
def RunGclient(path):
|
||||
assert os.path.isdir(path)
|
||||
print ">> Running gclient sync"
|
||||
subprocess.check_call("gclient sync --nohooks", cwd=path, shell=True)
|
||||
subprocess.check_call(["gclient", "sync", "--nohooks"], cwd=path)
|
||||
|
||||
def UninitGit(path):
|
||||
target = os.path.join(path, ".git")
|
||||
@ -53,15 +53,15 @@ def UpdateTarget(repository, options):
|
||||
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
|
||||
["git", "init"], # initialize target repo
|
||||
["git", "remote", "add", "origin", 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);
|
||||
subprocess.check_call(command, cwd=target)
|
||||
except:
|
||||
raise
|
||||
finally:
|
||||
@ -87,12 +87,26 @@ def UpdateGitIgnore(options):
|
||||
for x in content:
|
||||
gitignore.write("%s\n" % x)
|
||||
|
||||
def CreateCommit(options):
|
||||
print ">> Creating commit."
|
||||
# Find git hash from source.
|
||||
githash = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"],
|
||||
cwd=options.v8_path).strip()
|
||||
# Create commit at target.
|
||||
git_commands = [
|
||||
["git", "checkout", "-b", "update_v8_to_%s" % githash], # new branch
|
||||
["git", "add", "."], # add files
|
||||
["git", "commit", "-m", "Update V8 to %s" % githash] # new commit
|
||||
]
|
||||
for command in git_commands:
|
||||
subprocess.check_call(command, cwd=options.node_path)
|
||||
|
||||
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")
|
||||
parser.add_argument("--gclient", action="store_true", help="Run gclient sync")
|
||||
parser.add_argument("--commit", action="store_true", help="Create commit")
|
||||
options = parser.parse_args(args)
|
||||
assert os.path.isdir(options.v8_path)
|
||||
options.v8_path = os.path.abspath(options.v8_path)
|
||||
@ -110,6 +124,8 @@ def Main(args):
|
||||
UpdateGitIgnore(options)
|
||||
for repo in SUB_REPOSITORIES:
|
||||
UpdateTarget(repo, options)
|
||||
if options.commit:
|
||||
CreateCommit(options)
|
||||
|
||||
if __name__ == "__main__":
|
||||
Main(sys.argv[1:])
|
||||
|
Loading…
Reference in New Issue
Block a user