Skip to content

Commit 4795e34

Browse files
author
Michael Carroll
committed
Harmonic bazel
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
1 parent b35b9fd commit 4795e34

File tree

9 files changed

+632
-183
lines changed

9 files changed

+632
-183
lines changed

BUILD.bazel

Lines changed: 83 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ load(
99
)
1010
load(
1111
"@gz//msgs/tools:gz_msgs_generate.bzl",
12-
"get_proto_headers",
13-
"gz_msgs_generate",
12+
"gz_proto_library",
13+
"gz_proto_factory",
1414
)
1515

1616
package(
@@ -24,56 +24,48 @@ exports_files(["LICENSE"])
2424

2525
gz_configure_header(
2626
name = "msgs_config_hh",
27-
src = "include/gz/msgs/config.hh.in",
27+
src = "core/include/gz/msgs/config.hh.in",
2828
cmakelists = ["CMakeLists.txt"],
2929
package = "msgs",
3030
)
3131

3232
gz_export_header(
33-
name = "include/gz/msgs/Export.hh",
33+
name = "core/include/gz/msgs/Export.hh",
3434
export_base = "GZ_MSGS",
3535
lib_name = "gz-msgs",
3636
visibility = ["//visibility:private"],
3737
)
3838

3939
public_headers_no_gen = glob([
40-
"include/gz/msgs/*.hh",
41-
"include/gz/msgs/detail/*.hh",
40+
"core/include/gz/msgs/*.hh",
41+
"core/include/gz/msgs/convert/*.hh",
42+
"core/include/gz/msgs/detail/*.hh",
4243
])
4344

4445
protos = glob(["proto/gz/msgs/*.proto"])
4546

46-
gz_include_header(
47-
name = "messagetypes_hh_genrule",
48-
out = "include/gz/msgs/MessageTypes.hh",
49-
hdrs = get_proto_headers(protos),
50-
strip_prefix = ["gz_msgs"],
51-
)
52-
5347
gz_include_header(
5448
name = "msgs_hh_genrule",
5549
out = "include/gz/msgs.hh",
5650
hdrs = public_headers_no_gen + [
57-
"include/gz/msgs/config.hh",
58-
"include/gz/msgs/Export.hh",
59-
"include/gz/msgs/MessageTypes.hh",
51+
"core/include/gz/msgs/config.hh",
52+
"core/include/gz/msgs/Export.hh",
6053
],
6154
)
6255

6356
public_headers = public_headers_no_gen + [
64-
"include/gz/msgs/config.hh",
65-
"include/gz/msgs/Export.hh",
66-
"include/gz/msgs/MessageTypes.hh",
57+
"core/include/gz/msgs/config.hh",
58+
"core/include/gz/msgs/Export.hh",
6759
"include/gz/msgs.hh",
6860
]
6961

7062
# Custom Gazebo Protoc plugin
7163
cc_binary(
7264
name = "gz_msgs_gen",
7365
srcs = [
74-
"src/Generator.cc",
75-
"src/Generator.hh",
76-
"src/generator_main.cc",
66+
"core/generator_lite/Generator.cc",
67+
"core/generator_lite/Generator.hh",
68+
"core/generator_lite/generator_main.cc",
7769
],
7870
deps = [
7971
"@com_google_protobuf//:protobuf",
@@ -91,26 +83,37 @@ proto_library(
9183
],
9284
)
9385

94-
gz_msgs_generate(
95-
name = "gzmsgs_cc_proto",
96-
deps = [
97-
":gzmsgs_proto",
98-
"@com_google_protobuf//:any_proto",
99-
],
86+
gz_proto_library(
87+
name = "gzmsgs_cc_proto",
88+
proto_deps = [":gzmsgs_proto"],
89+
deps = [
90+
"@com_google_protobuf//:protobuf",
91+
]
92+
)
93+
94+
gz_proto_factory(
95+
name = "gzmsgs_proto_factory",
96+
deps = [":gzmsgs_proto"],
97+
namespace = "gz::msgs",
98+
cc_output = "core/src/RegisterMsgs.cc",
99+
hh_output = "core/src/MessageTypes.hh"
100100
)
101101

102102
cc_library(
103103
name = "msgs",
104104
srcs = [
105-
"src/Factory.cc",
106-
"src/Filesystem.cc",
107-
"src/Utility.cc",
108-
":gzmsgs_cc_proto",
105+
"core/src/Factory.cc",
106+
"core/src/DynamicFactory.cc",
107+
"core/src/DynamicFactory.hh",
108+
"core/src/MessageFactory.cc",
109+
"core/src/impl/InstallationDirectories.cc",
110+
"core/src/RegisterMsgs.cc"
109111
],
110112
hdrs = public_headers,
111-
includes = ["include"],
113+
includes = ["core/include", "core/src"],
112114
deps = [
113115
":gzmsgs_cc_proto",
116+
":gzmsgs_proto_factory",
114117
GZ_ROOT + "math",
115118
"@com_google_protobuf//:protobuf",
116119
"@tinyxml2",
@@ -138,3 +141,50 @@ test_sources = glob(
138141
"@gtest//:gtest_main",
139142
],
140143
) for src in test_sources]
144+
145+
146+
cc_test(
147+
name = "INTEGRATION_headers",
148+
srcs = ["test/integration/headers.cc"],
149+
deps = [
150+
":gzmsgs_cc_proto",
151+
"@gtest",
152+
"@gtest//:gtest_main",
153+
],
154+
)
155+
156+
cc_test(
157+
name = "INTEGRATION_image_msg",
158+
srcs = ["test/integration/image_msg.cc"],
159+
deps = [
160+
":gzmsgs_cc_proto",
161+
"@gtest",
162+
"@gtest//:gtest_main",
163+
],
164+
)
165+
166+
cc_test(
167+
name = "INTEGRATION_Utility",
168+
srcs = ["test/integration/Utility_TEST.cc"],
169+
deps = [
170+
":msgs",
171+
GZ_ROOT + "common/testing",
172+
"@gtest",
173+
"@gtest//:gtest_main",
174+
],
175+
)
176+
177+
cc_test(
178+
name = "INTEGRATION_Factory",
179+
srcs = ["test/integration/Factory_TEST.cc"],
180+
data = ["test/desc/stringmsg.desc"],
181+
deps = [
182+
":msgs",
183+
GZ_ROOT + "common/testing",
184+
"@gtest",
185+
"@gtest//:gtest_main",
186+
],
187+
defines = [
188+
'GZ_MSGS_TEST_PATH=\\"msgs/test\\"',
189+
],
190+
)

core/generator_lite/Generator.cc

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2016 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#include <algorithm>
19+
#include <filesystem>
20+
#include <iostream>
21+
#include <fstream>
22+
#include <map>
23+
#include <memory>
24+
#include <sstream>
25+
#include <string>
26+
#include <utility>
27+
#include <vector>
28+
29+
#ifdef _MSC_VER
30+
#pragma warning(push)
31+
#pragma warning(disable: 4100 4512 4127 4068 4244 4267 4251 4146)
32+
#endif
33+
34+
#include <google/protobuf/descriptor.h>
35+
#include <google/protobuf/compiler/code_generator.h>
36+
#include <google/protobuf/io/printer.h>
37+
#include <google/protobuf/io/zero_copy_stream.h>
38+
#include <google/protobuf/descriptor.pb.h>
39+
40+
#ifdef _MSC_VER
41+
#pragma warning(pop)
42+
#endif
43+
44+
#include "Generator.hh"
45+
46+
namespace google::protobuf::compiler::cpp {
47+
48+
/////////////////////////////////////////////////
49+
Generator::Generator(const std::string &/*_name*/)
50+
{
51+
}
52+
53+
/////////////////////////////////////////////////
54+
Generator::~Generator() = default;
55+
56+
/////////////////////////////////////////////////
57+
bool Generator::Generate(const FileDescriptor *_file,
58+
const std::string &/*_parameter*/,
59+
OutputDirectory *_generatorContext,
60+
std::string * /*_error*/) const
61+
{
62+
std::string delim = ".proto";
63+
auto headerFilename = _file->name();
64+
auto sourceFilename = _file->name();
65+
66+
{
67+
auto pos = headerFilename.rfind(delim);
68+
headerFilename.replace(pos, delim.size(), ".pb.h");
69+
}
70+
{
71+
auto pos = sourceFilename.rfind(delim);
72+
sourceFilename.replace(pos, delim.size(), ".pb.h");
73+
}
74+
75+
{
76+
auto *output = _generatorContext->OpenForInsert(headerFilename, "includes");
77+
auto printer = io::Printer(output, '$');
78+
printer.Print("#include <memory>\n", "name", "includes");
79+
}
80+
81+
{
82+
auto *output = _generatorContext->OpenForInsert(
83+
headerFilename, "namespace_scope");
84+
auto printer = io::Printer(output, '$');
85+
86+
for (auto i = 0; i < _file->message_type_count(); ++i)
87+
{
88+
const auto *desc = _file->message_type(i);
89+
std::string ptrTypes;
90+
91+
// Define std::unique_ptr types for our messages
92+
ptrTypes += "typedef std::unique_ptr<"
93+
+ desc->name() + "> "
94+
+ desc->name() + "UniquePtr;\n";
95+
96+
// Define const std::unique_ptr types for our messages
97+
ptrTypes += "typedef std::unique_ptr<const "
98+
+ desc->name() + "> Const"
99+
+ desc->name() + "UniquePtr;\n";
100+
101+
// Define std::shared_ptr types for our messages
102+
ptrTypes += "typedef std::shared_ptr<"
103+
+ desc->name() + "> "
104+
+ desc->name() + "SharedPtr;\n";
105+
106+
// Define const std::shared_ptr types for our messages
107+
ptrTypes += "typedef std::shared_ptr<const "
108+
+ desc->name() + "> Const"
109+
+ desc->name() + "SharedPtr;\n";
110+
111+
printer.PrintRaw(ptrTypes.c_str());
112+
}
113+
}
114+
return true;
115+
}
116+
} // namespace google::protobuf::compiler::cpp

core/generator_lite/Generator.hh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2016 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#ifndef GZ_MSGS_GENERATOR_HH_
19+
#define GZ_MSGS_GENERATOR_HH_
20+
21+
#include <google/protobuf/compiler/code_generator.h>
22+
#include <string>
23+
24+
namespace google {
25+
namespace protobuf {
26+
namespace compiler {
27+
namespace cpp {
28+
/// \cond
29+
/// \brief Google protobuf message generator for igntion::msgs
30+
class Generator : public CodeGenerator
31+
{
32+
/// \brief Constructor
33+
/// \param[in] _name Name value (currently unused)
34+
public: explicit Generator(const std::string &_name);
35+
36+
/// \brief Destructor
37+
public: virtual ~Generator();
38+
39+
/// \brief Generate a message.
40+
/// \param[in] _file File descriptor of the message.
41+
/// \param[in] _parameter Unused string value
42+
/// \param[in] _generatorContext Output directory.
43+
/// \param[in] _error Unused string value
44+
/// \return true if successful, otherwise sets _error and returns false
45+
public: virtual bool Generate(const FileDescriptor *_file,
46+
const std::string &_parameter,
47+
OutputDirectory *_generatorContext,
48+
std::string *_error) const;
49+
50+
// private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Generator);
51+
};
52+
/// \endcond
53+
}
54+
}
55+
}
56+
}
57+
#endif
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright (C) 2016 Open Source Robotics Foundation
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
#ifdef _MSC_VER
19+
#pragma warning(push)
20+
#pragma warning(disable: 4251)
21+
#endif
22+
23+
#include <google/protobuf/compiler/plugin.h>
24+
25+
#ifdef _MSC_VER
26+
#pragma warning(pop)
27+
#endif
28+
29+
#include "Generator.hh"
30+
31+
int main(int _argc, char *_argv[])
32+
{
33+
#ifdef _MSC_VER
34+
// Don't print a silly message or stick a modal dialog box in my face,
35+
// please.
36+
_set_abort_behavior(0, ~0);
37+
#endif // !_MSC_VER
38+
39+
google::protobuf::compiler::cpp::Generator
40+
generator("gz-msgs-plugin");
41+
return google::protobuf::compiler::PluginMain(_argc, _argv, &generator);
42+
}

0 commit comments

Comments
 (0)