forked from facebook/buck2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defs.bzl
59 lines (51 loc) · 2.33 KB
/
defs.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
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under both the MIT license found in the
# LICENSE-MIT file in the root directory of this source tree and the Apache
# License, Version 2.0 found in the LICENSE-APACHE file in the root directory
# of this source tree.
load("@fbcode_macros//build_defs:platform_utils.bzl", "platform_utils")
load("@prelude//decls:common.bzl", "buck")
load("@prelude//os_lookup:defs.bzl", "OsLookup")
def _symlinked_buck2_and_tpx_impl(ctx: AnalysisContext) -> list[Provider]:
"""
Produce a directory layout that is similar to the one our release binary
uses, this allows setting a path for Tpx relative to BUCK2_BINARY_DIR.
We do the whole BUCK2_BINARY_DIR_RELATIVE_TO dance to support doing this
using just symlinks. If we're willing to do a copy we can just
`out.project("buck2")` and we're done.
"""
target_is_windows = ctx.attrs._target_os_type[OsLookup].platform == "windows"
buck2 = ctx.attrs.buck2[DefaultInfo].default_outputs[0]
tpx = ctx.attrs.tpx[DefaultInfo].default_outputs[0]
binary_extension = ".exe" if target_is_windows else ""
buck2_binary = "buck2" + binary_extension
buck2_tpx_binary = "buck2-tpx" + binary_extension
out = ctx.actions.symlinked_dir("out", {buck2_binary: buck2, buck2_tpx_binary: tpx})
if target_is_windows:
cmd = cmd_args(
"cmd.exe",
"/c",
cmd_args(out, format = "set BUCK2_BINARY_DIR_RELATIVE_TO={}&&").relative_to(buck2, parent = 1),
out.project(buck2_binary),
).hidden(out)
else:
cmd = cmd_args(
"/usr/bin/env",
cmd_args(out, format = "BUCK2_BINARY_DIR_RELATIVE_TO={}").relative_to(buck2, parent = 1),
out.project(buck2_binary),
).hidden(out)
return [DefaultInfo(out), RunInfo(cmd)]
_symlinked_buck2_and_tpx = rule(
impl = _symlinked_buck2_and_tpx_impl,
attrs = {
"buck2": attrs.dep(),
"labels": attrs.list(attrs.string(), default = []),
"tpx": attrs.dep(),
"_target_os_type": buck.target_os_type_arg(),
},
)
def symlinked_buck2_and_tpx(**kwargs):
cxx_platform = platform_utils.get_cxx_platform_for_base_path(native.package_name())
kwargs["default_target_platform"] = cxx_platform.target_platform
_symlinked_buck2_and_tpx(**kwargs)