• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2
3import argparse
4import logging
5import os
6import re
7import shutil
8from genmakefiles import GenerateMakefiles
9
10AOSP_PATH = os.getcwd()
11UNWANTED_DIRS = [
12  'build/',
13  'test/',
14  'third_party/',
15  'buildtools/',
16  'tools/gyp',
17  'tools/swarming_client'
18]
19
20parser = argparse.ArgumentParser(description='Merge a new version of V8.')
21parser.add_argument('--v8_path', \
22  required=True, help='Absolute path to the new version of V8 to be merged.')
23args = parser.parse_args()
24
25# Find all the files that are in both the old and the new repo; remove them
26# (ie. leave the Android-only files in place)
27new_files = [f for f in os.listdir(args.v8_path) if not f.startswith(".")]
28current_files = [f for f in os.listdir(AOSP_PATH) if not f.startswith(".")]
29to_remove = [f for f in current_files if f in new_files]
30
31for file in to_remove:
32  path = os.path.join(AOSP_PATH, file)
33  if os.path.isfile(path):
34    os.remove(path)
35  else:
36    shutil.rmtree(path)
37
38# Copy accross the new files.
39all_new_v8 = os.path.join(args.v8_path, "*")
40rsync_cmd = "rsync -r --exclude=\"*.git*\" " + all_new_v8 + \
41  " . > /dev/null"
42if os.system(rsync_cmd) != 0:
43  raise RuntimeError("Could not rsync the new V8.")
44
45# Now remove extra stuff that AOSP doesn't want (to save space)
46for file in UNWANTED_DIRS:
47  path = os.path.join(AOSP_PATH, file)
48  shutil.rmtree(path)
49
50# Create new makefiles
51GenerateMakefiles()
52
53# Update V8_MERGE_REVISION
54major_version = 0
55minor_version = 0
56build_number = 0
57patch_level = 0
58
59success = True
60with open(os.path.join(AOSP_PATH, "include/v8-version.h"), 'r') as f:
61  content = f.read()
62  result = re.search("V8_MAJOR_VERSION (\\d*)", content)
63  if result != None:
64    major_version = result.group(1)
65  else:
66    success = False
67  result = re.search("V8_MINOR_VERSION (\\d*)", content)
68  if result != None:
69    minor_version = result.group(1)
70  else:
71    success = False
72  result = re.search("V8_BUILD_NUMBER (\\d*)", content)
73  if result != None:
74    build_number = result.group(1)
75  else:
76    success = False
77  result = re.search("V8_PATCH_LEVEL (\\d*)", content)
78  if result != None:
79    patch_level = result.group(1)
80  else:
81    success = False
82
83version_string = major_version + "." + \
84  minor_version + "." + \
85  build_number + "." + \
86  patch_level
87
88if not success:
89  logging.warning("Couldn't extract V8 version to update V8_MERGE_REVISION." + \
90     " Got " + version_string)
91else:
92  with open(os.path.join(AOSP_PATH, "V8_MERGE_REVISION"), 'w') as f:
93    f.write("v8 " + version_string + "\n")
94    f.write("https://chromium.googlesource.com/v8/v8/+/" + version_string)
95
96  # Done!
97  print "Merged V8 " + version_string + ". Test, commit and upload!"