aboutsummaryrefslogtreecommitdiff
path: root/merge.py
blob: b93eb7136a7065466c067d40a7cffbdd432d9731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python

import argparse
import logging
import os
import re
import shutil
from genmakefiles import GenerateMakefiles

AOSP_PATH = os.getcwd()
UNWANTED_DIRS = [
  'build/',
  'test/',
  'third_party/',
  'buildtools/',
  'tools/'
]

parser = argparse.ArgumentParser(description='Merge a new version of V8.')
parser.add_argument('--v8_path', \
  required=True, help='Absolute path to the new version of V8 to be merged.')
args = parser.parse_args()

# Find all the files that are in both the old and the new repo; remove them
# (ie. leave the Android-only files in place)
new_files = [f for f in os.listdir(args.v8_path) if not f.startswith(".")]
current_files = [f for f in os.listdir(AOSP_PATH) if not f.startswith(".")]
to_remove = [f for f in current_files if f in new_files]

for file in to_remove:
  path = os.path.join(AOSP_PATH, file)
  if os.path.isfile(path):
    os.remove(path)
  else:
    shutil.rmtree(path)

# Copy accross the new files.
all_new_v8 = os.path.join(args.v8_path, "*")
rsync_cmd = "rsync -r --exclude=\"*.git*\" " + all_new_v8 + \
  " . > /dev/null"
if os.system(rsync_cmd) != 0:
  raise RuntimeError("Could not rsync the new V8.")

# Now remove extra stuff that AOSP doesn't want (to save space)
for file in UNWANTED_DIRS:
  path = os.path.join(AOSP_PATH, file)
  shutil.rmtree(path)

# Create new makefiles
GenerateMakefiles()

# Update V8_MERGE_REVISION
major_version = 0
minor_version = 0
build_number = 0
patch_level = 0

success = True
with open(os.path.join(AOSP_PATH, "include/v8-version.h"), 'r') as f:
  content = f.read()
  result = re.search("V8_MAJOR_VERSION (\\d*)", content)
  if result != None:
    major_version = result.group(1)
  else:
    success = False
  result = re.search("V8_MINOR_VERSION (\\d*)", content)
  if result != None:
    minor_version = result.group(1)
  else:
    success = False
  result = re.search("V8_BUILD_NUMBER (\\d*)", content)
  if result != None:
    build_number = result.group(1)
  else:
    success = False
  result = re.search("V8_PATCH_LEVEL (\\d*)", content)
  if result != None:
    patch_level = result.group(1)
  else:
    success = False

version_string = major_version + "." + \
  minor_version + "." + \
  build_number + "." + \
  patch_level

if not success:
  logging.warning("Couldn't extract V8 version to update V8_MERGE_REVISION." + \
     " Got " + version_string)
else:
  with open(os.path.join(AOSP_PATH, "V8_MERGE_REVISION"), 'w') as f:
    f.write("v8 " + version_string + "\n")
    f.write("https://chromium.googlesource.com/v8/v8/+/" + version_string)

  # Done!
  print "Merged V8 " + version_string + ". Test, commit and upload!"