Skip to content

Commit bfd91c6

Browse files
xitskaemesare
authored andcommitted
[BNTL] Implement compiler flags field for Create From Directory
1 parent e2bcf29 commit bfd91c6

2 files changed

Lines changed: 50 additions & 2 deletions

File tree

plugins/bntl_utils/src/command/create.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ impl PlatformField {
124124
}
125125
}
126126

127+
pub struct FlagsField;
128+
129+
impl FlagsField {
130+
pub fn field() -> FormInputField {
131+
FormInputField::MultilineText {
132+
prompt: "Compiler flags".to_string(),
133+
default: None,
134+
value: None,
135+
}
136+
}
137+
138+
pub fn from_form(form: &Form) -> Option<String> {
139+
let field = form.get_field_with_name("Compiler flags")?;
140+
field.try_value_string()
141+
}
142+
}
143+
127144
pub struct CreateFromDirectory;
128145

129146
impl CreateFromDirectory {
@@ -134,20 +151,24 @@ impl CreateFromDirectory {
134151
form.add_field(PlatformField::field());
135152
form.add_field(NameField::field());
136153
form.add_field(OutputDirectoryField::field());
154+
form.add_field(FlagsField::field());
155+
137156
if !form.prompt() {
138157
return;
139158
}
140159
let input_dir = InputDirectoryField::from_form(&form).unwrap();
141160
let platform_name = PlatformField::from_form(&form).unwrap();
142161
let default_name = NameField::from_form(&form).unwrap();
143162
let output_dir = OutputDirectoryField::from_form(&form).unwrap();
163+
let flags = FlagsField::from_form(&form).unwrap();
144164

145165
let Some(default_platform) = Platform::by_name(&platform_name) else {
146166
tracing::error!("Invalid platform name: {}", platform_name);
147167
return;
148168
};
149169

150-
let processor = TypeLibProcessor::new(&default_name, &default_platform.name());
170+
let processor = TypeLibProcessor::new(&default_name, &default_platform.name())
171+
.with_options(split_args(flags.as_str()));
151172

152173
let background_task = BackgroundTask::new("Processing started...", true);
153174
new_processing_state_background_thread(background_task.clone(), processor.state());
@@ -274,3 +295,22 @@ impl ProjectCommand for CreateFromProject {
274295
true
275296
}
276297
}
298+
299+
fn split_args(input: &str) -> Vec<String> {
300+
let mut args = Vec::new();
301+
let mut cur = String::new();
302+
let mut in_quote = false;
303+
let mut has_token = false;
304+
305+
for c in input.chars() {
306+
match c {
307+
'"' => { in_quote = !in_quote; has_token = true; }
308+
c if c.is_whitespace() && !in_quote => {
309+
if has_token { args.push(std::mem::take(&mut cur)); has_token = false; }
310+
}
311+
c => { cur.push(c); has_token = true; }
312+
}
313+
}
314+
if has_token { args.push(cur); }
315+
args
316+
}

plugins/bntl_utils/src/process.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ pub struct TypeLibProcessor {
434434
include_directories: Vec<PathBuf>,
435435
/// Whether to process existing type libraries when processing a binary file.
436436
process_existing_type_libraries: bool,
437+
/// The compiler flags to use when processing header files.
438+
options: Vec<String>,
437439
}
438440

439441
impl TypeLibProcessor {
@@ -448,6 +450,7 @@ impl TypeLibProcessor {
448450
default_platform_name: default_platform_name.to_owned(),
449451
include_directories: Vec::new(),
450452
process_existing_type_libraries: false,
453+
options: Vec::new(),
451454
}
452455
}
453456

@@ -461,6 +464,11 @@ impl TypeLibProcessor {
461464
self
462465
}
463466

467+
pub fn with_options(mut self, options: Vec<String>) -> Self {
468+
self.options = options;
469+
self
470+
}
471+
464472
/// Whether to process existing type libraries when processing a binary file.
465473
///
466474
/// If you open `mymodule.dll` and it imports functions from `kernel32.dll`, any import found
@@ -988,7 +996,7 @@ impl TypeLibProcessor {
988996
&file_name,
989997
&platform,
990998
&platform_type_container,
991-
&[],
999+
&self.options,
9921000
&include_dirs,
9931001
"",
9941002
)

0 commit comments

Comments
 (0)