forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workspace_deps.bzl
145 lines (136 loc) · 5.92 KB
/
workspace_deps.bzl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""WORKSPACE default repository definitions."""
WORKSPACE_REPOS = {
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/cc_configure.WORKSPACE.
# Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE.
# Used in src/test/java/com/google/devtools/build/lib/blackbox/framework/blackbox.WORKSAPCE
"rules_cc": {
"archive": "rules_cc-0.0.10.tar.gz",
"sha256": "65b67b81c6da378f136cc7e7e14ee08d5b9375973427eceb8c773a4f69fa7e49",
"urls": ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.10/rules_cc-0.0.10.tar.gz"],
"strip_prefix": "rules_cc-0.0.10",
},
"rules_java": {
"archive": "rules_java-7.12.1.tar.gz",
"sha256": "dfbadbb37a79eb9e1cc1e156ecb8f817edf3899b28bc02410a6c1eb88b1a6862",
"urls": ["https://github.com/bazelbuild/rules_java/releases/download/7.12.1/rules_java-7.12.1.tar.gz"],
},
"bazel_skylib": {
"archive": "bazel-skylib-1.6.1.tar.gz",
"sha256": "9f38886a40548c6e96c106b752f242130ee11aaa068a56ba7e56f4511f33e4f2",
"urls": ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.6.1/bazel-skylib-1.6.1.tar.gz"],
},
"rules_license": {
"archive": "rules_license-0.0.7.tar.gz",
"sha256": "4531deccb913639c30e5c7512a054d5d875698daeb75d8cf90f284375fe7c360",
"urls": ["https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz"],
},
"rules_python": {
"archive": "rules_python-0.36.0.tar.gz",
"sha256": "ca77768989a7f311186a29747e3e95c936a41dffac779aff6b443db22290d913",
"strip_prefix": "rules_python-0.36.0",
"urls": ["https://github.com/bazelbuild/rules_python/releases/download/0.36.0/rules_python-0.36.0.tar.gz"],
},
"rules_pkg": {
"archive": "rules_pkg-0.9.1.tar.gz",
"sha256": "8f9ee2dc10c1ae514ee599a8b42ed99fa262b757058f65ad3c384289ff70c4b8",
"urls": ["https://github.com/bazelbuild/rules_pkg/releases/download/0.9.1/rules_pkg-0.9.1.tar.gz"],
},
"rules_testing": {
"archive": "rules_testing-v0.6.0.tar.gz",
"sha256": "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
"strip_prefix": "rules_testing-0.6.0",
"urls": ["https://github.com/bazelbuild/rules_testing/releases/download/v0.6.0/rules_testing-v0.6.0.tar.gz"],
},
"remote_coverage_tools": {
"archive": "coverage_output_generator-v2.6.zip",
"sha256": "7006375f6756819b7013ca875eab70a541cf7d89142d9c511ed78ea4fefa38af",
"urls": ["https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.6.zip"],
},
}
def _gen_workspace_stanza_impl(ctx):
if ctx.attr.template and (ctx.attr.preamble or ctx.attr.postamble):
fail("Can not use template with either preamble or postamble")
if ctx.attr.use_maybe and ctx.attr.repo_clause:
fail("Can not use use_maybe with repo_clause")
if ctx.attr.use_maybe:
repo_clause = """
maybe(
http_archive,
name = "{repo}",
sha256 = "{sha256}",
strip_prefix = {strip_prefix},
urls = {urls},
)
"""
elif ctx.attr.repo_clause:
repo_clause = ctx.attr.repo_clause
else:
repo_clause = """
http_archive(
name = "{repo}",
sha256 = "{sha256}",
strip_prefix = {strip_prefix},
urls = {urls},
)
"""
repo_stanzas = {}
for repo in ctx.attr.repos:
info = WORKSPACE_REPOS[repo]
strip_prefix = info.get("strip_prefix")
if strip_prefix:
strip_prefix = "\"%s\"" % strip_prefix
else:
strip_prefix = "None"
repo_stanzas["{%s}" % repo] = repo_clause.format(
repo = repo,
sha256 = str(info["sha256"]),
strip_prefix = strip_prefix,
urls = info["urls"],
)
if ctx.attr.template:
ctx.actions.expand_template(
output = ctx.outputs.out,
template = ctx.file.template,
substitutions = repo_stanzas,
)
else:
content = "\n".join([p.strip() for p in ctx.attr.preamble.strip().split("\n")])
content += "\n"
content += "".join(repo_stanzas.values())
content += "\n"
content += "\n".join([p.strip() for p in ctx.attr.postamble.strip().split("\n")])
content += "\n"
ctx.actions.write(ctx.outputs.out, content)
return [DefaultInfo(files = depset([ctx.outputs.out]))]
gen_workspace_stanza = rule(
attrs = {
"repos": attr.string_list(doc = "Set of repos to include."),
"out": attr.output(mandatory = True),
"preamble": attr.string(doc = "Preamble."),
"postamble": attr.string(doc = "Set of rules to follow repos."),
"template": attr.label(
doc = "Template WORKSPACE file. May not be used with preamble or postamble." +
"Repo stanzas can be included using the syntax '{repo name}'.",
allow_single_file = True,
mandatory = False,
),
"use_maybe": attr.bool(doc = "Use maybe() invocation instead of http_archive."),
"repo_clause": attr.string(doc = "Use a custom clause for each repository."),
},
doc = "Use specifications from WORKSPACE_REPOS to generate WORKSPACE http_archive stanzas or to" +
"drop them into a template.",
implementation = _gen_workspace_stanza_impl,
)