def workspace_content()

in pkg/releasing/release_tools.py [0:0]


def workspace_content(
    url,
    repo,
    sha256,
    deps_method=None,
    mirror_url=None,
    rename_repo=None,
    setup_file=None,
    toolchains_method=None):
  # Create the WORKSPACE stanza needed for this rule set.
  if setup_file and not (deps_method or toolchains_method):
    print(
        'setup_file can only be set if at least one of (deps_method, toolchains_method) is set.',
        flush=True,
        file=sys.stderr,
    )
    sys.exit(1)

  methods = []
  if deps_method:
    methods.append(deps_method)
  if toolchains_method:
    methods.append(toolchains_method)

  # If the github repo has a '-' in the name, that breaks bazel unless we remove
  # it or change it to an '_'
  repo = rename_repo or repo
  repo = repo.replace('-', '_')
  # Correct the common mistake of not putting a ':' in your setup file name
  if setup_file and ':' not in setup_file:
    setup_file = ':' + setup_file
  if mirror_url:
    # this could be more elegant
    urls = '"%s",\n        "%s"' % (mirror_url, url)
  else:
    urls = '"%s"' % url
  ret = WORKSPACE_STANZA_TEMPLATE.substitute({
      'urls': urls,
      'sha256': sha256,
      'repo': repo,
  })
  if methods:
    deps = DEPS_STANZA_TEMPLATE.substitute({
        'repo': repo,
        'setup_file': setup_file or ':deps.bzl',
        'to_load': ', '.join('"%s"' % m for m in methods),
    })
    ret += '\n%s\n' % deps

  for m in methods:
    ret += '%s()\n' % m

  return ret