Skip to content

Commit

Permalink
Merge pull request #620 from GuillaumeGomez/prevent-useless-generation
Browse files Browse the repository at this point in the history
Prevent some useless generations
  • Loading branch information
EPashkin committed Jul 5, 2018
2 parents 4c7ff69 + 1b13a07 commit d0f0425
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
8 changes: 5 additions & 3 deletions src/codegen/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
}
}

if !has_any {
return
}

let mut imports = Imports::new(&env.library);
imports.add("ffi", None);
if has_get_quark {
Expand All @@ -63,9 +67,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
try!(general::uses(w, env, &imports));
try!(writeln!(w));

if has_any {
mod_rs.push("\nmod enums;".into());
}
mod_rs.push("\nmod enums;".into());
for config in &configs {
if let Type::Enumeration(ref enum_) = *env.library.type_(config.type_id.unwrap()) {
if let Some(cfg) = version_condition_string(env, enum_.version, false, 0) {
Expand Down
35 changes: 22 additions & 13 deletions src/codegen/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,29 @@ use std::path::Path;
use traits::*;

pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
let configs: Vec<&GObject> = env.config
.objects
.values()
.filter(|c| {
c.status.need_generate()
&& c.type_id.map_or(false,
|tid| tid.ns_id == namespaces::MAIN)
})
.collect();
let has_any = configs.iter()
.any(|c| {
if let Type::Bitfield(_) = *env.library.type_(c.type_id.unwrap()) {
true
} else {
false
}
});

if !has_any {
return
}
let path = root_path.join("flags.rs");
file_saver::save_to_file(path, env.config.make_backup, |w| {
let configs: Vec<&GObject> = env.config
.objects
.values()
.filter(|c| {
c.status.need_generate()
&& c.type_id.map_or(false, |tid| tid.ns_id == namespaces::MAIN)
})
.collect();

let mut imports = Imports::new(&env.library);
imports.add("ffi", None);
Expand All @@ -45,13 +58,9 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
try!(general::uses(w, env, &imports));
try!(writeln!(w));

let mut first = true;
for config in &configs {
if let Type::Bitfield(ref flags) = *env.library.type_(config.type_id.unwrap()) {
if first {
mod_rs.push("\nmod flags;".into());
first = false;
}
mod_rs.push("\nmod flags;".into());
if let Some(cfg) = version_condition_string(env, flags.version, false, 0) {
mod_rs.push(cfg);
}
Expand Down

0 comments on commit d0f0425

Please sign in to comment.