Skip to content

Commit

Permalink
Don't import rules with a conflicting definition.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattmoor committed Jul 3, 2017
1 parent 48a438c commit 48b2f6a
Showing 1 changed file with 70 additions and 56 deletions.
126 changes: 70 additions & 56 deletions docker/docker.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,53 +32,62 @@ CONTAINERREGISTRY_RELEASE = "v0.0.11"

def docker_repositories():
"""Download dependencies of docker rules."""
native.http_file(
name = "puller",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/puller.par"),
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
executable = True,
)
excludes = native.existing_rules().keys()

native.http_file(
name = "pusher",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
executable = True,
)
if "puller" not in excludes:
native.http_file(
name = "puller",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/puller.par"),
sha256 = "90a76d01ee57a5df7353a533c96966822c9efda61636c11eac11344171556017",
executable = True,
)

native.git_repository(
name = "containerregistry",
remote = "https://github.com/google/containerregistry.git",
tag = CONTAINERREGISTRY_RELEASE,
)
if "pusher" not in excludes:
native.http_file(
name = "pusher",
url = ("https://storage.googleapis.com/containerregistry-releases/" +
CONTAINERREGISTRY_RELEASE + "/pusher.par"),
sha256 = "1989ceb41144784dccb3476cea5b5f1bef112bb0aae56544b9c56572894c38ab",
executable = True,
)

if "containerregistry" not in excludes:
native.git_repository(
name = "containerregistry",
remote = "https://github.com/google/containerregistry.git",
tag = CONTAINERREGISTRY_RELEASE,
)

# TODO(mattmoor): Remove all of this (copied from google/containerregistry)
# once transitive workspace instantiation lands.
native.new_http_archive(
name = "httplib2",
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
type = "tar.gz",
build_file_content = """
if "httplib2" not in excludes:
# TODO(mattmoor): Is there a clean way to override?
native.new_http_archive(
name = "httplib2",
url = "https://codeload.github.com/httplib2/httplib2/tar.gz/v0.10.3",
sha256 = "d1bee28a68cc665c451c83d315e3afdbeb5391f08971dcc91e060d5ba16986f1",
strip_prefix = "httplib2-0.10.3/python2/httplib2/",
type = "tar.gz",
build_file_content = """
py_library(
name = "httplib2",
srcs = glob(["**/*.py"]),
data = ["cacerts.txt"],
visibility = ["//visibility:public"]
)""",
)
)

# Used by oauth2client
native.new_http_archive(
name = "six",
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
strip_prefix = "six-1.9.0/",
type = "tar.gz",
build_file_content = """
if "six" not in excludes:
# TODO(mattmoor): Is there a clean way to override?
native.new_http_archive(
name = "six",
url = "https://pypi.python.org/packages/source/s/six/six-1.9.0.tar.gz",
sha256 = "e24052411fc4fbd1f672635537c3fc2330d9481b18c0317695b46259512c91d5",
strip_prefix = "six-1.9.0/",
type = "tar.gz",
build_file_content = """
# Rename six.py to __init__.py
genrule(
name = "rename",
Expand All @@ -91,16 +100,18 @@ py_library(
srcs = [":__init__.py"],
visibility = ["//visibility:public"],
)"""
)
)

# Used for authentication in containerregistry
native.new_http_archive(
name = "oauth2client",
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
strip_prefix = "oauth2client-4.0.0/oauth2client/",
type = "tar.gz",
build_file_content = """
if "oauth2client" not in excludes:
# TODO(mattmoor): Is there a clean way to override?
native.new_http_archive(
name = "oauth2client",
url = "https://codeload.github.com/google/oauth2client/tar.gz/v4.0.0",
sha256 = "7230f52f7f1d4566a3f9c3aeb5ffe2ed80302843ce5605853bee1f08098ede46",
strip_prefix = "oauth2client-4.0.0/oauth2client/",
type = "tar.gz",
build_file_content = """
py_library(
name = "oauth2client",
srcs = glob(["**/*.py"]),
Expand All @@ -110,26 +121,29 @@ py_library(
"@six//:six",
]
)"""
)
)

# Used for parallel execution in containerregistry
native.new_http_archive(
name = "concurrent",
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
strip_prefix = "pythonfutures-3.0.5/concurrent/",
type = "tar.gz",
build_file_content = """
if "concurrent" not in excludes:
# TODO(mattmoor): Is there a clean way to override?
native.new_http_archive(
name = "concurrent",
url = "https://codeload.github.com/agronholm/pythonfutures/tar.gz/3.0.5",
sha256 = "a7086ddf3c36203da7816f7e903ce43d042831f41a9705bc6b4206c574fcb765",
strip_prefix = "pythonfutures-3.0.5/concurrent/",
type = "tar.gz",
build_file_content = """
py_library(
name = "concurrent",
srcs = glob(["**/*.py"]),
visibility = ["//visibility:public"]
)"""
)
)

# For packaging python tools.
native.git_repository(
name = "subpar",
remote = "https://github.com/google/subpar",
commit = "7e12cc130eb8f09c8cb02c3585a91a4043753c56",
)
if "subpar" not in excludes:
native.git_repository(
name = "subpar",
remote = "https://github.com/google/subpar",
commit = "7e12cc130eb8f09c8cb02c3585a91a4043753c56",
)

0 comments on commit 48b2f6a

Please sign in to comment.