Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 1 | load("@bazel_gazelle//:deps.bzl", "go_repository") |
| 2 | load("@ci_configure//:ci.bzl", "RUNNING_IN_CI") |
Austin Schuh | 8f99c82 | 2024-05-05 22:43:40 -0700 | [diff] [blame] | 3 | load("//tools/go:go_mirrors.bzl", "GO_MIRROR_INFO") |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 4 | |
Philipp Schrader | 35bb153 | 2023-03-05 13:49:12 -0800 | [diff] [blame] | 5 | def maybe_override_go_dep(name, importpath, sum, version, **kwargs): |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 6 | """This macro selects between our dependency mirrors and upstream sources. |
| 7 | |
| 8 | We want to use the mirrored version whenever possible. In CI we are required |
| 9 | to use the mirrored version. For local development we only use the mirrored |
| 10 | version if it's available. Otherwise we download from the upstream sources. |
| 11 | """ |
| 12 | if not RUNNING_IN_CI: |
| 13 | override_go_dep = not (name in GO_MIRROR_INFO and GO_MIRROR_INFO[name]["version"] == version) |
| 14 | else: |
| 15 | override_go_dep = False |
| 16 | if name not in GO_MIRROR_INFO or GO_MIRROR_INFO[name]["version"] != version: |
| 17 | fail(("The repo {} is not properly mirrored. " + |
| 18 | "Please ask someone with mirroring access for help." + |
| 19 | "They need to 'bazel run //tools/go:mirror_go_repos -- " + |
| 20 | "--ssh_host <software.971spartans.net>'.").format(name)) |
| 21 | |
| 22 | # If we want to use the upstream version and we've already imported a |
| 23 | # mirrored version via mirrored_go_dependencies(), then we override it here |
| 24 | # by giving the upstream version the same name. |
| 25 | if override_go_dep: |
| 26 | go_repository( |
| 27 | name = name, |
| 28 | importpath = importpath, |
| 29 | sum = sum, |
| 30 | version = version, |
Philipp Schrader | 35bb153 | 2023-03-05 13:49:12 -0800 | [diff] [blame] | 31 | **kwargs |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 32 | ) |
| 33 | |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 34 | def mirrored_go_dependencies(): |
| 35 | """Sets up the Go dependencies we've mirrored.""" |
| 36 | for name in GO_MIRROR_INFO: |
| 37 | info = GO_MIRROR_INFO[name] |
Philipp Schrader | 35bb153 | 2023-03-05 13:49:12 -0800 | [diff] [blame] | 38 | kwargs = info.get("kwargs", {}) |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 39 | go_repository( |
| 40 | name = name, |
| 41 | strip_prefix = info["strip_prefix"], |
| 42 | type = "zip", |
| 43 | urls = [ |
Maxwell Henderson | 7a93a65 | 2023-06-24 15:17:09 -0700 | [diff] [blame] | 44 | "https://software.frc971.org/Build-Dependencies/go_deps/" + info["filename"], |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 45 | ], |
| 46 | sha256 = info["sha256"], |
| 47 | importpath = info["importpath"], |
Philipp Schrader | 35bb153 | 2023-03-05 13:49:12 -0800 | [diff] [blame] | 48 | **kwargs |
Philipp Schrader | 37fdbb6 | 2021-12-18 00:30:37 -0800 | [diff] [blame] | 49 | ) |