repository_locations_utils.bzl 1.1 KB

1234567891011121314151617181920212223242526
  1. def _format_version(s, version):
  2. return s.format(version = version, dash_version = version.replace(".", "-"), underscore_version = version.replace(".", "_"))
  3. # Generate a "repository location specification" from raw repository
  4. # specification. The information should match the format required by
  5. # external_deps.bzl. This function mostly does interpolation of {version} in
  6. # the repository info fields. This code should be capable of running in both
  7. # Python and Starlark.
  8. def load_repository_locations_spec(repository_locations_spec):
  9. locations = {}
  10. for key, location in repository_locations_spec.items():
  11. mutable_location = dict(location)
  12. locations[key] = mutable_location
  13. # Fixup with version information.
  14. if "version" in location:
  15. if "strip_prefix" in location:
  16. mutable_location["strip_prefix"] = _format_version(location["strip_prefix"], location["version"])
  17. mutable_location["urls"] = [_format_version(url, location["version"]) for url in location["urls"]]
  18. return locations
  19. def merge_dicts(*dicts):
  20. result = {}
  21. for d in dicts:
  22. result.update(d)
  23. return result