-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to use a prebuilt Dart SDK
- Loading branch information
Showing
9 changed files
with
333 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright 2013 The Flutter Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
# This python script downloads the Dart dev channel SDK that matches the | ||
# version in the source tree and puts it in prebuilts/. | ||
# TODO(zra): Eliminate the script and download through the DEPS file if/when | ||
# the SDKs pulled by this script are uploaded to cipd. | ||
|
||
import os | ||
import platform | ||
import re | ||
import shutil | ||
import subprocess | ||
import sys | ||
import zipfile | ||
|
||
|
||
SRC_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
FLUTTER_DIR = os.path.join(SRC_ROOT, 'flutter') | ||
FLUTTER_PREBUILTS_DIR = os.path.join(FLUTTER_DIR, 'prebuilts') | ||
DART_DIR = os.path.join(SRC_ROOT, 'third_party', 'dart') | ||
DART_VERSION = os.path.join(DART_DIR, 'tools', 'VERSION') | ||
|
||
# The Dart SDK script is the source of truth about the sematic version. | ||
sys.path.append(os.path.join(DART_DIR, 'tools')) | ||
import utils | ||
|
||
|
||
def eprint(*args, **kwargs): | ||
print(*args, file=sys.stderr, **kwargs) | ||
|
||
|
||
# Try to guess the host operating system. | ||
def GuessOS(): | ||
os_name = utils.GuessOS() | ||
if os_name == 'win32': | ||
os_name == 'windows' | ||
if os_name not in ['linux', 'macos', 'windows']: | ||
eprint('Could not determine the OS: "%s"' % os_id) | ||
return None | ||
return os_name | ||
|
||
|
||
def ArchitecturesForOS(os_name): | ||
if os_name == 'linux': | ||
return ['x64', 'arm64'] | ||
elif os_name == 'macos': | ||
return ['x64', 'arm64'] | ||
elif os_name =='windows': | ||
return ['x64'] | ||
|
||
eprint('Could not determine architectures for os "%s"' % os_name) | ||
return None | ||
|
||
|
||
def DownloadDartSDK(version, semantic_version, os_name, arch): | ||
channel = version.channel | ||
if channel == 'be': | ||
eprint('Only dev, beta, and stable channels can be used for prebuilt SDKs') | ||
return None | ||
file = 'dartsdk-{}-{}-release.zip'.format(os_name, arch) | ||
url = 'https://storage.googleapis.com/dart-archive/channels/{}/raw/{}/sdk/{}'.format( | ||
channel, semantic_version, file, | ||
) | ||
dest = os.path.join(FLUTTER_PREBUILTS_DIR, file) | ||
|
||
stamp_file = '{}.stamp'.format(dest) | ||
version_stamp = None | ||
try: | ||
with open(stamp_file) as fd: | ||
version_stamp = fd.read() | ||
except: | ||
version_stamp = 'none' | ||
|
||
if version == version_stamp: | ||
# Prebuilt Dart SDK already up-to-date. Skipping download. | ||
return '' | ||
|
||
if os.path.isfile(dest): | ||
os.unlink(dest) | ||
|
||
curl_command = ['curl', url, '-o', dest] | ||
curl_result = subprocess.run( | ||
curl_command, | ||
stdout=subprocess.PIPE, | ||
stderr=subprocess.PIPE, | ||
universal_newlines=True, | ||
) | ||
if curl_result.returncode != 0: | ||
eprint('Failed to download: stdout:\n{}\nstderr:\n{}'.format( | ||
curl_result.stdout, curl_result.stderr, | ||
)) | ||
return None | ||
|
||
return dest | ||
|
||
|
||
class ZipFileWithPermissions(zipfile.ZipFile): | ||
""" Custom ZipFile class handling file permissions. """ | ||
def _extract_member(self, member, targetpath, pwd): | ||
if not isinstance(member, zipfile.ZipInfo): | ||
member = self.getinfo(member) | ||
|
||
targetpath = super()._extract_member(member, targetpath, pwd) | ||
|
||
attr = member.external_attr >> 16 | ||
if attr != 0: | ||
os.chmod(targetpath, attr) | ||
return targetpath | ||
|
||
|
||
def ExtractDartSDK(archive, os_name, arch): | ||
os_arch = '{}-{}'.format(os_name, arch) | ||
dart_sdk = os.path.join(FLUTTER_PREBUILTS_DIR, os_arch, 'dart-sdk') | ||
if os.path.isdir(dart_sdk): | ||
shutil.rmtree(dart_sdk) | ||
|
||
extract_dest = os.path.join(FLUTTER_PREBUILTS_DIR, os_arch) | ||
os.makedirs(extract_dest, exist_ok=True) | ||
|
||
with ZipFileWithPermissions(archive, "r") as z: | ||
z.extractall(extract_dest) | ||
|
||
|
||
def Main(): | ||
os.makedirs(FLUTTER_PREBUILTS_DIR, exist_ok=True) | ||
|
||
version = utils.ReadVersionFile() | ||
if version == None: | ||
return 1 | ||
semantic_version = utils.GetSemanticSDKVersion() | ||
|
||
os_name = GuessOS() | ||
if os_name == None: | ||
return 1 | ||
|
||
architectures = ArchitecturesForOS(os_name) | ||
if architectures == None: | ||
return 1 | ||
|
||
for arch in ArchitecturesForOS(os_name): | ||
archive = DownloadDartSDK(version, semantic_version, os_name, arch) | ||
if archive == None: | ||
return 1 | ||
if archive == '': | ||
return 0 | ||
ExtractDartSDK(archive, os_name, arch) | ||
try: | ||
stamp_file = '{}.stamp'.format(archive) | ||
with open(stamp_file, "w") as fd: | ||
fd.write(semantic_version) | ||
except Exception as e: | ||
eprint('Failed to write Dart SDK version stamp file:\n{}'.format(e)) | ||
return 1 | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(Main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.