bender 0.31.0

A dependency management tool for hardware projects.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
// Copyright (c) 2017-2018 ETH Zurich
// Fabian Schuiki <fschuiki@iis.ee.ethz.ch>

//! The `script` subcommand.

use std::io::Write;
use std::path::{Path, PathBuf};

use clap::{ArgAction, Args, Subcommand, ValueEnum};
use indexmap::{IndexMap, IndexSet};
use serde::Serialize;
use tera::{Context, Tera};
use tokio::runtime::Runtime;

use crate::cmd::sources::get_passed_targets;
use crate::config::{Validate, ValidationContext};
use crate::diagnostic::Warnings;
use crate::error::*;
use crate::sess::{Session, SessionIo};
use crate::src::{SourceFile, SourceGroup, SourceType};
use crate::target::TargetSet;

/// Emit tool scripts for the package
#[derive(Args, Debug)]
pub struct ScriptArgs {
    /// Only include sources that match the given target
    #[arg(short, long, action = ArgAction::Append, global = true, help_heading = "General Script Options")]
    pub target: Vec<String>,

    /// Remove any default targets that may be added to the generated script
    #[arg(long, global = true, help_heading = "General Script Options")]
    pub no_default_target: bool,

    /// Pass an additional define to all source files
    #[arg(short = 'D', long, action = ArgAction::Append, global = true, help_heading = "General Script Options")]
    pub define: Vec<String>,

    /// Include source annotations in the generated script
    #[arg(long, global = true, help_heading = "General Script Options")]
    pub source_annotations: bool,

    /// Specify package to show sources for
    #[arg(short, long, action = ArgAction::Append, global = true, help_heading = "General Script Options")]
    pub package: Vec<String>,

    /// Exclude all dependencies, i.e. only top level or specified package(s)
    #[arg(short, long, global = true, help_heading = "General Script Options")]
    pub no_deps: bool,

    /// Specify package to exclude from sources
    #[arg(short, long, action = ArgAction::Append, global = true, help_heading = "General Script Options")]
    pub exclude: Vec<String>,

    /// Add the `rtl` target to any fileset without a target specification
    #[arg(long, global = true, help_heading = "General Script Options")]
    pub assume_rtl: bool,

    /// Ignore passed targets
    #[arg(long, global = true, help_heading = "General Script Options")]
    pub ignore_passed_targets: bool,

    /// Choose compilation mode option
    #[arg(
        long,
        default_value_t,
        value_enum,
        global = true,
        help_heading = "General Script Options"
    )]
    pub compilation_mode: CompilationMode,

    /// Do not abort analysis/compilation on first caught error
    #[arg(long, global = true, help_heading = "General Script Options")]
    pub no_abort_on_error: bool,

    /// Format of the generated script
    #[command(subcommand)]
    pub format: ScriptFormat,
}

/// Compilation mode enum
#[derive(Copy, Clone, Debug, PartialEq, Eq, ValueEnum, Serialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum CompilationMode {
    #[default]
    /// Compile each source file group separately
    Separate,
    /// Compile all source file groups together in a common compilation unit
    Common,
}

/// Common arguments for Vivado scripts
#[derive(Args, Debug, Clone)]
pub struct OnlyArgs {
    /// Only output commands to define macros
    #[arg(long = "only-defines", group = "only")]
    pub defines: bool,

    /// Only output commands to define include directories
    #[arg(long = "only-includes", group = "only")]
    pub includes: bool,

    /// Only output commands to define source files
    #[arg(long = "only-sources", group = "only")]
    pub sources: bool,
}

