forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUCK
251 lines (231 loc) · 8.41 KB
/
BUCK
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
load("@buck_bazel_skylib//lib:dicts.bzl", "dicts")
load(
"//tools/build_rules:module_rules.bzl",
"convert_modules_to_external_resources",
"convert_modules_to_resources",
)
load("//tools/build_rules:python_rules.bzl", "interpreter_override_args")
load(":defs.bzl", "get_gen_buck_info_command")
python_library(
name = "subprocutils",
srcs = [
"subprocutils.py",
],
visibility = [
"//programs/...",
"//scripts/...",
],
)
python_library(
name = "buck_version",
srcs = [
"buck_version.py",
"buck_version_mercurial.py",
],
deps = [
":subprocutils",
],
)
python_library(
name = "java_version",
srcs = [
"java_version.py",
],
)
python_binary(
name = "gen_buck_info",
main = "gen_buck_info.py",
visibility = ["PUBLIC"],
deps = [
":buck_version",
":java_version",
],
)
# This is bit weird. This rule isn't idempotent, since it calls out
# to git commands to find repo information -- and this stuff clearly
# isn't enumerated in the inputs of arguments for this rule (which
# would normally add it to the rule key). However, since we're just
# trying to generate the Buck version UID, this should work, since the
# in-repo Buck we're using to build this already implicitly adds the
# same Buck version UID to it's rule key. But still... gross.
#
# For releases, both OSS and not, we accept a number of configuration (-c) options
# and we build in a clean repo anyways, so in those cases it /is/ idempotent.
#
# One downside of this: If you don't rebuild the buck you're building with in between
# runs (say, by using ant), this rule won't re-run, and the --version of your .pex will
# be wrong. The upside of that is that this script can be slow, and for most cases
# skipping that leads to a better developer experience. Unfortunately if one makes
# a lot of changes, then rebuilds buck and tries to run that pex, the old buckd
# won't restart because the versions match. In that case, we have a buck-local rule
# that depends on //programs:buck, which /does/ force VCS info to be regenerated each
# time that buck.pex changes in any substantial way.
# That's what gen_local_buck_package_info and buck-local is for
genrule(
name = "gen_buck_package_info",
out = "buck_package_info.json",
cmd = get_gen_buck_info_command(":gen_buck_info"),
)
genrule(
name = "gen_local_buck_package_info",
# Depend on :buck binary so that we're invalidated and run if buck.pex changes
srcs = [":buck"],
out = "buck_package_info.json",
cmd = get_gen_buck_info_command(":gen_buck_info"),
)
build_type = read_config("build", "type", "LOCAL_PEX")
genrule(
name = "gen_build_type_info",
out = "build_type_info.txt",
bash = "echo {0} > $OUT".format(build_type),
cmd_exe = "echo {0}> %OUT%".format(build_type),
)
# These resources cannot affect the content of build artifacts.
RESOURCES_NOT_AFFECTING_BUILD_ARTIFACTS = {
"android_agent_path": "//assets/android:agent.apk",
"buck_build_type_info": ":gen_build_type_info",
"jacoco_agent_jar": "//third-party/java/jacoco:agent",
"legacy_fix_script": "//programs/fixes/source_only_abi:fix",
# The name of this resource is important, since it needs to have this filename in the PEX.
"libjcocoa.dylib": "//third-party/java/ObjCBridge:libjcocoa.dylib",
"logging_config_file": "//config:logging.properties",
"path_to_isolated_trampoline": "//src/com/facebook/buck/rules/modern/builders:trampoline",
"report_generator_jar": "//src/com/facebook/buck/jvm/java/coverage:report-generator",
"testrunner_classes": "//src/com/facebook/buck/testrunner:testrunner-bin-fixed",
}
# The name of the version info flag. If trying to do a deeper build, we need to ensure
# that we invalidate the version info more often.
RESOURCES_VERSION_INFO_NAME = "buck_package_info"
# These resources contain code that can affect the content of build artifacts.
# This list needs to be updated whenever there are new libraries that can affect build artifacts.
# Failing to do so can result in build artifacts that do not reflect changes in new libraries.
# This logic is used only when Buck is runnig with the config option `cache.use_buck_binary_hash`
# set to True.
RESOURCES_AFFECTING_BUILD_ARTIFACTS = {
"bootstrapper_jar": "//src/com/facebook/buck/cli/bootstrapper:bootstrapper",
"buck_server": "//src/com/facebook/buck/cli:main-fixed",
"buckfilesystem_jar": "//src/com/facebook/buck/core/filesystems:filesystems",
"dx": "//third-party/java/dx:etc_dx",
"native_exopackage_fake_path": "//assets/android:native-exopackage-fakes.apk",
"path_to_pathlib_py": "//third-party/py/pathlib:pathlib.py",
"path_to_pywatchman": "//third-party/py/pywatchman:pywatchman-archive",
"path_to_sh_binary_template": "//src/com/facebook/buck/shell:sh_binary_template",
"path_to_six_py": "//third-party/py/six:six.py",
"path_to_typing": "//third-party/py:typing-archive",
}
BUCK_MODULES = {
"d": "//src/com/facebook/buck/features/d:d",
"dotnet": "//src/com/facebook/buck/features/dotnet:dotnet",
"filebundler": "//src/com/facebook/buck/features/filebundler:filebundler",
"filegroup": "//src/com/facebook/buck/features/filegroup:filegroup",
"go": "//src/com/facebook/buck/features/go:go",
"gwt": "//src/com/facebook/buck/features/gwt:gwt",
"halide": "//src/com/facebook/buck/features/halide:halide",
"haskell": "//src/com/facebook/buck/features/haskell:haskell",
"intellij": "//src/com/facebook/buck/features/project/intellij:intellij",
"js": "//src/com/facebook/buck/features/js:js",
"lua": "//src/com/facebook/buck/features/lua:lua",
"ocaml": "//src/com/facebook/buck/features/ocaml:ocaml",
"python": "//src/com/facebook/buck/features/python:module",
"rust": "//src/com/facebook/buck/features/rust:rust",
"xcode": "//src/com/facebook/buck/features/apple/project:project",
"ziprules": "//src/com/facebook/buck/features/zip/rules:rules",
}
BUCK_MODULES_WITH_RESOURCES = [
"python",
]
# This genrule generates a single hash of all resources listed in
# RESOURCES_AFFECTING_BUILD_ARTIFACTS list. The hash is stored in the output file.
genrule(
name = "calculate-buck-binary-hash",
out = "buck-binary-hash.txt",
cmd = " ".join([
"$(exe //py/hash:hash_files)",
" ".join(["$(location {})".format(resource) for resource in RESOURCES_AFFECTING_BUILD_ARTIFACTS.values()]),
"$(location //py/hash:hash_files.py)",
" > $OUT",
]),
visibility = [
"PUBLIC",
],
)
python_library(
name = "bucklib",
srcs = [
"buck_logging.py",
"buck_package.py",
"buck_project.py",
"buck_repo.py",
"buck_tool.py",
"file_locks.py",
"java_lookup.py",
"timing.py",
"tracing.py",
],
resources = dicts.add(
RESOURCES_NOT_AFFECTING_BUILD_ARTIFACTS,
RESOURCES_AFFECTING_BUILD_ARTIFACTS,
convert_modules_to_resources(BUCK_MODULES),
{
"buck_binary_hash": ":calculate-buck-binary-hash",
},
convert_modules_to_external_resources(BUCK_MODULES, BUCK_MODULES_WITH_RESOURCES),
),
deps = [
":buck_version",
":subprocutils",
"//third-party/nailgun:ng",
],
)
# Simple container libs to hold the resources needed to identify buck's version
python_library(
name = "buck_committed_version",
srcs = [],
resources = {RESOURCES_VERSION_INFO_NAME: ":gen_buck_package_info"},
)
python_library(
name = "buck_local_version",
srcs = [],
resources = {RESOURCES_VERSION_INFO_NAME: ":gen_local_buck_package_info"},
)
python_binary(
name = "buck",
build_args = interpreter_override_args(),
main = "buck.py",
visibility = [
"//scripts/...",
"//test/...",
"//tools/...",
],
deps = [
":buck_committed_version",
":bucklib",
":java_version",
":subprocutils",
],
)
python_binary(
name = "buck-local",
build_args = interpreter_override_args(),
main = "buck.py",
visibility = [
"//scripts/packages/chocolatey:chocolatey",
"//scripts/packages/debian:debian",
"//test/...",
"//tools/...",
],
deps = [
":buck_local_version",
":bucklib",
":java_version",
":subprocutils",
],
)
python_test(
name = "test",
srcs = glob(["test_*.py"]),
deps = [
":bucklib",
":subprocutils",
],
)