aboutsummaryrefslogtreecommitdiffstats
path: root/src/google/protobuf/SEBS
blob: ba33c7327ecf99396dceaf4af67cda535567f1b7 (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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# **EXPERIMENTAL**
#
# See http://sebs.googlecode.com
#
# This is an experimental build definition file using the SEBS build system.
# I (Kenton Varda, maintainer of Protocol Buffers) happen to be the author of
# SEBS, though SEBS is not a Google project.  I'm sticking this file in
# protobuf's SVN because that's the easiest place for me to put it, and it
# shouldn't harm anyone.  This file is not included in the distribution.
#
# Currently, to use this file, you must generate config.h and put it at the
# top level of the source tree.

_cpp = sebs.import_("//sebs/cpp.sebs")

# ====================================================================
# Public targets

protobuf_lite = _cpp.Library(
  name = "protobuf-lite",
  srcs = [ "stubs/common.cc",
           "stubs/once.cc",
           "stubs/hash.cc",
           "stubs/hash.h",
           "stubs/map-util.h",
           "stubs/stl_util-inl.h",
           "extension_set.cc",
           "generated_message_util.cc",
           "message_lite.cc",
           "repeated_field.cc",
           "wire_format_lite.cc",
           "io/coded_stream.cc",
           "io/zero_copy_stream.cc",
           "io/zero_copy_stream_impl_lite.cc" ],
  deps = [ _cpp.SystemLibrary(name = "pthread") ])

protobuf = _cpp.Library(
  name = "protobuf",
  srcs = [ "stubs/strutil.cc",
           "stubs/strutil.h",
           "stubs/substitute.cc",
           "stubs/substitute.h",
           "stubs/structurally_valid.cc",
           "descriptor.cc",
           "descriptor.pb.cc",
           "descriptor_database.cc",
           "dynamic_message.cc",
           "extension_set_heavy.cc",
           "generated_message_reflection.cc",
           "message.cc",
           "reflection_ops.cc",
           "service.cc",
           "text_format.cc",
           "unknown_field_set.cc",
           "wire_format.cc",
           "io/gzip_stream.cc",
           "io/printer.cc",
           "io/tokenizer.cc",
           "io/zero_copy_stream_impl.cc",
           "compiler/importer.cc",
           "compiler/parser.cc" ],
  deps = [ protobuf_lite,
           _cpp.SystemLibrary(name = "z") ])

libprotoc = _cpp.Library(
  name = "protoc",
  srcs = [ "compiler/code_generator.cc",
           "compiler/command_line_interface.cc",
           "compiler/cpp/cpp_enum.cc",
           "compiler/cpp/cpp_enum.h",
           "compiler/cpp/cpp_enum_field.cc",
           "compiler/cpp/cpp_enum_field.h",
           "compiler/cpp/cpp_extension.cc",
           "compiler/cpp/cpp_extension.h",
           "compiler/cpp/cpp_field.cc",
           "compiler/cpp/cpp_field.h",
           "compiler/cpp/cpp_file.cc",
           "compiler/cpp/cpp_file.h",
           "compiler/cpp/cpp_generator.cc",
           "compiler/cpp/cpp_helpers.cc",
           "compiler/cpp/cpp_helpers.h",
           "compiler/cpp/cpp_message.cc",
           "compiler/cpp/cpp_message.h",
           "compiler/cpp/cpp_message_field.cc",
           "compiler/cpp/cpp_message_field.h",
           "compiler/cpp/cpp_primitive_field.cc",
           "compiler/cpp/cpp_primitive_field.h",
           "compiler/cpp/cpp_service.cc",
           "compiler/cpp/cpp_service.h",
           "compiler/cpp/cpp_string_field.cc",
           "compiler/cpp/cpp_string_field.h",
           "compiler/java/java_enum.cc",
           "compiler/java/java_enum.h",
           "compiler/java/java_enum_field.cc",
           "compiler/java/java_enum_field.h",
           "compiler/java/java_extension.cc",
           "compiler/java/java_extension.h",
           "compiler/java/java_field.cc",
           "compiler/java/java_field.h",
           "compiler/java/java_file.cc",
           "compiler/java/java_file.h",
           "compiler/java/java_generator.cc",
           "compiler/java/java_helpers.cc",
           "compiler/java/java_helpers.h",
           "compiler/java/java_message.cc",
           "compiler/java/java_message.h",
           "compiler/java/java_message_field.cc",
           "compiler/java/java_message_field.h",
           "compiler/java/java_primitive_field.cc",
           "compiler/java/java_primitive_field.h",
           "compiler/java/java_service.cc",
           "compiler/java/java_service.h",
           "compiler/python/python_generator.cc" ],
  deps = [ protobuf ])

protoc = _cpp.Binary(
  name = "protoc",
  srcs = [ "compiler/main.cc" ],
  deps = [ libprotoc ])

# ====================================================================
# ProtobufLibrary rule class

class ProtobufLibrary(sebs.Rule):
  argument_spec = sebs.ArgumentSpec(srcs = [sebs.Artifact],
                                    deps = ([sebs.Rule], []),
                                    lite = (bool, False))

  def _expand(self, args):
    for dep in args.deps:
      if not isinstance(dep, ProtobufLibrary):
        raise sebs.DefinitionError(
          "Dependency of ProtobufLibrary is not a ProtobufLibrary: %s" % dep)

    protoc.expand_once()

    # We must build protoc for the host configuration to allow cross-compiling.
    host_protoc = self.context.configured_artifact(protoc.binary, "host")

    protoc_action = self.context.action(self, "protobuf")
    protoc_args = [host_protoc, "-Isrc", "-Itmp", "-Iinclude","--cpp_out=tmp"]

    cpp_srcs = []
    for src in args.srcs:
      protoc_args.append(src)

      # We cannot build .proto files from other packages because the .pb.cc
      # and .pb.h files would be written to that package, and we aren't allowed
      # to write to other packages.
      if self.context.local_filename(src) is None:
        raise sebs.DefinitionError(
          "Source file is not in this package: %s" % src)

      cc_artifact = self.context.derived_artifact(src, ".pb.cc", protoc_action)
      header_artifact = self.context.derived_artifact(
          src, ".pb.h", protoc_action)

      cpp_srcs.append(cc_artifact)
      cpp_srcs.append(header_artifact)

    protoc_action.set_command(
      sebs.SubprocessCommand(protoc_action, protoc_args, implicit = cpp_srcs))

    deps = list(args.deps)
    if args.lite:
      deps.append(protobuf_lite)
    else:
      deps.append(protobuf)

    self.__cpp_library = _cpp.Library(srcs = cpp_srcs, deps = deps,
                                      context = self.context)
    self.__cpp_library.label = self.label
    self.outputs = []

  def as_cpp_library(self):
    self.expand_once()
    return self.__cpp_library

# ====================================================================
# Tests

_lite_test_protos = ProtobufLibrary(
  srcs = [ "unittest_lite.proto",
           "unittest_import_lite.proto" ],
  lite = True)
_test_protos = ProtobufLibrary(
  srcs = [ "unittest.proto",
           "unittest_empty.proto",
           "unittest_import.proto",
           "unittest_mset.proto",
           "unittest_optimize_for.proto",
           "unittest_embed_optimize_for.proto",
           "unittest_custom_options.proto",
           "unittest_lite_imports_nonlite.proto",
           "compiler/cpp/cpp_test_bad_identifiers.proto" ],
  deps = [ _lite_test_protos ])

_test_util = _cpp.Library(
  name = "test_util",
  srcs = [ "test_util.cc",
           "test_util.h",
           "testing/googletest.cc",
           "testing/googletest.h",
           "testing/file.cc",
           "testing/file.h" ],
  deps = [ protobuf, _test_protos, _cpp.SystemLibrary(name = "gtest")] )

protobuf_lite_test = _cpp.Test(
  srcs = [ "lite_unittest.cc",
           "test_util_lite.cc",
           "test_util_lite.h" ],
  deps = [ _lite_test_protos ])

protobuf_test = _cpp.Test(
  srcs = [ "stubs/common_unittest.cc",
           "stubs/once_unittest.cc",
           "stubs/strutil_unittest.cc",
           "stubs/structurally_valid_unittest.cc",
           "descriptor_database_unittest.cc",
           "descriptor_unittest.cc",
           "dynamic_message_unittest.cc",
           "extension_set_unittest.cc",
           "generated_message_reflection_unittest.cc",
           "message_unittest.cc",
           "reflection_ops_unittest.cc",
           "repeated_field_unittest.cc",
           "text_format_unittest.cc",
           "unknown_field_set_unittest.cc",
           "wire_format_unittest.cc",
           "io/coded_stream_unittest.cc",
           "io/printer_unittest.cc",
           "io/tokenizer_unittest.cc",
           "io/zero_copy_stream_unittest.cc",
           "compiler/command_line_interface_unittest.cc",
           "compiler/importer_unittest.cc",
           "compiler/parser_unittest.cc",
           "compiler/cpp/cpp_bootstrap_unittest.cc",
           "compiler/cpp/cpp_unittest.cc" ],
  deps = [ protobuf, libprotoc, _test_util,
           _cpp.SystemLibrary(name = "gtest_main") ])