Skip to content
This repository was archived by the owner on Sep 15, 2021. It is now read-only.

Commit 4ea7b82

Browse files
authored
Overhaul workspace file to use only a single setup function (#129)
1 parent 7a08959 commit 4ea7b82

File tree

4 files changed

+148
-155
lines changed

4 files changed

+148
-155
lines changed

WORKSPACE

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,7 @@
11
workspace(name = "io_bazel_skydoc")
2-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
42

5-
git_repository(
6-
name = "io_bazel_rules_sass",
7-
remote = "https://github.com/bazelbuild/rules_sass.git",
8-
tag = "1.15.1",
9-
)
10-
git_repository(
11-
name = "bazel_skylib",
12-
remote = "https://github.com/bazelbuild/bazel-skylib.git",
13-
tag = "0.6.0",
14-
)
15-
# Using bazel_skylib 0.6.0 requires at least version 0.16.2 of rules_nodejs.
16-
# (rules_sass depends on rules_nodejs, and but the current rules_sass version
17-
# depends on an older version of rule_nodejs.)
18-
# TODO: Remove this direct dependency when rules_sass can be updated.
19-
git_repository(
20-
name = "build_bazel_rules_nodejs",
21-
remote = "https://github.com/bazelbuild/rules_nodejs.git",
22-
tag = "0.16.2",
23-
)
24-
git_repository(
25-
name = "io_bazel",
26-
remote = "https://github.com/bazelbuild/bazel.git",
27-
# TODO: Update to a newer tagged version when available.
28-
commit = "e7ebb7e68d35ae090d91fe6b4c92c1c831421faa", # 2018-11-26
29-
)
30-
# Required by @io_bazel.
31-
# Note that @protobuf is already created in skydoc_repositories().
32-
# Maybe keep this in sync with that.
33-
git_repository(
34-
name = "com_google_protobuf",
35-
remote = "https://github.com/protocolbuffers/protobuf.git",
36-
# Latest tagged version at time of writing is v3.6.1, which doesn't
37-
# include fixes for --incompatible_package_name_is_a_function,
38-
# --incompatible_new_actions_api, and possibly others.
39-
# TODO: Update to a newer tagged version when available.
40-
commit = "7b28271a61a3da0a37f6fda399b0c4c86464e5b3", # 2018-11-16
41-
)
3+
load(":setup.bzl", "skydoc_repositories")
4+
skydoc_repositories()
425

436
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
447
rules_sass_dependencies()
@@ -48,6 +11,3 @@ node_repositories()
4811

4912
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
5013
sass_repositories()
51-
52-
load("//skylark:skylark.bzl", "skydoc_repositories")
53-
skydoc_repositories()

setup.bzl

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
2+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
3+
4+
def _include_if_not_defined(repo_rule, name, **kwargs):
5+
if name not in native.existing_rules():
6+
repo_rule(name = name, **kwargs)
7+
8+
JINJA2_BUILD_FILE = """
9+
py_library(
10+
name = "jinja2",
11+
srcs = glob(["jinja2/*.py"]),
12+
srcs_version = "PY2AND3",
13+
deps = [
14+
"@markupsafe_archive//:markupsafe",
15+
],
16+
visibility = ["//visibility:public"],
17+
)
18+
"""
19+
20+
MARKUPSAFE_BUILD_FILE = """
21+
py_library(
22+
name = "markupsafe",
23+
srcs = glob(["markupsafe/*.py"]),
24+
srcs_version = "PY2AND3",
25+
visibility = ["//visibility:public"],
26+
)
27+
"""
28+
29+
MISTUNE_BUILD_FILE = """
30+
py_library(
31+
name = "mistune",
32+
srcs = ["mistune.py"],
33+
srcs_version = "PY2AND3",
34+
visibility = ["//visibility:public"],
35+
)
36+
"""
37+
38+
SIX_BUILD_FILE = """
39+
py_library(
40+
name = "six",
41+
srcs = ["six.py"],
42+
srcs_version = "PY2AND3",
43+
visibility = ["//visibility:public"],
44+
)
45+
"""
46+
47+
def skydoc_repositories():
48+
"""Adds the external repositories used by the skylark rules."""
49+
_include_if_not_defined(
50+
git_repository,
51+
name = "bazel_skylib",
52+
remote = "https://github.com/bazelbuild/bazel-skylib.git",
53+
tag = "0.6.0",
54+
)
55+
_include_if_not_defined(
56+
git_repository,
57+
name = "io_bazel_rules_sass",
58+
remote = "https://github.com/bazelbuild/rules_sass.git",
59+
tag = "1.15.1",
60+
)
61+
_include_if_not_defined(
62+
git_repository,
63+
name = "io_bazel_rules_sass",
64+
remote = "https://github.com/bazelbuild/rules_sass.git",
65+
tag = "1.15.1",
66+
)
67+
_include_if_not_defined(
68+
git_repository,
69+
name = "io_bazel",
70+
remote = "https://github.com/bazelbuild/bazel.git",
71+
# TODO: Update to a newer tagged version when available.
72+
commit = "e7ebb7e68d35ae090d91fe6b4c92c1c831421faa", # 2018-11-26
73+
)
74+
_include_if_not_defined(
75+
git_repository,
76+
name = "com_google_protobuf",
77+
remote = "https://github.com/protocolbuffers/protobuf.git",
78+
# Latest tagged version at time of writing is v3.6.1, which doesn't
79+
# include fixes for --incompatible_package_name_is_a_function,
80+
# --incompatible_new_actions_api, and possibly others.
81+
# TODO: Update to a newer tagged version when available.
82+
commit = "7b28271a61a3da0a37f6fda399b0c4c86464e5b3", # 2018-11-16
83+
)
84+
_include_if_not_defined(
85+
git_repository,
86+
name = "io_bazel_rules_sass",
87+
remote = "https://github.com/bazelbuild/rules_sass.git",
88+
tag = "1.15.1",
89+
)
90+
91+
_include_if_not_defined(
92+
http_archive,
93+
name = "markupsafe_archive",
94+
urls = ["https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.23.tar.gz#md5=f5ab3deee4c37cd6a922fb81e730da6e"],
95+
sha256 = "a4ec1aff59b95a14b45eb2e23761a0179e98319da5a7eb76b56ea8cdc7b871c3",
96+
build_file_content = MARKUPSAFE_BUILD_FILE,
97+
strip_prefix = "MarkupSafe-0.23",
98+
)
99+
native.bind(
100+
name = "markupsafe",
101+
actual = "@markupsafe_archive//:markupsafe",
102+
)
103+
104+
_include_if_not_defined(
105+
http_archive,
106+
name = "jinja2_archive",
107+
urls = ["https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.8.tar.gz#md5=edb51693fe22c53cee5403775c71a99e"],
108+
sha256 = "bc1ff2ff88dbfacefde4ddde471d1417d3b304e8df103a7a9437d47269201bf4",
109+
build_file_content = JINJA2_BUILD_FILE,
110+
strip_prefix = "Jinja2-2.8",
111+
)
112+
native.bind(
113+
name = "jinja2",
114+
actual = "@jinja2_archive//:jinja2",
115+
)
116+
117+
_include_if_not_defined(
118+
http_archive,
119+
name = "mistune_archive",
120+
urls = ["https://pypi.python.org/packages/source/m/mistune/mistune-0.7.1.tar.gz#md5=057bc28bf629d6a1283d680a34ed9d0f"],
121+
sha256 = "6076dedf768348927d991f4371e5a799c6a0158b16091df08ee85ee231d929a7",
122+
build_file_content = MISTUNE_BUILD_FILE,
123+
strip_prefix = "mistune-0.7.1",
124+
)
125+
native.bind(
126+
name = "mistune",
127+
actual = "@mistune_archive//:mistune",
128+
)
129+
130+
_include_if_not_defined(
131+
http_archive,
132+
name = "six_archive",
133+
urls = ["https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55"],
134+
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
135+
build_file_content = SIX_BUILD_FILE,
136+
strip_prefix = "six-1.10.0",
137+
)
138+
native.bind(
139+
name = "six",
140+
actual = "@six_archive//:six",
141+
)

skydoc/BUILD

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ licenses(["notice"]) # Apache 2.0
22

33
package(default_visibility = ["//visibility:public"])
44

5-
load("@protobuf//:protobuf.bzl", "py_proto_library")
5+
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
66

77
py_proto_library(
88
name = "build_pb_py",
99
srcs = ["build.proto"],
10-
default_runtime = "@protobuf//:protobuf_python",
11-
protoc = "@protobuf//:protoc",
10+
default_runtime = "@com_google_protobuf//:protobuf_python",
11+
protoc = "@com_google_protobuf//:protoc",
1212
)
1313

1414
py_library(

skylark/skylark.bzl

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
1818
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1919
load("@bazel_skylib//:bzl_library.bzl", "StarlarkLibraryInfo")
20+
load("//:setup.bzl", _skydoc_repositories="skydoc_repositories")
2021

2122
_SKYLARK_FILETYPE = [".bzl"]
2223

@@ -170,113 +171,4 @@ Example:
170171
a set of HTML pages that is ready to be served, set `format = "html"`.
171172
"""
172173

173-
JINJA2_BUILD_FILE = """
174-
py_library(
175-
name = "jinja2",
176-
srcs = glob(["jinja2/*.py"]),
177-
srcs_version = "PY2AND3",
178-
deps = [
179-
"@markupsafe_archive//:markupsafe",
180-
],
181-
visibility = ["//visibility:public"],
182-
)
183-
"""
184-
185-
MARKUPSAFE_BUILD_FILE = """
186-
py_library(
187-
name = "markupsafe",
188-
srcs = glob(["markupsafe/*.py"]),
189-
srcs_version = "PY2AND3",
190-
visibility = ["//visibility:public"],
191-
)
192-
"""
193-
194-
MISTUNE_BUILD_FILE = """
195-
py_library(
196-
name = "mistune",
197-
srcs = ["mistune.py"],
198-
srcs_version = "PY2AND3",
199-
visibility = ["//visibility:public"],
200-
)
201-
"""
202-
203-
SIX_BUILD_FILE = """
204-
py_library(
205-
name = "six",
206-
srcs = ["six.py"],
207-
srcs_version = "PY2AND3",
208-
visibility = ["//visibility:public"],
209-
)
210-
"""
211-
212-
def skydoc_repositories():
213-
"""Adds the external repositories used by the skylark rules."""
214-
git_repository(
215-
name = "protobuf",
216-
remote = "https://github.com/protocolbuffers/protobuf.git",
217-
# Latest tagged version at time of writing is v3.6.1, which doesn't
218-
# include fixes for --incompatible_package_name_is_a_function,
219-
# --incompatible_new_actions_api, and possibly others.
220-
# TODO: Update to a newer tagged version when available.
221-
commit = "7b28271a61a3da0a37f6fda399b0c4c86464e5b3", # 2018-11-16
222-
)
223-
224-
# Protobuf expects an //external:python_headers label which would contain the
225-
# Python headers if fast Python protos is enabled. Since we are not using fast
226-
# Python protos, bind python_headers to a dummy target.
227-
native.bind(
228-
name = "python_headers",
229-
actual = "//:dummy",
230-
)
231-
232-
http_archive(
233-
name = "markupsafe_archive",
234-
urls = ["https://pypi.python.org/packages/source/M/MarkupSafe/MarkupSafe-0.23.tar.gz#md5=f5ab3deee4c37cd6a922fb81e730da6e"],
235-
sha256 = "a4ec1aff59b95a14b45eb2e23761a0179e98319da5a7eb76b56ea8cdc7b871c3",
236-
build_file_content = MARKUPSAFE_BUILD_FILE,
237-
strip_prefix = "MarkupSafe-0.23",
238-
)
239-
240-
native.bind(
241-
name = "markupsafe",
242-
actual = "@markupsafe_archive//:markupsafe",
243-
)
244-
245-
http_archive(
246-
name = "jinja2_archive",
247-
urls = ["https://pypi.python.org/packages/source/J/Jinja2/Jinja2-2.8.tar.gz#md5=edb51693fe22c53cee5403775c71a99e"],
248-
sha256 = "bc1ff2ff88dbfacefde4ddde471d1417d3b304e8df103a7a9437d47269201bf4",
249-
build_file_content = JINJA2_BUILD_FILE,
250-
strip_prefix = "Jinja2-2.8",
251-
)
252-
253-
native.bind(
254-
name = "jinja2",
255-
actual = "@jinja2_archive//:jinja2",
256-
)
257-
258-
http_archive(
259-
name = "mistune_archive",
260-
urls = ["https://pypi.python.org/packages/source/m/mistune/mistune-0.7.1.tar.gz#md5=057bc28bf629d6a1283d680a34ed9d0f"],
261-
sha256 = "6076dedf768348927d991f4371e5a799c6a0158b16091df08ee85ee231d929a7",
262-
build_file_content = MISTUNE_BUILD_FILE,
263-
strip_prefix = "mistune-0.7.1",
264-
)
265-
266-
native.bind(
267-
name = "mistune",
268-
actual = "@mistune_archive//:mistune",
269-
)
270-
271-
http_archive(
272-
name = "six_archive",
273-
urls = ["https://pypi.python.org/packages/source/s/six/six-1.10.0.tar.gz#md5=34eed507548117b2ab523ab14b2f8b55"],
274-
sha256 = "105f8d68616f8248e24bf0e9372ef04d3cc10104f1980f54d57b2ce73a5ad56a",
275-
build_file_content = SIX_BUILD_FILE,
276-
strip_prefix = "six-1.10.0",
277-
)
278-
279-
native.bind(
280-
name = "six",
281-
actual = "@six_archive//:six",
282-
)
174+
skydoc_repositories = _skydoc_repositories

0 commit comments

Comments
 (0)