Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Automatically assume that win32_ and unix_ should use the related cfg #1547

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/analysis/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Borrow;

use crate::{config, env::Env, library, nameutil, traits::*, update_cfgs, version::Version};
use crate::{config, env::Env, library, nameutil, traits::*, version::Version};

#[derive(Debug)]
pub struct Info {
Expand Down Expand Up @@ -49,7 +49,6 @@ pub fn analyze<F: Borrow<library::Constant>>(
let cfg_condition = configured_constants
.iter()
.find_map(|c| c.cfg_condition.clone());
let cfg_condition = update_cfgs::get_constant_cfg_condition(&constant.name, &cfg_condition);

let name = nameutil::mangle_keywords(&*constant.name).into_owned();

Expand Down
4 changes: 0 additions & 4 deletions src/analysis/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use crate::{
},
nameutil,
traits::*,
update_cfgs,
version::Version,
};

Expand Down Expand Up @@ -652,9 +651,6 @@ fn analyze_function(
let cfg_condition = configured_functions
.iter()
.find_map(|f| f.cfg_condition.clone());
let ns = env.library.namespace(ns_id);
let cfg_condition =
update_cfgs::get_cfg_condition(&func.name, &cfg_condition, &ns.symbol_prefixes);
let doc_hidden = configured_functions.iter().any(|f| f.doc_hidden);
let doc_trait_name = configured_functions
.iter()
Expand Down
2 changes: 0 additions & 2 deletions src/analysis/namespaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub struct Namespace {
pub higher_crate_name: String,
pub package_names: Vec<String>,
pub symbol_prefixes: Vec<String>,
pub identifier_prefixes: Vec<String>,
pub shared_libs: Vec<String>,
pub versions: Vec<Version>,
}
Expand Down Expand Up @@ -59,7 +58,6 @@ pub fn run(gir: &library::Library) -> Info {
higher_crate_name,
package_names: ns.package_names.clone(),
symbol_prefixes: ns.symbol_prefixes.clone(),
identifier_prefixes: ns.identifier_prefixes.clone(),
shared_libs: ns.shared_library.clone(),
versions: ns.versions.iter().copied().collect(),
});
Expand Down
11 changes: 2 additions & 9 deletions src/analysis/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
library::{self, FunctionKind},
nameutil::*,
traits::*,
update_cfgs,
};

/// The location of an item within the object
Expand Down Expand Up @@ -303,9 +302,6 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
imports.add("glib::prelude::*");
}

let ns = env.library.namespace(class_tid.ns_id);
let cfg_condition =
update_cfgs::get_object_cfg_condition(&name, &obj.cfg_condition, &ns.identifier_prefixes);
let base = InfoBase {
full_name,
type_id: class_tid,
Expand All @@ -315,7 +311,7 @@ pub fn class(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<Info>
imports,
version,
deprecated_version,
cfg_condition,
cfg_condition: obj.cfg_condition.clone(),
concurrency: obj.concurrency,
visibility: obj.visibility,
};
Expand Down Expand Up @@ -432,9 +428,6 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
deps,
);

let ns = env.library.namespace(iface_tid.ns_id);
let cfg_condition =
update_cfgs::get_object_cfg_condition(&name, &obj.cfg_condition, &ns.identifier_prefixes);
let base = InfoBase {
full_name,
type_id: iface_tid,
Expand All @@ -444,7 +437,7 @@ pub fn interface(env: &Env, obj: &GObject, deps: &[library::TypeId]) -> Option<I
imports,
version,
deprecated_version,
cfg_condition,
cfg_condition: obj.cfg_condition.clone(),
concurrency: obj.concurrency,
visibility: obj.visibility,
};
Expand Down
7 changes: 1 addition & 6 deletions src/analysis/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::{
library,
nameutil::*,
traits::*,
update_cfgs,
version::Version,
};