/// Script format enum
#[derive(Subcommand, Debug)]
pub enum ScriptFormat {
    /// A general file list
    Flist {
        /// Use relative paths
        #[arg(long)]
        relative_path: bool,
    },
    /// An extended file list with include dirs and defines
    FlistPlus {
        /// Use relative paths
        #[arg(long)]
        relative_path: bool,

        /// Common arguments for Vivado scripts
        #[command(flatten)]
        only: OnlyArgs,
    },
    /// ModelSim/QuestaSim script
    Vsim {
        /// Pass arguments to vlog calls
        #[arg(long, action = ArgAction::Append, alias = "vlog-arg")]
        vlog_args: Vec<String>,

        /// Pass arguments to vcom calls
        #[arg(long, action = ArgAction::Append, alias = "vcom-arg")]
        vcom_args: Vec<String>,
    },
    /// Synopsys VCS script
    Vcs {
        /// Pass arguments to vlogan calls
        #[arg(long, action = ArgAction::Append, alias = "vlog-arg")]
        vlogan_args: Vec<String>,

        /// Pass arguments to vhdlan calls
        #[arg(long, action = ArgAction::Append, alias = "vcom-arg")]
        vhdlan_args: Vec<String>,

        /// Specify a `vlogan` command
        #[arg(long, default_value = "vlogan")]
        vlogan_bin: String,

        /// Specify a `vhdlan` command
        #[arg(long, default_value = "vhdlan")]
        vhdlan_bin: String,
    },
    /// Verilator script
    Verilator {
        /// Pass arguments to verilator calls
        #[arg(long, action = ArgAction::Append, alias = "vlog-arg")]
        vlt_args: Vec<String>,
    },
    /// Synopsys EDA tool script
    Synopsys {
        /// Pass arguments to verilog compilation calls
        #[arg(long, action = ArgAction::Append, alias = "vlog-arg")]
        verilog_args: Vec<String>,

        /// Pass arguments to vhdl compilation calls
        #[arg(long, action = ArgAction::Append, alias = "vcom-arg")]
        vhdl_args: Vec<String>,
    },
    /// Synopsys Formality script
    Formality,
    /// Riviera script
    Riviera {
        /// Pass arguments to vlog calls
        #[arg(long, action = ArgAction::Append, alias = "vlog-arg")]
        vlog_args: Vec<String>,

        /// Pass arguments to vcom calls
        #[arg(long, action = ArgAction::Append, alias = "vcom-arg")]
        vcom_args: Vec<String>,
    },
    /// Cadence Genus script
    Genus,
    /// Xilinx Vivado synthesis script
    Vivado {
        /// Do not change `simset` fileset
        #[arg(long)]
        no_simset: bool,

        /// Common arguments for Vivado scripts
        #[command(flatten)]
        only: OnlyArgs,
    },
    /// Xilinx Vivado simulation script
    VivadoSim {
        /// Do not change `simset` fileset
        #[arg(long)]
        no_simset: bool,

        /// Common arguments for Vivado scripts
        #[command(flatten)]
        only: OnlyArgs,
    },
    /// Mentor Graphics Precision script
    Precision,
    /// Custom template script
    Template {
        /// Path to a file containing the tera template string to be formatted.
        #[arg(long)]
        template: String,
    },
    /// JSON output
    #[command(alias = "template_json")]
    TemplateJson,
}

fn get_package_strings<I>(packages: I) -> IndexSet<String>
where
    I: IntoIterator,
    I::Item: AsRef<str>,
{
    packages
        .into_iter()
        .map(|t| t.as_ref().to_string().to_lowercase())
        .collect()
}

