forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo.bzl
152 lines (129 loc) · 4.09 KB
/
repo.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
146
147
148
149
150
151
152
# `@envoy_repo` repository rule for managing the repo and querying its metadata.
def _envoy_repo_impl(repository_ctx):
"""This provides information about the Envoy repository
You can access the current project and api versions and the path to the repository in
.bzl/BUILD files as follows:
```starlark
load("@envoy_repo//:version.bzl", "VERSION", "API_VERSION")
```
`*VERSION` can be used to derive version-specific rules and can be passed
to the rules.
The `VERSION`s and also the local `PATH` to the repo can be accessed in
python libraries/binaries. By adding `@envoy_repo` to `deps` they become
importable through the `envoy_repo` namespace.
As the `PATH` is local to the machine, it is generally only useful for
jobs that will run locally.
This can be useful, for example, for bazel run jobs to run bazel queries that cannot be run
within the constraints of a `genquery`, or that otherwise need access to the repository
files.
Project and repo data can be accessed in JSON format using `@envoy_repo//:project`, eg:
```starlark
load("@aspect_bazel_lib//lib:jq.bzl", "jq")
jq(
name = "project_version",
srcs = ["@envoy_repo//:data"],
out = "version.txt",
args = ["-r"],
filter = ".version",
)
```
"""
repo_version_path = repository_ctx.path(repository_ctx.attr.envoy_version)
api_version_path = repository_ctx.path(repository_ctx.attr.envoy_api_version)
version = repository_ctx.read(repo_version_path).strip()
api_version = repository_ctx.read(api_version_path).strip()
repository_ctx.file("version.bzl", "VERSION = '%s'\nAPI_VERSION = '%s'" % (version, api_version))
repository_ctx.file("path.bzl", "PATH = '%s'" % repo_version_path.dirname)
repository_ctx.file("__init__.py", "PATH = '%s'\nVERSION = '%s'\nAPI_VERSION = '%s'" % (repo_version_path.dirname, version, api_version))
repository_ctx.file("WORKSPACE", "")
repository_ctx.file("BUILD", '''
load("@rules_python//python:defs.bzl", "py_library")
load("@envoy//tools/base:envoy_python.bzl", "envoy_entry_point")
load("//:path.bzl", "PATH")
py_library(
name = "envoy_repo",
srcs = ["__init__.py"],
visibility = ["//visibility:public"],
)
envoy_entry_point(
name = "get_project_json",
pkg = "envoy.base.utils",
script = "envoy.project_data",
init_data = [":__init__.py"],
)
genrule(
name = "project",
outs = ["project.json"],
cmd = """
$(location :get_project_json) $$(dirname $(location @envoy//:VERSION.txt)) > $@
""",
tools = [
":get_project_json",
"@envoy//:VERSION.txt",
"@envoy//changelogs",
],
visibility = ["//visibility:public"],
)
envoy_entry_point(
name = "release",
args = [
"release",
PATH,
"--release-message-path=$(location @envoy//changelogs:summary)",
],
data = ["@envoy//changelogs:summary"],
pkg = "envoy.base.utils",
script = "envoy.project",
init_data = [":__init__.py"],
)
envoy_entry_point(
name = "dev",
args = [
"dev",
PATH,
],
pkg = "envoy.base.utils",
script = "envoy.project",
init_data = [":__init__.py"],
)
envoy_entry_point(
name = "sync",
args = [
"sync",
PATH,
],
pkg = "envoy.base.utils",
script = "envoy.project",
init_data = [":__init__.py"],
)
envoy_entry_point(
name = "publish",
args = [
"publish",
PATH,
],
pkg = "envoy.base.utils",
script = "envoy.project",
init_data = [":__init__.py"],
)
envoy_entry_point(
name = "trigger",
args = [
"trigger",
PATH,
],
pkg = "envoy.base.utils",
script = "envoy.project",
init_data = [":__init__.py"],
)
''')
_envoy_repo = repository_rule(
implementation = _envoy_repo_impl,
attrs = {
"envoy_version": attr.label(default = "@envoy//:VERSION.txt"),
"envoy_api_version": attr.label(default = "@envoy//:API_VERSION.txt"),
},
)
def envoy_repo():
if "envoy_repo" not in native.existing_rules().keys():
_envoy_repo(name = "envoy_repo")