blob: e132033ee4782f754e1d5c465effd667c4079d26 [file] [log] [blame] [edit]
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
_FLUTTER_SDK_URL_TEMPLATE = "https://chrome-infra-packages.appspot.com/dl/flutter/fuchsia/+/{tag}"
_DART_SDK_URL_TEMPLATE = "https://chrome-infra-packages.appspot.com/dl/fuchsia/dart-sdk/{os}-amd64/+/{tag}"
def _flutter_sdk_url(tag):
# Return the URL of the SDK given an Operating System string and
# a CIPD tag.
return _FLUTTER_SDK_URL_TEMPLATE.format(tag = tag)
def _dart_sdk_url(os, tag):
# Return the URL of the SDK given an Operating System string and
# a CIPD tag.
return _DART_SDK_URL_TEMPLATE.format(os = os, tag = tag)
def _instantiate_from_cipd_bucket_impl(ctx):
ctx.file("WORKSPACE.bazel", content = "")
ctx.report_progress("Downloading " + ctx.attr.display_name)
ctx.download_and_extract(
ctx.attr.url,
type = "zip",
sha256 = ctx.attr.sha256,
)
ctx.template(
"BUILD.bazel",
ctx.attr.template,
substitutions = {
},
)
_instantiate_from_cipd_bucket = repository_rule(
implementation = _instantiate_from_cipd_bucket_impl,
attrs = {
"url": attr.string(),
"sha256": attr.string(),
"display_name": attr.string(),
"template": attr.label(allow_single_file = True),
},
)
def flutter_register_toolchains(
flutter_tag = None,
dart_tag = None,
flutter_sha256 = "",
dart_linux_sha256 = "",
dart_mac_sha256 = ""):
""" Registers the flutter and dart toolchains and downloads their content.
Note: This API is not stable.
Args:
flutter_tag: The Flutter CIPD tag to use
dart_tag: The Flutter CIPD tag to use
flutter_sha256: The Flutter SHA256 for this CIPD bucket
dart_linux_sha256: The Dart Linux SHA256 for this CIPD bucket
dart_mac_sha256: The Dart Mac SHA256 for this CIPD bucket
"""
# Download and instantiate the Flutter toolchain
_instantiate_from_cipd_bucket(
name = "flutter_sdk",
url = _flutter_sdk_url(flutter_tag),
sha256 = flutter_sha256,
display_name = "Flutter SDK",
template = Label("@rules_fuchsia//flutter/private:flutter_sdk_repository_template.BUILD"),
)
native.register_toolchains("@flutter_sdk//:flutter_toolchain")
# Download and instantiate the Dart toolchain
_instantiate_from_cipd_bucket(
name = "dart_linux_sdk",
url = _dart_sdk_url("linux", dart_tag),
sha256 = dart_linux_sha256,
display_name = "Dart Linux SDK",
template = Label("@rules_fuchsia//flutter/private:dart_sdk_repository_template.BUILD"),
)
native.register_toolchains("@dart_linux_sdk//:dart_linux_toolchain")
_instantiate_from_cipd_bucket(
name = "dart_mac_sdk",
url = _dart_sdk_url("mac", dart_tag),
sha256 = dart_mac_sha256,
display_name = "Dart Mac SDK",
template = Label("@rules_fuchsia//flutter/private:dart_sdk_repository_template.BUILD"),
)
native.register_toolchains("@dart_mac_sdk//:dart_mac_toolchain")