Expand Down Expand Up @@ -196,10 +195,6 @@ pub fn new(env: &Env, obj: &GObject) -> Option<Info> {
}
}

let ns = env.library.namespace(record_tid.ns_id);
let cfg_condition =
update_cfgs::get_object_cfg_condition(&name, &obj.cfg_condition, &ns.identifier_prefixes);

let base = InfoBase {
full_name,
type_id: record_tid,
Expand All @@ -209,7 +204,7 @@ pub fn new(env: &Env, obj: &GObject) -> Option<Info> {
imports,
version,
deprecated_version,
cfg_condition,
cfg_condition: obj.cfg_condition.clone(),
concurrency: obj.concurrency,
visibility: obj.visibility,
};
Expand Down
51 changes: 14 additions & 37 deletions src/codegen/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use crate::{
library::*,
nameutil::{enum_member_name, use_glib_if_needed, use_glib_type},
traits::*,
update_cfgs,
version::Version,
};

Expand Down Expand Up @@ -50,31 +49,10 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {

let enum_ = enum_analysis.type_(&env.library);

let ns = env.namespaces.main();
let full_name = format!("{}.{}", ns.name, enum_.name);
let cfg_condition = env
.config
.objects
.get(&full_name)
.and_then(|obj| {
update_cfgs::get_object_cfg_condition(
&obj.name,
&config.cfg_condition,
&ns.identifier_prefixes,
)
})
.or_else(|| {
update_cfgs::get_object_cfg_condition(
&enum_.name,
&None,
&ns.identifier_prefixes,
)
});

if let Some(cfg) = version_condition_string(env, None, enum_.version, false, 0) {
mod_rs.push(cfg);
}
if let Some(cfg) = cfg_condition_string(cfg_condition.as_ref(), false, 0) {
if let Some(cfg) = cfg_condition_string(config.cfg_condition.as_ref(), false, 0) {
mod_rs.push(cfg);
}
mod_rs.push(format!(
Expand All @@ -87,7 +65,7 @@ pub fn generate(env: &Env, root_path: &Path, mod_rs: &mut Vec<String>) {
enum_.name
));

generate_enum(env, w, enum_, config, enum_analysis, cfg_condition)?;
generate_enum(env, w, enum_, config, enum_analysis)?;
}

Ok(())
Expand All @@ -100,7 +78,6 @@ fn generate_enum(
enum_: &Enumeration,
config: &GObject,
analysis: &Info,
cfg_cond: Option<String>,
) -> Result<()> {
struct Member<'a> {
name: String,
Expand Down Expand Up @@ -148,7 +125,7 @@ fn generate_enum(
0,
)?;
version_condition(w, env, None, enum_.version, false, 0)?;
cfg_condition(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition(w, config.cfg_condition.as_ref(), false, 0)?;
if config.must_use {
writeln!(w, "#[must_use]")?;
}
Expand Down Expand Up @@ -217,7 +194,7 @@ fn generate_enum(
if !functions.is_empty() {
writeln!(w)?;
version_condition(w, env, None, enum_.version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
write!(w, "impl {} {{", analysis.name)?;
for func_analysis in functions {
Expand All @@ -244,7 +221,7 @@ fn generate_enum(
&analysis.specials,
None,
None,
cfg_cond.as_deref(),
config.cfg_condition.as_deref(),
)?;

writeln!(w)?;
Expand All @@ -258,7 +235,7 @@ fn generate_enum(

// Generate IntoGlib trait implementation.
version_condition(w, env, None, enum_.version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, any_deprecated_version, false, 0)?;
writeln!(
w,
Expand Down Expand Up @@ -315,7 +292,7 @@ impl IntoGlib for {name} {{

// Generate FromGlib trait implementation.
version_condition(w, env, None, enum_.version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, any_deprecated_version, false, 0)?;
writeln!(
w,
Expand Down Expand Up @@ -369,7 +346,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
let has_failed_member = members.iter().any(|m| m.name == "Failed");

version_condition(w, env, None, enum_.version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, any_deprecated_version, false, 0)?;
writeln!(
w,
Expand Down Expand Up @@ -440,7 +417,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
.flatten();

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand All @@ -462,7 +439,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
writeln!(w)?;

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand All @@ -483,7 +460,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
writeln!(w)?;

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand All @@ -496,7 +473,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
writeln!(w)?;

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand All @@ -518,7 +495,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
writeln!(w)?;

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand All @@ -545,7 +522,7 @@ impl FromGlib<{sys_crate_name}::{ffi_name}> for {name} {{
writeln!(w)?;

version_condition(w, env, None, version, false, 0)?;
cfg_condition_no_doc(w, cfg_cond.as_ref(), false, 0)?;
cfg_condition_no_doc(w, config.cfg_condition.as_ref(), false, 0)?;
allow_deprecated(w, enum_.deprecated_version, false, 0)?;
writeln!(
w,
Expand Down
16 changes: 6 additions & 10 deletions src/codegen/sys/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
env::Env,
library::*,
traits::{IntoString, MaybeRefAs},
update_cfgs,
};

pub struct Fields {
Expand Down Expand Up @@ -165,13 +164,10 @@ fn field_ffi_type(env: &Env, field: &Field) -> Result {
}

fn get_gobject_cfg_condition(env: &Env, name: &str) -> Option<String> {
let ns = env.namespaces.main();
let full_name = format!("{}.{}", ns.name, name);
env.config
.objects
.get(&full_name)
.and_then(|obj| {
update_cfgs::get_object_cfg_condition(name, &obj.cfg_condition, &ns.identifier_prefixes)
})
.or_else(|| update_cfgs::get_object_cfg_condition(name, &None, &ns.identifier_prefixes))
let full_name = format!("{}.{}", env.namespaces.main().name, name);
if let Some(obj) = env.config.objects.get(&full_name) {
obj.cfg_condition.clone()
} else {
None
}
}
15 changes: 4 additions & 11 deletions src/codegen/sys/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
env::Env,
library, nameutil,
traits::*,
update_cfgs,
};

// used as glib:get-type in GLib-2.0.gir
Expand Down Expand Up @@ -181,19 +180,13 @@ pub fn generate_other_funcs(

fn generate_cfg_configure(
w: &mut dyn Write,
env: &Env,
function_name: &str,
configured_functions: &[&Function],
commented: bool,
) -> Result<()> {
let ns = env.namespaces.main();
let cfg_condition_ = configured_functions
.iter()
.find_map(|f| {
update_cfgs::get_cfg_condition(function_name, &f.cfg_condition, &ns.symbol_prefixes)
})
.or_else(|| update_cfgs::get_cfg_condition(function_name, &None, &ns.symbol_prefixes));
cfg_condition(w, cfg_condition_.as_ref(), commented, 1)?;
.find_map(|f| f.cfg_condition.as_ref());
cfg_condition(w, cfg_condition_, commented, 1)?;
Ok(())
}

Expand Down Expand Up @@ -231,7 +224,7 @@ fn generate_object_funcs(
.max()
.flatten();
version_condition(w, env, None, version, false, 1)?;
generate_cfg_configure(w, env, glib_get_type, &configured_functions, false)?;
generate_cfg_configure(w, &configured_functions, false)?;
writeln!(w, " pub fn {glib_get_type}() -> GType;")?;
}
}
Expand Down Expand Up @@ -261,7 +254,7 @@ fn generate_object_funcs(

version_condition(w, env, None, version, commented, 1)?;
let name = func.c_identifier.as_ref().unwrap();
generate_cfg_configure(w, env, name, &configured_functions, commented)?;
generate_cfg_configure(w, &configured_functions, commented)?;
writeln!(w, " {comment}pub fn {name}{sig};")?;
}

Expand Down
Loading
Loading