blob: 91b49783cc135ca132f24282e0fcd60c3e2b3c98 [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
Brian Silvermanb200c172017-01-02 17:35:35 -080021def _single_queue_file_outputs(src):
Brian Silverman38658b02015-09-13 02:25:50 -040022 return {
Brian Silvermanb200c172017-01-02 17:35:35 -080023 'header': src.name + '.h',
24 'cc': src.name + '.cc',
Brian Silverman38658b02015-09-13 02:25:50 -040025 }
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,
Brian Silvermanb200c172017-01-02 17:35:35 -080033 allow_files = ['.q'],
Brian Silverman38658b02015-09-13 02:25:50 -040034 ),
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'),
Brian Silvermanb200c172017-01-02 17:35:35 -080045 cfg = 'host',
Brian Silverman38658b02015-09-13 02:25:50 -040046 ),
47 },
48 outputs = _single_queue_file_outputs,
49 output_to_genfiles = True,
50)
51
52def _q_deps_impl(ctx):
53 transitive_q_files = ctx.files.srcs
54 for dep in ctx.attr.deps:
55 transitive_q_files += dep.transitive_q_files
56 return struct(transitive_q_files = transitive_q_files)
57
58_q_deps = rule(
59 implementation = _q_deps_impl,
60 attrs = {
61 'srcs': attr.label_list(
62 mandatory = True,
63 non_empty = True,
Brian Silvermanb200c172017-01-02 17:35:35 -080064 allow_files = ['.q'],
Brian Silverman38658b02015-09-13 02:25:50 -040065 ),
66 'deps': attr.label_list(
67 mandatory = True,
68 non_empty = False,
69 providers = ['transitive_q_files'],
70 ),
71 },
72)
73
74'''Creates a C++ library from a set of .q files.
75
76Attrs:
77 srcs: A list of .q files.
78 deps: Other queue_library rules this one depends on.
79'''
80def queue_library(name, srcs, deps = [],
81 visibility = None):
82 q_deps = _q_deps(
83 name = name + '__q_deps',
84 srcs = srcs,
85 deps = [dep + '__q_deps' for dep in deps],
86 visibility = visibility,
87 )
88
89 for src in srcs:
90 _single_queue_file(
91 name = name + '_' + src,
92 src = src,
93 q_deps = ':%s__q_deps' % name,
94 package_name = PACKAGE_NAME,
95 visibility = ['//visibility:private'],
96 )
97
98 native.cc_library(
99 name = name,
100 srcs = [src + '.cc' for src in srcs],
101 hdrs = [src + '.h' for src in srcs],
102 deps = deps + [
103 '//aos/common:once',
104 '//aos/common:queues',
105 '//aos/common:queue_types',
Brian Silvermancb5da1f2015-12-05 22:19:58 -0500106 '//aos/common/logging:printf_formats',
Brian Silverman38658b02015-09-13 02:25:50 -0400107 ],
108 visibility = visibility,
109 )