BUCKannotatedBUCKsource58 lines · 1.9 KB · raw
1load("//build:defs.bzl", "first_party_binary", "first_party_test")
2
3first_party_binary(
4    name = "third-party-notices",
5    srcs = glob(["src/**/*.rs"]),
6    crate_root = "src/main.rs",
7    deps = ["//third-party:toml"],
8)
9
10# The crate archives linked into each shipped binary: target deps only, so
11# build scripts, their deps and proc-macros (bindgen, cc, serde_derive),
12# which run at build time and are not shipped, are left out.
13# `query_outputs` reads the archives straight from third-party/BUCK, whose
14# http_archive targets are private: a query reaches them where a dep
15# cannot. Both files come from one run, because one texts/ serves both.
16ARCHIVES = "$(query_outputs 'kind(http_archive, deps({}, 1000, target_deps()))')"
17
18genrule(
19    name = "notices",
20    srcs = glob(["texts/**"]),
21    outs = {
22        "extension": ["THIRD-PARTY"],
23        "sidecar": ["THIRD-PARTY-sidecar"],
24    },
25    cmd = " ".join([
26        "$(exe :third-party-notices) generate $SRCDIR/texts",
27        "-- $OUT/THIRD-PARTY postjevsql postjevsql.so",
28        ARCHIVES.format("//crates/postjevsql:postjevsql"),
29        "-- $OUT/THIRD-PARTY-sidecar postjevsql-sidecar 'the postjevsql-sidecar binary'",
30        ARCHIVES.format("//crates/postjevsql-sidecar:cli"),
31    ]),
32)
33
34first_party_test(
35    name = "drift",
36    srcs = ["drift.rs"],
37    crate_root = "drift.rs",
38    env = {
39        "COMMITTED": "$(location //:third-party-notices)",
40        "COMMITTED_SIDECAR": "$(location //:third-party-notices-sidecar)",
41        "GENERATED": "$(location :notices[extension])",
42        "GENERATED_SIDECAR": "$(location :notices[sidecar])",
43    },
44)
45
46# `buck2 run //tools/third-party-notices:update` rewrites the root
47# THIRD-PARTY and THIRD-PARTY-sidecar.
48command_alias(
49    name = "update",
50    exe = ":third-party-notices",
51    args = [
52        "write",
53        "$(location :notices[extension])",
54        "THIRD-PARTY",
55        "$(location :notices[sidecar])",
56        "THIRD-PARTY-sidecar",
57    ],
58)