/// Execute the `script` subcommand.
pub fn run(sess: &Session, args: &ScriptArgs) -> Result<()> {
    let rt = Runtime::new()?;
    let io = SessionIo::new(sess);
    let mut srcs = rt.block_on(io.sources(false, &[]))?;

    // Format-specific target specifiers.
    let vivado_targets = &["vivado", "fpga", "xilinx"];
    fn concat<T: Clone>(a: &[T], b: &[T]) -> Vec<T> {
        a.iter().chain(b).cloned().collect()
    }
    let format_targets: Vec<&str> = if !args.no_default_target {
        match args.format {
            ScriptFormat::Flist { .. } => vec!["flist"],
            ScriptFormat::FlistPlus { .. } => vec!["flist"],
            ScriptFormat::Vsim { .. } => vec!["vsim", "simulation"],
            ScriptFormat::Vcs { .. } => vec!["vcs", "simulation"],
            ScriptFormat::Verilator { .. } => vec!["verilator", "synthesis"],
            ScriptFormat::Synopsys { .. } => vec!["synopsys", "synthesis"],
            ScriptFormat::Formality => vec!["synopsys", "synthesis", "formality"],
            ScriptFormat::Riviera { .. } => vec!["riviera", "simulation"],
            ScriptFormat::Genus => vec!["genus", "synthesis"],
            ScriptFormat::Vivado { .. } => concat(vivado_targets, &["synthesis"]),
            ScriptFormat::VivadoSim { .. } => concat(vivado_targets, &["simulation"]),
            ScriptFormat::Precision => vec!["precision", "fpga", "synthesis"],
            ScriptFormat::Template { .. } => vec![],
            ScriptFormat::TemplateJson => vec![],
        }
    } else {
        vec![]
    };

    // Filter the sources by target.
    let targets = TargetSet::new(args.target.iter().map(|s| s.as_str()).chain(format_targets));

    if args.assume_rtl {
        srcs = srcs.assign_target("rtl".to_string());
    }

    // Filter the sources by specified packages.
    let packages = &srcs.get_package_list(
        sess.manifest.package.name.to_string(),
        &get_package_strings(&args.package),
        &get_package_strings(&args.exclude),
        args.no_deps,
    );

    let (all_targets, used_packages) = get_passed_targets(
        sess,
        &rt,
        &io,
        &targets,
        packages,
        &get_package_strings(&args.package),
    )?;

    let targets = if args.ignore_passed_targets {
        targets
    } else {
        all_targets
    };

    let packages = if args.ignore_passed_targets {
        packages.clone()
    } else {
        used_packages
    };

    srcs = srcs.filter_targets(&targets).unwrap_or_default();

    srcs = srcs.filter_packages(&packages).unwrap_or_default();

    // Flatten and validate the sources.
    let srcs = srcs
        .flatten()
        .into_iter()
        .map(|f| f.validate(&ValidationContext::default()))
        .collect::<Result<Vec<_>>>()?;

    let mut tera_context = Context::new();
    let mut only_args = OnlyArgs {
        defines: false,
        includes: false,
        sources: false,
    };

    // Generate the corresponding output.
    let template_content = match &args.format {
        ScriptFormat::Flist { relative_path } => {
            tera_context.insert("relativize_path", relative_path);
            include_str!("../script_fmt/flist.tera")
        }
        ScriptFormat::FlistPlus {
            relative_path,
            only,
        } => {
            tera_context.insert("relativize_path", relative_path);
            only_args = only.clone();
            include_str!("../script_fmt/flist-plus.tera")
        }
        ScriptFormat::Vsim {
            vlog_args,
            vcom_args,
        } => {
            tera_context.insert("vlog_args", vlog_args);
            tera_context.insert("vcom_args", vcom_args);
            include_str!("../script_fmt/vsim_tcl.tera")
        }
        ScriptFormat::Vcs {
            vlogan_bin,
            vhdlan_bin,
            vlogan_args,
            vhdlan_args,
        } => {
            tera_context.insert("vlogan_args", vlogan_args);
            tera_context.insert("vhdlan_args", vhdlan_args);
            tera_context.insert("vlogan_bin", vlogan_bin);
            tera_context.insert("vhdlan_bin", vhdlan_bin);
            include_str!("../script_fmt/vcs_sh.tera")
        }
        ScriptFormat::Verilator { vlt_args } => {
            tera_context.insert("vlt_args", vlt_args);
            include_str!("../script_fmt/verilator_sh.tera")
        }
        ScriptFormat::Synopsys {
            verilog_args,
            vhdl_args,
        } => {
            tera_context.insert("verilog_args", verilog_args);
            tera_context.insert("vhdl_args", vhdl_args);
            include_str!("../script_fmt/synopsys_tcl.tera")
        }
        ScriptFormat::Formality => include_str!("../script_fmt/formality_tcl.tera"),
        ScriptFormat::Riviera {
            vlog_args,
            vcom_args,
        } => {
            tera_context.insert("vlog_args", vlog_args);
            tera_context.insert("vcom_args", vcom_args);
            include_str!("../script_fmt/riviera_tcl.tera")
        }
        ScriptFormat::Genus => include_str!("../script_fmt/genus_tcl.tera"),
        ScriptFormat::Vivado { no_simset, only } | ScriptFormat::VivadoSim { no_simset, only } => {
            only_args = only.clone();
            tera_context.insert("vivado_filesets", &{
                if *no_simset {
                    vec![""]
                } else {
                    vec!["", " -simset"]
                }
            });
            include_str!("../script_fmt/vivado_tcl.tera")
        }
        ScriptFormat::Precision => include_str!("../script_fmt/precision_tcl.tera"),
        ScriptFormat::Template { template } => &std::fs::read_to_string(template)?,
        ScriptFormat::TemplateJson => JSON,
    };

    emit_template(sess, tera_context, template_content, args, only_args, srcs)
}

