Skip to content

Commit

Permalink
Checkout prebuilt dart into standalone dart location. (flutter#77)
Browse files Browse the repository at this point in the history
* Checkout prebuilt dart into same location where standalone dart sdk expects it.

* Refactor. Remove correct folder
  • Loading branch information
aam authored Jun 29, 2017
1 parent 1038354 commit 2145244
Showing 1 changed file with 48 additions and 41 deletions.
89 changes: 48 additions & 41 deletions tools/dart/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,61 +27,68 @@

# Path constants. (All of these should be absolute paths.)
THIS_DIR = os.path.abspath(os.path.dirname(__file__))
MOJO_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))
DART_SDK_DIR = os.path.join(MOJO_DIR, 'third_party', 'dart-sdk')
STAMP_FILE = os.path.join(DART_SDK_DIR, 'STAMP_FILE')
LIBRARIES_FILE = os.path.join(DART_SDK_DIR,'dart-sdk',
'lib', '_internal', 'libraries.dart')
PATCH_FILE = os.path.join(MOJO_DIR, 'tools', 'dart', 'patch_sdk.diff')
FLUTTER_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..'))
DART_SDKS_DIR = os.path.join(FLUTTER_DIR, 'dart/tools/sdks')
PATCH_FILE = os.path.join(FLUTTER_DIR, 'tools', 'dart', 'patch_sdk.diff')

def IsStampFileUpToDate(stamp_file, sdk_url):
if not os.path.exists(stamp_file):
return False
# Get the contents of the stamp file.
with open(stamp_file, "r") as stamp_file:
stamp_url = stamp_file.read().replace('\n', '')
return stamp_url == sdk_url

def ExtractZipInto(zip_file, target_extract_dir, set_unix_file_modes):
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
for zip_info in zip_ref.infolist():
zip_ref.extract(zip_info, path=target_extract_dir)
if set_unix_file_modes:
# external_attr is 32 in size with the unix mode in the
# high order 16 bit
mode = (zip_info.external_attr >> 16) & 0xFFF
os.chmod(os.path.join(target_extract_dir, zip_info.filename), mode)

def main():
# Only get the SDK if we don't have a stamp for or have an out of date stamp
# file.
get_sdk = False
set_unix_file_modes = True
if sys.platform.startswith('linux'):
sdk_url = SDK_URL_BASE + LINUX_64_SDK
output_file = os.path.join(DART_SDK_DIR, LINUX_64_SDK)
os_infix = 'linux'
zip_filename = LINUX_64_SDK
elif sys.platform.startswith('darwin'):
sdk_url = SDK_URL_BASE + MACOS_64_SDK
output_file = os.path.join(DART_SDK_DIR, MACOS_64_SDK)
os_infix = 'mac'
zip_filename = MACOS_64_SDK
elif sys.platform.startswith('win'):
sdk_url = SDK_URL_BASE + WINDOWS_64_SDK
output_file = os.path.join(DART_SDK_DIR, WINDOWS_64_SDK)
os_infix = 'win'
zip_filename = WINDOWS_64_SDK
set_unix_file_modes = False
else:
print "Platform not supported"
return 1

if not os.path.exists(STAMP_FILE):
get_sdk = True
else:
# Get the contents of the stamp file.
with open(STAMP_FILE, "r") as stamp_file:
stamp_url = stamp_file.read().replace('\n', '')
if stamp_url != sdk_url:
get_sdk = True

if get_sdk:
# Completely remove all traces of the previous SDK.
if os.path.exists(DART_SDK_DIR):
shutil.rmtree(DART_SDK_DIR)
os.mkdir(DART_SDK_DIR)

urllib.urlretrieve(sdk_url, output_file)
print(output_file)
with zipfile.ZipFile(output_file, 'r') as zip_ref:
for zip_info in zip_ref.infolist():
zip_ref.extract(zip_info, path=DART_SDK_DIR)
if set_unix_file_modes:
# external_attr is 32 in size with the unix mode in the
# high order 16 bit
mode = (zip_info.external_attr >> 16) & 0xFFF
os.chmod(os.path.join(DART_SDK_DIR, zip_info.filename), mode)

# Write our stamp file so we don't redownload the sdk.
with open(STAMP_FILE, "w") as stamp_file:
stamp_file.write(sdk_url)
sdk_url = SDK_URL_BASE + zip_filename
dart_base_sdk_dir = os.path.join(DART_SDKS_DIR, os_infix)
output_file = os.path.join(dart_base_sdk_dir, zip_filename)

dart_sdk_dir = os.path.join(dart_base_sdk_dir, 'dart-sdk')

stamp_file = os.path.join(dart_sdk_dir, 'STAMP_FILE')
if IsStampFileUpToDate(stamp_file, sdk_url):
return 0

# Completely remove all traces of the previous SDK.
if os.path.exists(dart_sdk_dir):
shutil.rmtree(dart_sdk_dir)
os.mkdir(dart_sdk_dir)

urllib.urlretrieve(sdk_url, output_file)
ExtractZipInto(output_file, dart_base_sdk_dir, set_unix_file_modes)

# Write our stamp file so we don't redownload the sdk.
with open(stamp_file, "w") as stamp_file:
stamp_file.write(sdk_url)

return 0

Expand Down

0 comments on commit 2145244

Please sign in to comment.