blob: 87d5b5433e8928bedf1aeb9e0b3b08fe9b902bd7 [file] [log] [blame]
Brian Silverman38658b02015-09-13 02:25:50 -04001def _single_queue_file_impl(ctx):
2 args = [
3 '-h_file_path', ctx.outputs.header.path,
4 '-cc_file_path', ctx.outputs.cc.path,
5 '-src_filename', ctx.file.src.short_path,
6 '-I', '.',
7 ctx.file.src.path,
8 ]
9 ctx.action(
10 outputs = [
11 ctx.outputs.header,
12 ctx.outputs.cc,
13 ],
14 inputs = [ ctx.file.src ] + ctx.attr.q_deps.transitive_q_files,
15 executable = ctx.executable._queue_compiler,
16 arguments = args,
17 mnemonic = 'QGen',
18 progress_message = 'Generating C++ code for %s' % ctx.file.src.short_path,
19 )
20
21def _single_queue_file_outputs(attrs):
22 return {
23 'header': attrs.src.name + '.h',
24 'cc': attrs.src.name + '.cc',
25 }
26
27_single_queue_file = rule(
28 implementation = _single_queue_file_impl,
29 attrs = {
30 'src': attr.label(
31 mandatory = True,
32 single_file = True,
33 allow_files = FileType(['.q']),
34 ),
35 'q_deps': attr.label(
36 providers = ['transitive_q_files'],
37 mandatory = True,
38 ),
39 'package_name': attr.string(
40 mandatory = True,
41 ),
42 '_queue_compiler': attr.label(
43 executable = True,
44 default = Label('//aos/build/queues:compiler'),
45 ),
46 },
47 outputs = _single_queue_file_outputs,
48 output_to_genfiles = True,
49)
50
51def _q_deps_impl(ctx):
52 transitive_q_files = ctx.files.srcs
53 for dep in ctx.attr.deps:
54 transitive_q_files += dep.transitive_q_files
55 return struct(transitive_q_files = transitive_q_files)
56
57_q_deps = rule(
58 implementation = _q_deps_impl,
59 attrs = {
60 'srcs': attr.label_list(
61 mandatory = True,
62 non_empty = True,
63 allow_files = FileType(['.q']),
64 ),
65 'deps': attr.label_list(
66 mandatory = True,
67 non_empty = False,
68 providers = ['transitive_q_files'],
69 ),
70 },
71)
72
73'''Creates a C++ library from a set of .q files.
74
75Attrs:
76 srcs: A list of .q files.
77 deps: Other queue_library rules this one depends on.
78'''
79def queue_library(name, srcs, deps = [],
80 visibility = None):
81 q_deps = _q_deps(
82 name = name + '__q_deps',
83 srcs = srcs,
84 deps = [dep + '__q_deps' for dep in deps],
85 visibility = visibility,
86 )
87
88 for src in srcs:
89 _single_queue_file(
90 name = name + '_' + src,
91 src = src,
92 q_deps = ':%s__q_deps' % name,
93 package_name = PACKAGE_NAME,
94 visibility = ['//visibility:private'],
95 )
96
97 native.cc_library(
98 name = name,
99 srcs = [src + '.cc' for src in srcs],
100 hdrs = [src + '.h' for src in srcs],
101 deps = deps + [
102 '//aos/common:once',
103 '//aos/common:queues',
104 '//aos/common:queue_types',
Brian Silvermancb5da1f2015-12-05 22:19:58 -0500105 '//aos/common/logging:printf_formats',
Brian Silverman38658b02015-09-13 02:25:50 -0400106 ],
107 visibility = visibility,
108 )