/// Subdivide the source files in a group.
///
/// The function `categorize` is used to assign a category to each source file.
/// Files with the same category that appear after each other will be kept in
/// the same source group. Files with different cateogries are split into
/// separate groups.
fn separate_files_in_group<F1, F2, T>(mut src: SourceGroup, categorize: F1, mut consume: F2)
where
    F1: Fn(&SourceFile) -> Option<T>,
    F2: FnMut(&SourceGroup, T, Vec<SourceFile>),
    T: Eq,
{
    let mut category = None;
    let mut files = vec![];
    for file in std::mem::take(&mut src.files) {
        let new_category = categorize(&file);
        if new_category.is_none() {
            continue;
        }
        if category.is_some() && category != new_category && !files.is_empty() {
            consume(&src, category.take().unwrap(), std::mem::take(&mut files));
        }
        files.push(file);
        category = new_category;
    }
    if !files.is_empty() {
        consume(&src, category.unwrap(), files);
    }
}

static HEADER_AUTOGEN: &str = "This script was generated automatically by bender.";

fn add_defines(defines: &mut IndexMap<String, Option<String>>, define_args: &[String]) {
    defines.extend(define_args.iter().map(|t| {
        let mut parts = t.splitn(2, '=');
        let name = parts.next().unwrap().trim();
        let value = parts.next().map(|v| v.trim().to_string());
        (name.to_string(), value)
    }));
}

static JSON: &str = "json";

