Sergiusz Bazanski | e03c217 | 2020-02-15 01:04:38 +0100 | [diff] [blame] | 1 | def _gen_imports_impl(ctx): |
| 2 | ctx.file("BUILD", "") |
| 3 | |
Sergiusz Bazanski | c5a77b8 | 2020-02-17 23:04:35 +0100 | [diff] [blame] | 4 | if "hscloud_root" not in ctx.os.environ: |
| 5 | fail("Please souce env.sh") |
| 6 | |
| 7 | is_nixos = "hscloud_nixos" in ctx.os.environ |
Sergiusz Bazanski | e03c217 | 2020-02-15 01:04:38 +0100 | [diff] [blame] | 8 | bzl_file_content = """ |
| 9 | load( |
| 10 | "@io_bazel_rules_go//go:deps.bzl", |
| 11 | "go_register_toolchains", |
| 12 | "go_rules_dependencies", |
| 13 | ) |
| 14 | def load_go_sdk(): |
| 15 | go_rules_dependencies() |
| 16 | go_register_toolchains({go_version}) |
| 17 | """.format( |
| 18 | go_version = 'go_version = "host"' if is_nixos else "", |
| 19 | ) |
| 20 | |
| 21 | ctx.file("imports.bzl", bzl_file_content) |
| 22 | |
| 23 | _gen_imports = repository_rule( |
| 24 | implementation = _gen_imports_impl, |
| 25 | attrs = dict(), |
| 26 | ) |
| 27 | |
| 28 | def gen_imports(name): |
| 29 | _gen_imports( |
| 30 | name = name, |
| 31 | ) |