Skip to content

Commit a8706cd

Browse files
author
Benjamin Denhartog
committed
refactor: use builtin maybe() from @bazel_tools instead of a custom _maybe macro
1 parent 64cad21 commit a8706cd

File tree

8 files changed

+35
-59
lines changed

8 files changed

+35
-59
lines changed

Diff for: buildozer/deps.bzl

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
22
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
3+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
34

45
def buildozer_dependencies():
5-
_maybe(
6+
maybe(
67
http_archive,
78
name = "bazel_skylib",
89
urls = [
@@ -12,14 +13,10 @@ def buildozer_dependencies():
1213
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
1314
)
1415

15-
_maybe(
16+
maybe(
1617
git_repository,
1718
name = "com_github_bazelbuild_buildtools",
1819
commit = "5bcc31df55ec1de770cb52887f2e989e7068301f", #v0.29.0
1920
remote = "https://github.com/bazelbuild/buildtools.git",
2021
shallow_since = "1568030193 +0200",
2122
)
22-
23-
def _maybe(repo_rule, name, **kwargs):
24-
if name not in native.existing_rules():
25-
repo_rule(name = name, **kwargs)

Diff for: goimports/deps.bzl

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
load("@bazel_gazelle//:deps.bzl", "go_repository")
22
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
34

45
def goimports_dependencies():
5-
_maybe(
6+
maybe(
67
go_repository,
78
name = "org_golang_x_tools",
89
importpath = "golang.org/x/tools",
910
commit = "6de373a2766cf6891613ba19eb8bb06227ba7273", # master, as of 2020-01-02
1011
)
1112

12-
_maybe(
13+
maybe(
1314
http_archive,
1415
name = "bazel_skylib",
1516
urls = [
@@ -18,7 +19,3 @@ def goimports_dependencies():
1819
],
1920
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
2021
)
21-
22-
def _maybe(repo_rule, name, **kwargs):
23-
if name not in native.existing_rules():
24-
repo_rule(name = name, **kwargs)

Diff for: golangcilint/deps.bzl

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
23

34
_DOWNLOAD_URI = (
45
"https://github.com/golangci/golangci-lint/releases/download/v{version}/" +
@@ -55,7 +56,7 @@ _golangcilint_download = repository_rule(
5556
)
5657

5758
def golangcilint_dependencies():
58-
_maybe(
59+
maybe(
5960
http_archive,
6061
name = "bazel_skylib",
6162
urls = [
@@ -67,7 +68,3 @@ def golangcilint_dependencies():
6768
_golangcilint_download(
6869
name = "com_github_atlassian_bazel_tools_golangcilint",
6970
)
70-
71-
def _maybe(repo_rule, name, **kwargs):
72-
if name not in native.existing_rules():
73-
repo_rule(name = name, **kwargs)

Diff for: gometalinter/deps.bzl

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
23

34
_GOMETALINTER_TARBALLS = {
45
"darwin_amd64": (
@@ -42,7 +43,7 @@ _gometalinter_download = repository_rule(
4243
)
4344

4445
def gometalinter_dependencies():
45-
_maybe(
46+
maybe(
4647
http_archive,
4748
name = "bazel_skylib",
4849
urls = [
@@ -54,7 +55,3 @@ def gometalinter_dependencies():
5455
_gometalinter_download(
5556
name = "com_github_atlassian_bazel_tools_gometalinter",
5657
)
57-
58-
def _maybe(repo_rule, name, **kwargs):
59-
if name not in native.existing_rules():
60-
repo_rule(name = name, **kwargs)

Diff for: gorevive/deps.bzl

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,87 @@
11
load("@bazel_gazelle//:deps.bzl", "go_repository")
22
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
45

56
def go_revive_dependencies():
6-
_maybe(
7+
maybe(
78
go_repository,
89
name = "com_github_burntsushi_toml",
910
importpath = "github.com/BurntSushi/toml",
1011
tag = "v0.3.0",
1112
)
1213

13-
_maybe(
14+
maybe(
1415
go_repository,
1516
name = "com_github_fatih_color",
1617
importpath = "github.com/fatih/color",
1718
tag = "v1.7.0",
1819
)
1920

20-
_maybe(
21+
maybe(
2122
go_repository,
2223
name = "com_github_fatih_structtag",
2324
importpath = "github.com/fatih/structtag",
2425
tag = "v1.0.0",
2526
)
2627

27-
_maybe(
28+
maybe(
2829
go_repository,
2930
name = "com_github_mattn_go_colorable",
3031
importpath = "github.com/mattn/go-colorable",
3132
tag = "v0.0.9",
3233
)
3334

34-
_maybe(
35+
maybe(
3536
go_repository,
3637
name = "com_github_mattn_go_isatty",
3738
importpath = "github.com/mattn/go-isatty",
3839
tag = "v0.0.4",
3940
)
4041

41-
_maybe(
42+
maybe(
4243
go_repository,
4344
name = "com_github_mattn_go_runewidth",
4445
importpath = "github.com/mattn/go-runewidth",
4546
tag = "v0.0.3",
4647
)
4748

48-
_maybe(
49+
maybe(
4950
go_repository,
5051
name = "com_github_mgechev_dots",
5152
commit = "8e09d8ea2757",
5253
importpath = "github.com/mgechev/dots",
5354
)
5455

55-
_maybe(
56+
maybe(
5657
go_repository,
5758
name = "com_github_olekukonko_tablewriter",
5859
commit = "be2c049b30cc",
5960
importpath = "github.com/olekukonko/tablewriter",
6061
)
6162

62-
_maybe(
63+
maybe(
6364
go_repository,
6465
name = "com_github_pkg_errors",
6566
importpath = "github.com/pkg/errors",
6667
tag = "v0.8.0",
6768
)
6869

69-
_maybe(
70+
maybe(
7071
go_repository,
7172
name = "org_golang_x_sys",
7273
commit = "d0be0721c37e",
7374
importpath = "golang.org/x/sys",
7475
)
7576

76-
_maybe(
77+
maybe(
7778
go_repository,
7879
name = "org_golang_x_tools",
7980
commit = "bf090417da8b6150dcfe96795325f5aa78fff718",
8081
importpath = "golang.org/x/tools",
8182
)
8283

83-
_maybe(
84+
maybe(
8485
http_archive,
8586
name = "bazel_skylib",
8687
urls = [
@@ -90,14 +91,10 @@ def go_revive_dependencies():
9091
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
9192
)
9293

93-
_maybe(
94+
maybe(
9495
new_git_repository,
9596
name = "com_github_mgechev_revive",
9697
commit = "b4cc152955fbbcd2afafd5df3d46393d621a7fdf",
9798
remote = "https://github.com/mgechev/revive.git",
9899
build_file = "@com_github_atlassian_bazel_tools//gorevive:revive.BUILD.bazel",
99100
)
100-
101-
def _maybe(repo_rule, name, **kwargs):
102-
if name not in native.existing_rules():
103-
repo_rule(name = name, **kwargs)

Diff for: gotemplate/deps.bzl

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
load("@bazel_gazelle//:deps.bzl", "go_repository")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
23

34
def gotemplate_dependencies():
4-
_maybe(
5+
maybe(
56
go_repository,
67
name = "com_github_ghodss_yaml",
78
commit = "c7ce16629ff4cd059ed96ed06419dd3856fd3577",
89
importpath = "github.com/ghodss/yaml",
910
)
1011

11-
_maybe(
12+
maybe(
1213
go_repository,
1314
name = "in_gopkg_yaml_v2",
1415
commit = "5420a8b6744d3b0345ab293f6fcba19c978f1183",
1516
importpath = "gopkg.in/yaml.v2",
1617
)
17-
18-
def _maybe(repo_rule, name, **kwargs):
19-
if name not in native.existing_rules():
20-
repo_rule(name = name, **kwargs)

Diff for: multirun/deps.bzl

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
23

34
def multirun_dependencies():
4-
_maybe(
5+
maybe(
56
http_archive,
67
name = "bazel_skylib",
78
urls = [
@@ -10,7 +11,3 @@ def multirun_dependencies():
1011
],
1112
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
1213
)
13-
14-
def _maybe(repo_rule, name, **kwargs):
15-
if name not in native.existing_rules():
16-
repo_rule(name = name, **kwargs)

Diff for: rjsone/deps.bzl

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
load("@bazel_gazelle//:deps.bzl", "go_repository")
2+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
23

34
def rjsone_dependencies():
4-
_maybe(
5+
maybe(
56
go_repository,
67
name = "com_github_wryun_rjsone",
78
commit = "a871600de5f3b73007fd8c92e084768b92668877",
89
importpath = "github.com/wryun/rjsone",
910
)
1011

11-
_maybe(
12+
maybe(
1213
go_repository,
1314
name = "com_github_taskcluster_json_e",
1415
commit = "5f1fefda8b07ed0016c98f77cd4640ec8a920201",
1516
importpath = "github.com/taskcluster/json-e",
1617
)
1718

18-
_maybe(
19+
maybe(
1920
go_repository,
2021
name = "com_github_wryun_yaml_1",
2122
commit = "e5213689ab3ec721209263e51f9edf8615d93085",
2223
importpath = "github.com/wryun/yaml-1",
2324
)
2425

25-
_maybe(
26+
maybe(
2627
go_repository,
2728
name = "com_github_imdario_mergo",
2829
commit = "9316a62528ac99aaecb4e47eadd6dc8aa6533d58",
2930
importpath = "github.com/imdario/mergo",
3031
)
3132

32-
_maybe(
33+
maybe(
3334
go_repository,
3435
name = "in_gopkg_yaml_v2",
3536
commit = "5420a8b6744d3b0345ab293f6fcba19c978f1183",
3637
importpath = "gopkg.in/yaml.v2",
3738
)
38-
39-
def _maybe(repo_rule, name, **kwargs):
40-
if name not in native.existing_rules():
41-
repo_rule(name = name, **kwargs)

0 commit comments

Comments
 (0)