text: # Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
  # SPDX-License-Identifier: Apache-2.0
  
  def _impl(ctx):
      # Generates an empty BUILD file, because we do not need to build anything.
      ctx.file(
          "BUILD",
          content = """exports_files(["index.bzl"])""",
          executable = False,
      )
  
      version = ctx.os.environ.get("DAML_SCALA_VERSION", default = "2.12.12")
      suffix = version.replace(".", "_")
  
      major = version[:version.rfind(".")]
      major_suffix = major.replace(".", "_")
      ctx.file(
          "index.bzl",
          content =
              """
  scala_version = "{version}"
  scala_major_version = "{major}"
  scala_version_suffix = "{suffix}"
  scala_major_version_suffix = "{major_suffix}"
  """.format(
                  version = version,
                  major = major,
                  suffix = suffix,
                  major_suffix = major_suffix,
              ),
          executable = False,
      )
  
  scala_version = repository_rule(
      environ = ["DAML_SCALA_VERSION"],
      implementation = _impl,
      attrs = {},
  )
  