|
1 | 1 | use clap::{Parser, ValueEnum};
|
2 | 2 | use log::LevelFilter;
|
3 | 3 | use regex::Regex;
|
4 |
| -use std::{fs, path::PathBuf}; |
| 4 | +use std::{fs, path::PathBuf, collections::HashSet}; |
5 | 5 |
|
6 | 6 | use c2rust_transpile::{Derive, Diagnostic, ReplaceMode, TranspilerConfig};
|
7 | 7 |
|
@@ -194,12 +194,6 @@ impl ExtraDerive {
|
194 | 194 | fn main() {
|
195 | 195 | let args = Args::parse();
|
196 | 196 |
|
197 |
| - let derives = DEFAULT_DERIVES |
198 |
| - .iter() |
199 |
| - .cloned() |
200 |
| - .chain(args.extra_derives.iter().map(|d| d.to_transpiler_derive())) |
201 |
| - .collect(); |
202 |
| - |
203 | 197 | // Build a TranspilerConfig from the command line
|
204 | 198 | let mut tcfg = TranspilerConfig {
|
205 | 199 | dump_untyped_context: args.dump_untyped_clang_ast,
|
@@ -249,7 +243,7 @@ fn main() {
|
249 | 243 | emit_no_std: args.emit_no_std,
|
250 | 244 | enabled_warnings: args.warn.into_iter().collect(),
|
251 | 245 | log_level: args.log_level,
|
252 |
| - derives, |
| 246 | + derives: get_derives(&args.extra_derives), |
253 | 247 | };
|
254 | 248 | // binaries imply emit-build-files
|
255 | 249 | if !tcfg.binaries.is_empty() {
|
@@ -295,3 +289,15 @@ fn main() {
|
295 | 289 | .expect("Failed to remove temporary compile_commands.json");
|
296 | 290 | }
|
297 | 291 | }
|
| 292 | + |
| 293 | +fn get_derives(extra_derives: &[ExtraDerive]) -> Vec<Derive> { |
| 294 | + // Make sure there are no dupes and sort so the derives are always in the same order |
| 295 | + let derives_set: HashSet<_> = DEFAULT_DERIVES |
| 296 | + .iter() |
| 297 | + .cloned() |
| 298 | + .chain(extra_derives.iter().map(|d| d.to_transpiler_derive())) |
| 299 | + .collect(); |
| 300 | + let mut derives: Vec<Derive> = derives_set.into_iter().collect(); |
| 301 | + derives.sort(); |
| 302 | + derives |
| 303 | +} |
0 commit comments