@@ -31,10 +31,6 @@ template("_chip_build_time_codegen") {
31
31
_name = target_name
32
32
_generator = invoker .generator
33
33
34
- config (" ${ _name } _config" ) {
35
- include_dirs = [ target_gen_dir ]
36
- }
37
-
38
34
pw_python_action (" ${ _name } _generate" ) {
39
35
script = " ${ chip_root } /scripts/codegen.py"
40
36
@@ -124,10 +120,6 @@ template("_chip_build_time_zapgen") {
124
120
_name = target_name
125
121
_generator = invoker .generator
126
122
127
- config (" ${ _name } _config" ) {
128
- include_dirs = [ " ${ target_gen_dir } /zapgen/" ]
129
- }
130
-
131
123
assert (_generator == " app-templates" )
132
124
133
125
if (_generator == " app-templates" ) {
@@ -225,6 +217,9 @@ template("_chip_build_time_zapgen") {
225
217
# generator
226
218
# Name of the generator to use (e.g. java-jni, java-class, cpp-app)
227
219
#
220
+ # outputs MUST share the same directory prefix (e.g. 'app/' or 'tlv/meta'
221
+ # or 'jni')
222
+ #
228
223
# outputs
229
224
# Explicit names of the expected outputs. Enforced to validate that
230
225
# expected outputs are generated when processing input files.
@@ -265,7 +260,17 @@ template("_chip_build_time_zapgen") {
265
260
# ]
266
261
# }
267
262
#
263
+ # Guarantees a target named "${target_name}_generate" exists and contains all
264
+ # generated files (this works even in the case of using a pre-generated directory
265
+ # by using a copy target to import pre-generated data)
266
+ #
268
267
template (" chip_codegen" ) {
268
+ _name = target_name
269
+
270
+ config (" ${ _name } _config" ) {
271
+ include_dirs = [ target_gen_dir ]
272
+ }
273
+
269
274
if (chip_code_pre_generated_directory == " " ) {
270
275
_chip_build_time_codegen (target_name ) {
271
276
forward_variables_from (invoker ,
@@ -279,8 +284,6 @@ template("chip_codegen") {
279
284
])
280
285
}
281
286
} else {
282
- _name = target_name
283
-
284
287
not_needed (invoker , [ " options" ])
285
288
286
289
# This constructs a path like:
@@ -292,8 +295,21 @@ template("chip_codegen") {
292
295
string_replace (rebase_path (invoker .input , chip_root ), " .matter" , " " ) +
293
296
" /codegen/" + invoker .generator
294
297
295
- config (" ${ _name } _config" ) {
296
- include_dirs = [ " ${ _generation_dir } " ]
298
+ # Generation in this case just involves some files copying
299
+ copy (" ${ _name } _generate" ) {
300
+ sources = []
301
+
302
+ foreach (name , invoker .outputs ) {
303
+ sources += [ " ${ _generation_dir } /${ name } " ]
304
+ }
305
+
306
+ # NOTE: we assume ALL outputs have a common subdir. This is generally the case with
307
+ # paths like "app/callback-stub.cpp" and "app/PluginApplicationCallbacks.h"
308
+ _outputs = invoker .outputs
309
+ _dir_name = get_path_info (_outputs [0 ], " dir" )
310
+ outputs = [ " ${ target_gen_dir } /${ _dir_name } /{{source_file_part}}" ]
311
+
312
+ public_configs = [ " :${ _name } _config" ]
297
313
}
298
314
299
315
source_set (_name ) {
@@ -302,13 +318,13 @@ template("chip_codegen") {
302
318
if (defined (invoker .public_configs )) {
303
319
public_configs += invoker .public_configs
304
320
}
321
+ sources = get_target_outputs (" :${ _name } _generate" )
305
322
306
323
forward_variables_from (invoker , [ " deps" ])
307
-
308
- sources = []
309
- foreach (name , invoker .outputs ) {
310
- sources += [ " ${ _generation_dir } /${ name } " ]
324
+ if (! defined (deps )) {
325
+ deps = []
311
326
}
327
+ deps += [ " :${ _name } _generate" ]
312
328
}
313
329
}
314
330
}
@@ -327,6 +343,9 @@ template("chip_codegen") {
327
343
# Explicit names of the expected outputs. Enforced to validate that
328
344
# expected outputs are generated when processing input files.
329
345
#
346
+ # outputs MUST share the same directory prefix (e.g. 'app/' or 'tlv/meta'
347
+ # or 'jni')
348
+ #
330
349
# deps, public_configs
331
350
# Forwarded to the resulting source set
332
351
#
@@ -352,18 +371,28 @@ template("chip_codegen") {
352
371
#
353
372
# Example usage:
354
373
#
355
- # chip_codegen("java-jni-generate ") {
356
- # input = "controller-clusters.matter "
357
- # generator = "java-jni "
374
+ # chip_zapgen("controller-clusters-zap ") {
375
+ # input = "controller-clusters.zap "
376
+ # generator = "app-templates "
358
377
#
359
- # outputs = [
360
- # "jni/IdentifyClient-ReadImpl.cpp",
361
- # "jni/IdentifyClient-InvokeSubscribeImpl.cpp",
362
- # # ... more to follow
363
- # ]
364
- # }
378
+ # outputs = [
379
+ # "zap-generated/access.h",
380
+ # "zap-generated/gen_config.h",
381
+ # "zap-generated/endpoint_config.h",
382
+ # ]
383
+ # }
384
+ #
385
+ # Guarantees a target named "${target_name}_generate" exists and contains all
386
+ # generated files (this works even in the case of using a pre-generated directory
387
+ # by using a copy target to import pre-generated data)
365
388
#
366
389
template (" chip_zapgen" ) {
390
+ _name = target_name
391
+
392
+ config (" ${ _name } _config" ) {
393
+ include_dirs = [ " ${ target_gen_dir } /zapgen/" ]
394
+ }
395
+
367
396
if (chip_code_pre_generated_directory == " " ) {
368
397
_chip_build_time_zapgen (target_name ) {
369
398
forward_variables_from (invoker ,
@@ -376,8 +405,6 @@ template("chip_zapgen") {
376
405
])
377
406
}
378
407
} else {
379
- _name = target_name
380
-
381
408
# This contstructs a path like:
382
409
# FROM all-clusters-app.zap (inside examples/all-clusters-app/all-clusters-common/)
383
410
# USING "cpp-app" for generator:
@@ -387,10 +414,6 @@ template("chip_zapgen") {
387
414
string_replace (rebase_path (invoker .input , chip_root ), " .zap" , " " ) +
388
415
" /zap/" + invoker .generator
389
416
390
- config (" ${ _name } _config" ) {
391
- include_dirs = [ " ${ _generation_dir } " ]
392
- }
393
-
394
417
# Pick up only the headers and mark them available to use
395
418
# Specifically controller seems to require header files but NOT cpp (does)
396
419
# not want to include cpp compilation of IM command handler data
@@ -429,6 +452,23 @@ template("chip_zapgen") {
429
452
public_deps = [ " :${ _name } _headers" ]
430
453
}
431
454
455
+ # Generation in this case just involves some files copying
456
+ copy (" ${ _name } _generate" ) {
457
+ sources = []
458
+
459
+ foreach (name , invoker .outputs ) {
460
+ sources += [ " ${ _generation_dir } /${ name } " ]
461
+ }
462
+
463
+ # NOTE: we assume ALL outputs have a common subdir. This is generally the case with
464
+ # paths like "app/callback-stub.cpp" and "app/PluginApplicationCallbacks.h"
465
+ _outputs = invoker .outputs
466
+ _dir_name = get_path_info (_outputs [0 ], " dir" )
467
+ outputs = [ " ${ target_gen_dir } /zapgen/${ _dir_name } /{{source_file_part}}" ]
468
+
469
+ public_configs = [ " :${ _name } _config" ]
470
+ }
471
+
432
472
source_set (_name ) {
433
473
forward_variables_from (invoker ,
434
474
[
@@ -440,10 +480,12 @@ template("chip_zapgen") {
440
480
}
441
481
public_configs += [ " :${ _name } _config" ]
442
482
443
- sources = []
444
- foreach (name , invoker .outputs ) {
445
- sources += [ " ${ _generation_dir } /${ name } " ]
483
+ if (! defined (public_deps )) {
484
+ public_deps = []
446
485
}
486
+ public_deps += [ " :${ _name } _generate" ]
487
+
488
+ sources = get_target_outputs (" :${ _name } _generate" )
447
489
448
490
# Ugly, but references WILL reference back into main code.
449
491
check_includes = false
0 commit comments