1 #!/usr/bin/env python 2 3 import argparse 4 import logging 5 import os 6 import re 7 import shutil 8 from genmakefiles import GenerateMakefiles 9 10 AOSP_PATH = os.getcwd() 11 UNWANTED_DIRS = [ 12 'build/', 13 'test/', 14 'third_party/', 15 'buildtools/', 16 'tools/gyp', 17 'tools/swarming_client' 18 ] 19 20 parser = argparse.ArgumentParser(description='Merge a new version of V8.') 21 parser.add_argument('--v8_path', \ 22 required=True, help='Absolute path to the new version of V8 to be merged.') 23 args = 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) 27 new_files = [f for f in os.listdir(args.v8_path) if not f.startswith(".")] 28 current_files = [f for f in os.listdir(AOSP_PATH) if not f.startswith(".")] 29 to_remove = [f for f in current_files if f in new_files] 30 31 for 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. 39 all_new_v8 = os.path.join(args.v8_path, "*") 40 rsync_cmd = "rsync -r --exclude=\"*.git*\" " + all_new_v8 + \ 41 " . > /dev/null" 42 if 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) 46 for file in UNWANTED_DIRS: 47 path = os.path.join(AOSP_PATH, file) 48 shutil.rmtree(path) 49 50 # Create new makefiles 51 GenerateMakefiles() 52 53 # Update V8_MERGE_REVISION 54 major_version = 0 55 minor_version = 0 56 build_number = 0 57 patch_level = 0 58 59 success = True 60 with 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 83 version_string = major_version + "." + \ 84 minor_version + "." + \ 85 build_number + "." + \ 86 patch_level 87 88 if not success: 89 logging.warning("Couldn't extract V8 version to update V8_MERGE_REVISION." + \ 90 " Got " + version_string) 91 else: 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!"