forked from protocolbuffers/protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.bazel
executable file
·163 lines (149 loc) · 5.18 KB
/
BUILD.bazel
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
# Protobuf Ruby runtime
#
# See also code generation logic under /src/google/protobuf/compiler/ruby.
load("@rules_pkg//:mappings.bzl", "pkg_files", "strip_prefix")
load("@rules_ruby//ruby:defs.bzl", "ruby_library")
load("//build_defs:internal_shell.bzl", "inline_sh_binary")
load("//:protobuf.bzl", "internal_ruby_proto_library")
load("//conformance:defs.bzl", "conformance_test")
load("//:protobuf_version.bzl", "PROTOBUF_RUBY_VERSION")
################################################################################
# Ruby Runtime
################################################################################
ruby_library(
name = "protobuf",
deps = ["//ruby/lib/google:protobuf_lib"],
visibility = [
"//visibility:public",
],
)
# Note: these can be greatly simplified using inline_sh_binary in Bazel 6,
# but doesn't work prior to that due to https://github.com/bazelbuild/bazel/issues/15043.
# Instead, we need to manually copy all of the srcs into gendir from a genrule.
genrule(
name = "jruby_release",
srcs = [
"//ruby/lib/google:copy_jar",
"//ruby/lib/google:dist_files",
"//:well_known_ruby_protos",
"google-protobuf.gemspec",
],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+"-java.gem"],
cmd = """
set -eux
mkdir tmp
for src in $(SRCS); do
cp --parents -L "$$src" tmp
done
for wkt in $(execpaths //:well_known_ruby_protos); do
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
done
mv "tmp/$(execpath //ruby/lib/google:copy_jar)" "tmp/ruby/lib/google"
cd tmp/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
cd ../..
mv tmp/ruby/google-protobuf-*.gem $@
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
genrule(
name = "ruby_release",
srcs = [
"@utf8_range//:utf8_range_srcs",
"@utf8_range//:LICENSE",
"//:well_known_ruby_protos",
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"google-protobuf.gemspec",
],
outs = ["google-protobuf-"+PROTOBUF_RUBY_VERSION+".gem"],
cmd = """
set -eux
mkdir tmp
for src in $(SRCS); do
cp --parents -L "$$src" "tmp"
done
mkdir -p "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
for utf in $(execpaths @utf8_range//:utf8_range_srcs) $(execpath @utf8_range//:LICENSE); do
mv "tmp/$$utf" "tmp/ruby/ext/google/protobuf_c/third_party/utf8_range"
done
for wkt in $(execpaths //:well_known_ruby_protos); do
mv "tmp/$$wkt" "tmp/ruby/lib/google/protobuf/"
done
cd tmp/ruby
chmod -R 777 ./
gem build google-protobuf.gemspec
cd ../..
mv tmp/ruby/google-protobuf-*.gem $@
""",
tags = ["manual"],
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_ruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
filegroup(
name = "release",
srcs = select({
"@rules_ruby//ruby/runtime:config_jruby": [":jruby_release"],
"//conditions:default": [":ruby_release"],
}),
tags = ["manual"],
)
################################################################################
# Tests
################################################################################
# Define this here so the descriptor paths match what we get in Rake tests.
internal_ruby_proto_library(
name = "test_ruby_protos",
srcs = ["//ruby/tests:test_protos"],
deps = ["//:well_known_ruby_protos"],
includes = [".", "src", "ruby/tests"],
visibility = [
"//ruby:__subpackages__",
],
)
conformance_test(
name = "conformance_test",
failure_list = "//conformance:failure_list_ruby.txt",
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_ruby.txt",
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_ruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
conformance_test(
name = "conformance_test_jruby",
failure_list = "//conformance:failure_list_jruby.txt",
testee = "//conformance:conformance_ruby",
text_format_failure_list = "//conformance:text_format_failure_list_jruby.txt",
target_compatible_with = select({
"@rules_ruby//ruby/runtime:config_jruby": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
)
################################################################################
# Distribution files
################################################################################
pkg_files(
name = "dist_files",
srcs = [
"//ruby/ext/google/protobuf_c:dist_files",
"//ruby/lib/google:dist_files",
"//ruby/src/main/java:dist_files",
"//ruby/tests:dist_files",
".gitignore",
"BUILD.bazel",
"Gemfile",
"Rakefile",
"README.md",
],
strip_prefix = strip_prefix.from_root(""),
visibility = ["//pkg:__pkg__"],
)