Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel updates for Harmonic #397

Merged
merged 26 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up harmonic implementation
Signed-off-by: Michael Carroll <mjcarroll@intrinsic.ai>
  • Loading branch information
mjcarroll committed Mar 4, 2024
commit 35d48cd1d656e44ff13ebf14d7998655d527ad01
9 changes: 4 additions & 5 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protos = glob(["proto/gz/msgs/*.proto"])

gz_include_header(
name = "msgs_hh_genrule",
out = "include/gz/msgs.hh",
out = "core/include/gz/msgs.hh",
hdrs = public_headers_no_gen + [
"core/include/gz/msgs/config.hh",
"core/include/gz/msgs/Export.hh",
Expand Down Expand Up @@ -88,16 +88,15 @@ gz_proto_library(
gz_proto_factory(
name = "gzmsgs_proto_factory",
deps = [":gzmsgs_proto"],
namespace = "gz::msgs",
cc_output = "core/src/RegisterMsgs.cc",
hh_output = "include/gz/msgs/MessageTypes.hh"
hh_output = "core/include/gz/msgs/MessageTypes.hh"
)

public_headers = public_headers_no_gen + [
"core/include/gz/msgs/config.hh",
"core/include/gz/msgs/Export.hh",
"include/gz/msgs.hh",
"include/gz/msgs/MessageTypes.hh"
"core/include/gz/msgs.hh",
"core/include/gz/msgs/MessageTypes.hh"
]


Expand Down
235 changes: 0 additions & 235 deletions protobuf.bzl

This file was deleted.

9 changes: 3 additions & 6 deletions tools/gz_msgs_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ def _gz_proto_factory_impl(ctx):
for proto in src[ProtoInfo].direct_sources:
in_protos.append(proto)

for proto in src[ProtoInfo].transitive_sources.to_list():
in_protos.append(proto)
#for proto in src[ProtoInfo].transitive_sources.to_list():
# print('transitive: ', proto)
# in_protos.append(proto)

in_protos = depset(in_protos).to_list()
arguments = [
Expand All @@ -64,7 +65,6 @@ def _gz_proto_factory_impl(ctx):
arguments.append("--proto-path=" + include_dir)

arguments.append("--proto-include-path=" + out_dir.path)
arguments.append("--namespace=" + ctx.attr.namespace)
arguments.append("--protos")
for proto in in_protos:
arguments.append(proto.path)
Expand Down Expand Up @@ -92,9 +92,6 @@ _gz_proto_factory = rule(
allow_empty = False,
providers = [ProtoInfo],
),
"namespace": attr.string(
mandatory = True,
),
"cc_output": attr.output(mandatory = True),
"hh_output": attr.output(mandatory = True),
"gz_msgs_generate_factory_py": attr.label(
Expand Down
35 changes: 15 additions & 20 deletions tools/gz_msgs_generate_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@
* Do not edit this directly
*/

#include "MessageTypes.hh"

#include "gz/msgs/Factory.hh"
#include "gz/msgs/MessageFactory.hh"
#include "{include_path}/MessageTypes.hh"

#include <array>

Expand Down Expand Up @@ -118,10 +117,6 @@ def main(argv=sys.argv[1:]):
'--hh-output',
required=True,
help='The path to the generated hh file')
parser.add_argument(
'--namespace',
required=True,
help='The namespace to use')
parser.add_argument(
'--proto-path',
required=True,
Expand All @@ -143,13 +138,12 @@ def main(argv=sys.argv[1:]):
package_re = re.compile('^package (.*);$')
message_re = re.compile(r'message (\w*)\s?{?$')

registrations = []
registrations = dict()
gz_msgs_headers = []
package = None
messages = []

for proto in args.protos:
package = None
messages = []

try:
with open(proto, 'r') as f:
content = f.readlines()
Expand All @@ -166,28 +160,29 @@ def main(argv=sys.argv[1:]):

if package and messages:
for message in messages:
registrations.append(register_fn.format(
registrations['_'.join([*package, message])] = register_fn.format(
package_str='.'.join(package),
message_str=message,
message_cpp_type='::'.join([*package, message])
))

)

split = proto.replace(args.proto_include_path, '')
split = [s for s in split.split("/") if s]
split[-1] = split[-1].replace(".proto", ".pb.h")
print(split)

gz_msgs_headers.append("#include <" + "/".join(split) + ">")

namespace = '::'.join(package)
include_path = '/'.join(package)

with open(os.path.join(args.cc_output), 'w') as f:
f.write((cc_source.format(registrations='\n'.join(registrations),
nRegistrations=len(registrations),
namespace=args.namespace) +
cc_factory.format(namespace=args.namespace)))
f.write((cc_source.format(registrations='\n'.join(registrations.values()),
nRegistrations=len(registrations.values()),
namespace=namespace,
include_path=include_path) +
cc_factory.format(namespace=namespace)))

with open(os.path.join(args.hh_output), 'w') as f:
f.write(cc_header.format(namespace=args.namespace,
f.write(cc_header.format(namespace=namespace,
gz_msgs_headers='\n'.join(gz_msgs_headers)))

if __name__ == '__main__':
Expand Down
Loading