aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/packages/BUILD
blob: ace087ce2abf2885877dd718b4890107680e0330 (plain)
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
package(default_visibility = ["//scripts/packages:__subpackages__"])

filegroup(
    name = "srcs",
    srcs = glob(["**"]) + [
        "//scripts/packages/debian:srcs",
        "//scripts/packages/fedora:srcs",
    ],
    visibility = [
        "//scripts:__pkg__",
        "//scripts/packages:__subpackages__",
    ],
)

filegroup(
    name = "packages",
    srcs = select({
        "//src/conditions:windows": [
            ":zip-bazel-exe",
            ":zip-bazel-exe_with_jdk",
        ],
        "//src/conditions:freebsd": [],
        "//src/conditions:darwin": [
            ":with-jdk/install.sh",
            ":without-jdk/install.sh",
            ":generate-package-info",
        ],
        "//src/conditions:darwin_x86_64": [
            ":with-jdk/install.sh",
            ":without-jdk/install.sh",
            ":generate-package-info",
        ],
        "//conditions:default": [
            ":with-jdk/install.sh",
            ":without-jdk/install.sh",
            ":generate-package-info",
            "//:bazel-distfile",
            "//scripts/packages/debian:bazel-debian",
            "//scripts/packages/debian:bazel-debian-src",
        ],
    }),
)

sh_binary(
    name = "package-info-generator",
    srcs = ["package_info_generator.sh"],
)

genrule(
    name = "generate-package-info",
    outs = ["README.md"],
    cmd = "$(location :package-info-generator) $$(find . -name '*status*.txt') >$@",
    stamp = 1,
    tools = [":package-info-generator"],
)

[genrule(
    name = "zip-bazel-exe" + suffix,
    srcs = ["//src:bazel%s.exe" % suffix],
    outs = ["bazel%s.zip" % suffix],
    cmd = "\n".join([
        "tmpdir=$$(mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXX)",
        "trap \"rm -fr $${tmpdir}\" EXIT",
        "mv $(SRCS) $${tmpdir}/bazel.exe",
        "touch -t 198001010000.00 $${tmpdir}/bazel.exe",
        "zip -jq $@ $${tmpdir}/bazel.exe",
    ]),
) for suffix in [
    "",
    "_with_jdk",
]]

genrule(
    name = "generate-launcher",
    srcs = [
        "template_bin.sh",
        ":README.md",
    ],
    outs = ["launcher_bin.sh"],
    cmd = """
        release_info="$$(cat $(location :README.md))"
        template="$$(cat $(location template_bin.sh))"
        echo "$${template//%release_info%/$${release_info}}" >$@
        """,
)

genrule(
    name = "rename-bazel-bin",
    srcs = ["//src:bazel"],
    outs = ["with-jdk/bazel-real"],
    cmd = "mkdir -p $$(dirname $@); cp $< $@",
)

genrule(
    name = "rename-bazel-bin-without-jdk",
    srcs = ["//src:bazel"],
    outs = ["without-jdk/bazel-real"],
    cmd = "mkdir -p $$(dirname $@); cp $< $@",
)

genrule(
    name = "bazel-sh-with-jdk",
    srcs = ["bazel.sh"],
    outs = ["with-jdk/bazel"],
    cmd = "mkdir -p $$(dirname $@); cp $< $@",
)

genrule(
    name = "bazel-sh-without-jdk",
    srcs = ["bazel.sh"],
    outs = ["without-jdk/bazel"],
    cmd = "mkdir -p $$(dirname $@); cp $< $@",
)

load(":self_extract_binary.bzl", "self_extract_binary")

[self_extract_binary(
    name = "%s/install.sh" % kind,
    flatten_resources = [
        ":%s/bazel-real" % kind,
        ":%s/bazel" % kind,
        "//scripts:bash_completion",
    ],
    launcher = ":launcher_bin.sh",
) for kind in ("with-jdk", "without-jdk")]

genrule(
    name = "embedded_label",
    srcs = [],
    outs = [
        "version.txt",
    ],
    cmd =
        "find -L . -name stable-status.txt -exec cat '{}' ';'" +
        " | grep EMBED_LABEL | cut -d ' ' -f 2-" +
        " > $@\n",
    stamp = 1,
)