-
Notifications
You must be signed in to change notification settings - Fork 176
/
BUILD
138 lines (124 loc) · 4.45 KB
/
BUILD
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
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -*- coding: utf-8 -*-
licenses(["notice"])
load("@rules_pkg//:pkg.bzl", "pkg_deb", "pkg_tar")
load(":package_upload.bzl", "debian_upload")
load(":my_package_name.bzl", "basic_naming", "name_part_from_command_line", "names_from_toolchains")
config_setting(
name = "special_build",
values = {"define": "SPECIAL=1"},
)
# Exposes the value of the compilation mode to the package naming.
basic_naming(
name = "my_naming_vars",
# An explicit value.
# This technique can be useful if you need to create packages in many
# different formats but have not decided on the final naming yet. You
# can use a placeholder and change it on one location.
#
product_name = "RulesPkgExamples",
# Use a config_setting flag to specify part of the package name.
# In this example, we define the config_setting based on a command line
# flag. Example
# bazel build :example1
# bazel build :example1 --define=SPECIAL=1
special_build = select({
":special_build": "-IsSpecial",
"//conditions:default": "",
}),
)
# Try building with various flag combinations to explore.
# bazel build :example1
# bazel build :example1 -c dbg
# bazel build :example1 -define=SPECIAL=1
# bazel build :example1 -c dbg --define=SPECIAL=1
pkg_tar(
name = "example1",
srcs = [
":BUILD",
],
package_file_name = "example1-{product_name}-{target_cpu}-{compilation_mode}{special_build}.tar",
package_variables = ":my_naming_vars",
)
# This example shows that in the same way as package_file_name, the inner folder structure of the archive
# specified with package_dir attribute also can be controlled by the package_variables attribute.
pkg_tar(
name = "example2",
srcs = [
":BUILD",
],
package_file_name = "example2-{product_name}-{target_cpu}-{compilation_mode}{special_build}.tar",
package_dir = "example1/{product_name}/{target_cpu}/{compilation_mode}{special_build}",
package_variables = ":my_naming_vars",
)
#
# names_from_toolchains() extracts variables from the CC toolchain.
#
names_from_toolchains(
name = "toolchain_vars",
)
pkg_tar(
name = "example3",
srcs = [
":BUILD",
],
package_file_name = "example3-{cc_cpu}-{compiler}-{compilation_mode}.tar",
package_variables = ":toolchain_vars",
)
#
# Demonstrate how the .changes file defaults based on package_file_name.
#
pkg_deb(
name = "a_deb_package",
data = ":example1",
description = "what it does",
maintainer = "someone@somewhere.com",
package = "foo_tools",
# Note: We could not know target_cpu at the time I write this rule.
package_file_name = "foo_tools-1-{target_cpu}.deb",
package_variables = ":my_naming_vars",
version = "1",
)
# This does not actually build anything. It writes a skelaton of a script that
# could upload the .deb and .changes pair. You should see something like
# $ cat bazel-bin/upload.sh
# # Uploading foo_tools-1-k8
# gsutil cp bazel-out/k8-fastbuild/bin/foo_tools-1-k8.deb gs://my_mirror/foo_tools-1-k8.deb
# gsutil cp bazel-out/k8-fastbuild/bin/foo_tools-1-k8.changes gs://my_mirror/foo_tools-1-k8.changes
debian_upload(
name = "upload",
out = "upload.sh",
host = "my_mirror",
# Refer to the target label, without having to know the final file name.
package = ":a_deb_package",
)
#
# Demonstrate how we can use a value from the command line in a package name.
#
# bazel build --//:name_part_from_command_line=bar :tarball_that_needs_a_name
# ls bazel-bin/foo-bar.tar
name_part_from_command_line(
name = "name_part_from_command_line",
# We use a harmless default value so that the build succeeds all the time.
build_setting_default = "@set_me@",
)
pkg_tar(
name = "tarball_that_needs_a_name",
srcs = [
":BUILD",
],
package_file_name = "foo-{name_part}.tar",
package_variables = ":name_part_from_command_line",
)