fn emit_template(
    sess: &Session,
    mut tera_context: Context,
    template: &str,
    args: &ScriptArgs,
    only: OnlyArgs,
    srcs: Vec<SourceGroup>,
) -> Result<()> {
    tera_context.insert("HEADER_AUTOGEN", HEADER_AUTOGEN);
    tera_context.insert("root", sess.root);
    // tera_context.insert("srcs", &srcs);
    tera_context.insert("abort_on_error", &!args.no_abort_on_error);

    let mut global_defines = IndexMap::new();
    let emit_sources = !only.defines && !only.includes;
    let emit_defines = !only.includes && !only.sources;
    let emit_incdirs = !only.defines && !only.sources;

    add_defines(&mut global_defines, &args.define);
    tera_context.insert("global_defines", &global_defines);

    let mut all_defines = IndexMap::new();
    let mut all_incdirs = IndexSet::new();
    let mut all_files = IndexSet::new();
    let mut all_verilog = vec![];
    let mut all_vhdl = vec![];
    let mut unknown_files = vec![];
    let mut all_override_files: IndexSet<(&Path, &str)> = IndexSet::new();
    for src in &srcs {
        all_defines.extend(
            src.defines
                .iter()
                .map(|(k, &v)| (k.to_string(), v.map(String::from))),
        );
        all_incdirs.extend(src.clone().get_incdirs());

        // If override_files is set, source files are not automatically included, only to replace files with matching basenames.
        if src.override_files {
            all_override_files.extend(src.files.iter().filter_map(|file| match file {
                SourceFile::File(p, _) => Some((*p, src.package.unwrap_or("None"))),
                SourceFile::Group(_) => None,
            }));
        } else {
            all_files.extend(src.files.iter().filter_map(|file| match file {
                SourceFile::File(p, _) => Some((*p, None::<String>)),
                SourceFile::Group(_) => None,
            }));
        }
    }

    add_defines(&mut all_defines, &args.define);
    let all_defines = if emit_defines {
        all_defines.into_iter().collect()
    } else {
        IndexSet::new()
    };

    tera_context.insert("all_defines", &all_defines);

    all_incdirs.sort();
    let all_incdirs: IndexSet<PathBuf> = if emit_incdirs {
        all_incdirs.into_iter().map(|p| p.to_path_buf()).collect()
    } else {
        IndexSet::new()
    };
    tera_context.insert("all_incdirs", &all_incdirs);

    // replace files in all_files with override files
    let override_map = all_override_files
        .iter()
        .map(|(f, pkg)| {
            (
                f.file_name()
                    .and_then(std::ffi::OsStr::to_str)
                    .unwrap_or(""),
                (*f, pkg),
            )
        })
        .collect::<IndexMap<_, _>>();
    let all_files = all_files
        .into_iter()
        .map(|file| {
            let basename = file
                .0
                .file_name()
                .and_then(std::ffi::OsStr::to_str)
                .unwrap_or("");
            match override_map.get(&basename) {
                Some((new_path, pkg)) => FileEntry {
                    file: new_path.to_path_buf(),
                    comment: Some(format!(
                        "OVERRIDDEN from {}: {}",
                        pkg,
                        file.0.to_string_lossy()
                    )),
                },
                None => FileEntry {
                    file: file.0.to_path_buf(),
                    comment: file.1,
                },
            }
        })
        .collect::<IndexSet<_>>();

    if emit_sources {
        tera_context.insert("all_files", &all_files);
    }

    let mut split_srcs = vec![];
    for src in srcs {
        if src.override_files {
            continue;
        }
        separate_files_in_group(
            src,
            |f| match f {
                SourceFile::File(p, fmt) => match fmt {
                    Some(SourceType::Verilog) => Some(SourceType::Verilog),
                    Some(SourceType::Vhdl) => Some(SourceType::Vhdl),
                    _ => match p.extension().and_then(std::ffi::OsStr::to_str) {
                        Some("sv") | Some("v") | Some("vp") => Some(SourceType::Verilog),
                        Some("vhd") | Some("vhdl") => Some(SourceType::Vhdl),
                        _ => Some(SourceType::Unknown),
                    },
                },
                _ => None,
            },
            |src, ty, files| {
                split_srcs.push(TplSrcStruct {
                    metadata: {
                        let package = src.package.unwrap_or("None");
                        let target = src.target.reduce().to_string();
                        format!("Package({package}) Target({target})")
                    },
                    defines: {
                        let mut local_defines = IndexMap::new();
                        local_defines.extend(
                            src.defines
                                .iter()
                                .map(|(k, &v)| (k.to_string(), v.map(String::from))),
                        );

                        add_defines(&mut local_defines, &args.define);
                        local_defines.into_iter().collect()
                    },
                    incdirs: {
                        let mut incdirs = src
                            .clone()
                            .get_incdirs()
                            .iter()
                            .map(|p| p.to_path_buf())
                            .collect::<IndexSet<_>>();
                        incdirs.sort();
                        incdirs
                    },
                    files: files
                        .iter()
                        .map(|f| match f {
                            SourceFile::File(p, _) => {
                                let basename = p
                                    .file_name()
                                    .and_then(std::ffi::OsStr::to_str)
                                    .unwrap_or("");
                                match override_map.get(&basename) {
                                    Some((new_path, pkg)) => FileEntry {
                                        file: new_path.to_path_buf(),
                                        comment: Some(format!(
                                            "OVERRIDDEN from {}: {}",
                                            pkg,
                                            p.to_string_lossy()
                                        )),
                                    },
                                    None => FileEntry {
                                        file: p.to_path_buf(),
                                        comment: None,
                                    },
                                }
                            }
                            SourceFile::Group(_) => unreachable!(),
                        })
                        .collect(),
                    file_type: match ty {
                        SourceType::Verilog => "verilog".to_string(),
                        SourceType::Vhdl => "vhdl".to_string(),
                        SourceType::Unknown => "".to_string(),
                    },
                });
            },
        );
    }
    for src in &split_srcs {
        match src.file_type.as_str() {
            "verilog" => {
                all_verilog.append(&mut src.files.clone().into_iter().collect());
            }
            "vhdl" => {
                all_vhdl.append(&mut src.files.clone().into_iter().collect());
            }
            _ => {
                unknown_files.append(&mut src.files.clone().into_iter().collect());
            }
        }
    }
    let split_srcs = if emit_sources { split_srcs } else { vec![] };
    tera_context.insert("srcs", &split_srcs);

    let all_verilog = if emit_sources {
        all_verilog.into_iter().collect()
    } else {
        IndexSet::new()
    };
    let all_vhdl = if emit_sources {
        all_vhdl.into_iter().collect()
    } else {
        IndexSet::new()
    };
    tera_context.insert("all_verilog", &all_verilog);
    tera_context.insert("all_vhdl", &all_vhdl);
    if !unknown_files.is_empty() && template.contains("file_type") {
        Warnings::UnknownFileType(unknown_files.iter().map(|x| x.file.clone()).collect()).emit();
    }

    tera_context.insert("source_annotations", &args.source_annotations);
    tera_context.insert("compilation_mode", &args.compilation_mode);

    if template == "json" {
        let _ = writeln!(std::io::stdout(), "{:#}", tera_context.into_json());
        return Ok(());
    }

    let _ = write!(
        std::io::stdout(),
        "{}",
        Tera::default()
            .render_str(template, &tera_context)
            .map_err(|e| { Error::chain("Failed to render template.", e) })?
    );

    Ok(())
}

#[derive(Debug, Serialize, Hash, Eq, PartialEq, Clone)]
struct FileEntry {
    file: PathBuf,
    comment: Option<String>,
}

#[derive(Debug, Serialize)]
struct TplSrcStruct {
    metadata: String,
    defines: IndexSet<(String, Option<String>)>,
    incdirs: IndexSet<PathBuf>,
    files: IndexSet<FileEntry>,
    file_type: String,
}