Skip to content

Commit 48b2f6a

Browse files
committed
Don't import rules with a conflicting definition.
This avoids manual `excludes=[]` and `overrides={}`, which were suggested in the linked issues. We exclude things that have already been imported, so to override them, simply import them before `docker_repositories()` and the exclusion logic will handle the rest. Fixes: bazelbuild#55 Fixes: bazelbuild#77
1 parent 48a438c commit 48b2f6a

File tree

1 file changed

+70
-56
lines changed

1 file changed

+70
-56
lines changed

docker/docker.bzl

+70-56
Original file line numberDiff line numberDiff line change
@@ -32,53 +32,62 @@ CONTAINERREGISTRY_RELEASE = "v0.0.11"
3232

3333
def docker_repositories():
3434
"""Download dependencies of docker rules."""
35-
native.http_file(
36-
name = "puller",
37-
url = ("https://storage.googleapis.com/containerregistry-releases/" +
38-
CONTAINERREGISTRY_RELEASE + "/puller.par"),
39-
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
40-
executable = True,
41-
)
35+
excludes = native.existing_rules().keys()
4236

43-
native.http_file(
44-
name = "pusher",
45-
url = ("https://storage.googleapis.com/containerregistry-releases/" +
46-
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
47-
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
48-
executable = True,
49-
)
37+
if "puller" not in excludes:
38+
native.http_file(
39+
name = "puller",
40+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
41+
CONTAINERREGISTRY_RELEASE + "/puller.par"),
42+
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
43+
executable = True,
44+
)
5045

51-
native.git_repository(
52-
name = "containerregistry",
53-
remote = "https://github.com/google/containerregistry.git",
54-
tag = CONTAINERREGISTRY_RELEASE,
55-
)
46+
if "pusher" not in excludes:
47+
native.http_file(
48+
name = "pusher",
49+
url = ("https://storage.googleapis.com/containerregistry-releases/" +
50+
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
51+
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
52+
executable = True,
53+
)
54+
55+
if "containerregistry" not in excludes:
56+
native.git_repository(
57+
name = "containerregistry",
58+
remote = "https://github.com/google/containerregistry.git",
59+
tag = CONTAINERREGISTRY_RELEASE,
60+
)
5661

5762
# TODO(mattmoor): Remove all of this (copied from google/containerregistry)
5863
# once transitive workspace instantiation lands.
59-
native.new_http_archive(
60-
name = "httplib2",
61-
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
62-
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
63-
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
64-
type = "tar.gz",
65-
build_file_content = """
64+
if "httplib2" not in excludes:
65+
# TODO(mattmoor): Is there a clean way to override?
66+
native.new_http_archive(
67+
name = "httplib2",
68+
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
69+
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
70+
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
71+
type = "tar.gz",
72+
build_file_content = """
6673
py_library(
6774
name = "httplib2",
6875
srcs = glob(["**/*.py"]),
6976
data = ["cacerts.txt"],
7077
visibility = ["//visibility:public"]
7178
)""",
72-
)
79+
)
7380

7481
# Used by oauth2client
75-
native.new_http_archive(
76-
name = "six",
77-
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
78-
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
79-
strip_prefix = "six-1.9.0/",
80-
type = "tar.gz",
81-
build_file_content = """
82+
if "six" not in excludes:
83+
# TODO(mattmoor): Is there a clean way to override?
84+
native.new_http_archive(
85+
name = "six",
86+
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
87+
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
88+
strip_prefix = "six-1.9.0/",
89+
type = "tar.gz",
90+
build_file_content = """
8291
# Rename six.py to __init__.py
8392
genrule(
8493
name = "rename",
@@ -91,16 +100,18 @@ py_library(
91100
srcs = [":__init__.py"],
92101
visibility = ["//visibility:public"],
93102
)"""
94-
)
103+
)
95104

96105
# Used for authentication in containerregistry
97-
native.new_http_archive(
98-
name = "oauth2client",
99-
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
100-
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
101-
strip_prefix = "oauth2client-4.0.0/oauth2client/",
102-
type = "tar.gz",
103-
build_file_content = """
106+
if "oauth2client" not in excludes:
107+
# TODO(mattmoor): Is there a clean way to override?
108+
native.new_http_archive(
109+
name = "oauth2client",
110+
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
111+
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
112+
strip_prefix = "oauth2client-4.0.0/oauth2client/",
113+
type = "tar.gz",
114+
build_file_content = """
104115
py_library(
105116
name = "oauth2client",
106117
srcs = glob(["**/*.py"]),
@@ -110,26 +121,29 @@ py_library(
110121
"@six//:six",
111122
]
112123
)"""
113-
)
124+
)
114125

115126
# Used for parallel execution in containerregistry
116-
native.new_http_archive(
117-
name = "concurrent",
118-
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
119-
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
120-
strip_prefix = "pythonfutures-3.0.5/concurrent/",
121-
type = "tar.gz",
122-
build_file_content = """
127+
if "concurrent" not in excludes:
128+
# TODO(mattmoor): Is there a clean way to override?
129+
native.new_http_archive(
130+
name = "concurrent",
131+
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
132+
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
133+
strip_prefix = "pythonfutures-3.0.5/concurrent/",
134+
type = "tar.gz",
135+
build_file_content = """
123136
py_library(
124137
name = "concurrent",
125138
srcs = glob(["**/*.py"]),
126139
visibility = ["//visibility:public"]
127140
)"""
128-
)
141+
)
129142

130143
# For packaging python tools.
131-
native.git_repository(
132-
name = "subpar",
133-
remote = "https://github.com/google/subpar",
134-
commit = "7e12cc130eb8f09c8cb02c3585a91a4043753c56",
135-
)
144+
if "subpar" not in excludes:
145+
native.git_repository(
146+
name = "subpar",
147+
remote = "https://github.com/google/subpar",
148+
commit = "7e12cc130eb8f09c8cb02c3585a91a4043753c56",
149+
)

0 commit comments

Comments
 (0)