@@ -5,7 +5,6 @@ load("@rules_ecsact//ecsact/private:ecsact_codegen_plugin.bzl", "EcsactCodegenPl
5
5
6
6
def _cc_ecsact_codegen_plugin_impl (ctx ):
7
7
# type: (ctx) -> list
8
-
9
8
plugin = None # type: File | None
10
9
files = ctx .attr .cc_binary [DefaultInfo ].files .to_list () # type: list[File]
11
10
@@ -30,6 +29,7 @@ def _cc_ecsact_codegen_plugin_impl(ctx):
30
29
),
31
30
EcsactCodegenPluginInfo (
32
31
output_extension = ctx .attr .output_extension ,
32
+ outputs = ctx .attr .outputs ,
33
33
plugin = plugin ,
34
34
data = [plugin ],
35
35
),
@@ -39,7 +39,8 @@ _cc_ecsact_codegen_plugin = rule(
39
39
implementation = _cc_ecsact_codegen_plugin_impl ,
40
40
attrs = {
41
41
"cc_binary" : attr .label (mandatory = True ),
42
- "output_extension" : attr .string (mandatory = True ),
42
+ "output_extension" : attr .string (mandatory = False ),
43
+ "outputs" : attr .string_list (mandatory = False )
43
44
},
44
45
)
45
46
@@ -53,10 +54,16 @@ const char* ecsact_codegen_plugin_name() {{
53
54
54
55
def _cc_ecsact_codegen_plugin_src_impl (ctx ):
55
56
output_cc_src = ctx .actions .declare_file ("{}.plugin_name.cc" .format (ctx .attr .name ))
56
- ctx .actions .write (
57
- output = output_cc_src ,
58
- content = _generated_src .format (output_extension = ctx .attr .output_extension ),
59
- )
57
+ if ctx .attr .output_extension != None :
58
+ ctx .actions .write (
59
+ output = output_cc_src ,
60
+ content = _generated_src .format (output_extension = ctx .attr .output_extension ),
61
+ )
62
+ else :
63
+ ctx .actions .write (
64
+ output = output_cc_src ,
65
+ content = _generated_src .format (output_extension = ctx .attr .name ),
66
+ )
60
67
61
68
return [
62
69
DefaultInfo (files = depset ([output_cc_src ])),
@@ -65,11 +72,11 @@ def _cc_ecsact_codegen_plugin_src_impl(ctx):
65
72
_cc_ecsact_codegen_plugin_src = rule (
66
73
implementation = _cc_ecsact_codegen_plugin_src_impl ,
67
74
attrs = {
68
- "output_extension" : attr .string (mandatory = True ),
75
+ "output_extension" : attr .string (mandatory = False ),
69
76
},
70
77
)
71
78
72
- def cc_ecsact_codegen_plugin (name = None , srcs = [], deps = [], defines = [], no_validate_test = False , output_extension = None , ** kwargs ):
79
+ def cc_ecsact_codegen_plugin (name = None , srcs = [], deps = [], defines = [], no_validate_test = False , output_extension = None , outputs = [], ** kwargs ):
73
80
"""Create ecsact codegen plugin with C++
74
81
75
82
NOTE: ecsact_codegen_plugin_name() is automatically generated for you based
@@ -80,10 +87,14 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
80
87
srcs: Passed to underling cc_binary
81
88
deps: Passed to underling cc_binary
82
89
defines: Passed to underling cc_binary
83
- output_extension: File extension the plugin writes to
90
+ output_extension: File extension the plugin writes to. Cannot be used with outputs
91
+ outputs: A list of well known filenames to output. Cannot be used with output_extension
84
92
no_validate_test: Don't create plugin validation test (not recommended)
85
93
**kwargs: Passed to underling cc_binary
86
94
"""
95
+ if output_extension and len (outputs ) != 0 :
96
+ fail ("You cannot use both output extension and outputs" )
97
+
87
98
name_hash = hash (name )
88
99
cc_binary (
89
100
name = "{}__bin" .format (name_hash ),
@@ -101,13 +112,19 @@ def cc_ecsact_codegen_plugin(name = None, srcs = [], deps = [], defines = [], no
101
112
** kwargs
102
113
)
103
114
104
- _cc_ecsact_codegen_plugin_src (
105
- name = "{}__src" .format (name_hash ),
106
- output_extension = output_extension ,
107
- )
115
+ if (output_extension != None ):
116
+ _cc_ecsact_codegen_plugin_src (
117
+ name = "{}__src" .format (name_hash ),
118
+ output_extension = output_extension ,
119
+ )
120
+ else :
121
+ _cc_ecsact_codegen_plugin_src (
122
+ name = "{}__src" .format (name_hash ),
123
+ )
108
124
109
125
_cc_ecsact_codegen_plugin (
110
126
name = name ,
111
127
cc_binary = ":{}__bin" .format (name_hash ),
112
128
output_extension = output_extension ,
129
+ outputs = outputs
113
130
)
0 commit comments