|
27 | 27 |
|
28 | 28 | # Path constants. (All of these should be absolute paths.) |
29 | 29 | THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
30 | | -MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..')) |
31 | | -DART_SDK_DIR = os.path.join(MOJO_DIR, 'third_party', 'dart-sdk') |
32 | | -STAMP_FILE = os.path.join(DART_SDK_DIR, 'STAMP_FILE') |
33 | | -LIBRARIES_FILE = os.path.join(DART_SDK_DIR,'dart-sdk', |
34 | | - 'lib', '_internal', 'libraries.dart') |
35 | | -PATCH_FILE = os.path.join(MOJO_DIR, 'tools', 'dart', 'patch_sdk.diff') |
| 30 | +FLUTTER_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..')) |
| 31 | +DART_SDKS_DIR = os.path.join(FLUTTER_DIR, 'dart/tools/sdks') |
| 32 | +PATCH_FILE = os.path.join(FLUTTER_DIR, 'tools', 'dart', 'patch_sdk.diff') |
| 33 | + |
| 34 | +def IsStampFileUpToDate(stamp_file, sdk_url): |
| 35 | + if not os.path.exists(stamp_file): |
| 36 | + return False |
| 37 | + # Get the contents of the stamp file. |
| 38 | + with open(stamp_file, "r") as stamp_file: |
| 39 | + stamp_url = stamp_file.read().replace('\n', '') |
| 40 | + return stamp_url == sdk_url |
| 41 | + |
| 42 | +def ExtractZipInto(zip_file, target_extract_dir, set_unix_file_modes): |
| 43 | + with zipfile.ZipFile(zip_file, 'r') as zip_ref: |
| 44 | + for zip_info in zip_ref.infolist(): |
| 45 | + zip_ref.extract(zip_info, path=target_extract_dir) |
| 46 | + if set_unix_file_modes: |
| 47 | + # external_attr is 32 in size with the unix mode in the |
| 48 | + # high order 16 bit |
| 49 | + mode = (zip_info.external_attr >> 16) & 0xFFF |
| 50 | + os.chmod(os.path.join(target_extract_dir, zip_info.filename), mode) |
36 | 51 |
|
37 | 52 | def main(): |
38 | 53 | # Only get the SDK if we don't have a stamp for or have an out of date stamp |
39 | 54 | # file. |
40 | 55 | get_sdk = False |
41 | 56 | set_unix_file_modes = True |
42 | 57 | if sys.platform.startswith('linux'): |
43 | | - sdk_url = SDK_URL_BASE + LINUX_64_SDK |
44 | | - output_file = os.path.join(DART_SDK_DIR, LINUX_64_SDK) |
| 58 | + os_infix = 'linux' |
| 59 | + zip_filename = LINUX_64_SDK |
45 | 60 | elif sys.platform.startswith('darwin'): |
46 | | - sdk_url = SDK_URL_BASE + MACOS_64_SDK |
47 | | - output_file = os.path.join(DART_SDK_DIR, MACOS_64_SDK) |
| 61 | + os_infix = 'mac' |
| 62 | + zip_filename = MACOS_64_SDK |
48 | 63 | elif sys.platform.startswith('win'): |
49 | | - sdk_url = SDK_URL_BASE + WINDOWS_64_SDK |
50 | | - output_file = os.path.join(DART_SDK_DIR, WINDOWS_64_SDK) |
| 64 | + os_infix = 'win' |
| 65 | + zip_filename = WINDOWS_64_SDK |
51 | 66 | set_unix_file_modes = False |
52 | 67 | else: |
53 | 68 | print "Platform not supported" |
54 | 69 | return 1 |
55 | 70 |
|
56 | | - if not os.path.exists(STAMP_FILE): |
57 | | - get_sdk = True |
58 | | - else: |
59 | | - # Get the contents of the stamp file. |
60 | | - with open(STAMP_FILE, "r") as stamp_file: |
61 | | - stamp_url = stamp_file.read().replace('\n', '') |
62 | | - if stamp_url != sdk_url: |
63 | | - get_sdk = True |
64 | | - |
65 | | - if get_sdk: |
66 | | - # Completely remove all traces of the previous SDK. |
67 | | - if os.path.exists(DART_SDK_DIR): |
68 | | - shutil.rmtree(DART_SDK_DIR) |
69 | | - os.mkdir(DART_SDK_DIR) |
70 | | - |
71 | | - urllib.urlretrieve(sdk_url, output_file) |
72 | | - print(output_file) |
73 | | - with zipfile.ZipFile(output_file, 'r') as zip_ref: |
74 | | - for zip_info in zip_ref.infolist(): |
75 | | - zip_ref.extract(zip_info, path=DART_SDK_DIR) |
76 | | - if set_unix_file_modes: |
77 | | - # external_attr is 32 in size with the unix mode in the |
78 | | - # high order 16 bit |
79 | | - mode = (zip_info.external_attr >> 16) & 0xFFF |
80 | | - os.chmod(os.path.join(DART_SDK_DIR, zip_info.filename), mode) |
81 | | - |
82 | | - # Write our stamp file so we don't redownload the sdk. |
83 | | - with open(STAMP_FILE, "w") as stamp_file: |
84 | | - stamp_file.write(sdk_url) |
| 71 | + sdk_url = SDK_URL_BASE + zip_filename |
| 72 | + dart_base_sdk_dir = os.path.join(DART_SDKS_DIR, os_infix) |
| 73 | + output_file = os.path.join(dart_base_sdk_dir, zip_filename) |
| 74 | + |
| 75 | + dart_sdk_dir = os.path.join(dart_base_sdk_dir, 'dart-sdk') |
| 76 | + |
| 77 | + stamp_file = os.path.join(dart_sdk_dir, 'STAMP_FILE') |
| 78 | + if IsStampFileUpToDate(stamp_file, sdk_url): |
| 79 | + return 0 |
| 80 | + |
| 81 | + # Completely remove all traces of the previous SDK. |
| 82 | + if os.path.exists(dart_sdk_dir): |
| 83 | + shutil.rmtree(dart_sdk_dir) |
| 84 | + os.mkdir(dart_sdk_dir) |
| 85 | + |
| 86 | + urllib.urlretrieve(sdk_url, output_file) |
| 87 | + ExtractZipInto(output_file, dart_base_sdk_dir, set_unix_file_modes) |
| 88 | + |
| 89 | + # Write our stamp file so we don't redownload the sdk. |
| 90 | + with open(stamp_file, "w") as stamp_file: |
| 91 | + stamp_file.write(sdk_url) |
85 | 92 |
|
86 | 93 | return 0 |
87 | 94 |
|
|
0 commit comments