Skip to content

Commit 85f1318

Browse files
committed
Refactor dependency and imports calculation
1 parent 7a1e21d commit 85f1318

File tree

91 files changed

+716
-648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+716
-648
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/header-translator/src/config.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use heck::ToTrainCase;
88
use semver::Version;
99
use serde::{de, Deserialize, Deserializer};
1010

11-
use crate::id::{Location, LocationLibrary};
11+
use crate::id::Location;
1212
use crate::stmt::{Derives, Mutability};
1313
use crate::ItemIdentifier;
1414

@@ -21,16 +21,14 @@ pub struct Config {
2121
impl Config {
2222
pub fn library(&self, location: impl AsRef<Location>) -> &LibraryConfig {
2323
let location = location.as_ref();
24-
match location.library() {
25-
LocationLibrary::System => &self.system,
26-
LocationLibrary::Library(library) => self.libraries.get(library).unwrap_or_else(|| {
24+
let library_name = location.library_name();
25+
if library_name == "System" || library_name == "objc2" {
26+
&self.system
27+
} else {
28+
self.libraries.get(library_name).unwrap_or_else(|| {
2729
error!("tried to get library config from {location:?}");
2830
&self.system
29-
}),
30-
_ => {
31-
error!("tried to get library config from {location:?}");
32-
&self.system
33-
}
31+
})
3432
}
3533
}
3634

@@ -310,8 +308,8 @@ impl<'de> Deserialize<'de> for Mutability {
310308
let (library, rest) = value.split_once("::")?;
311309
let (file_name, name) = rest.split_once("::")?;
312310
Some(ItemIdentifier::from_raw(
313-
name.to_string(),
314-
vec![library.to_string(), file_name.to_string()],
311+
name.into(),
312+
vec![library.to_string().into(), file_name.to_string().into()],
315313
))
316314
}
317315

crates/header-translator/src/context.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::borrow::Cow;
12
use std::collections::HashMap;
23
use std::ops;
34
use std::path::{Path, PathBuf};
@@ -30,7 +31,7 @@ impl<'a> Context<'a> {
3031
if let Some(file) = location.get_file_location().file {
3132
let path = file.get_path();
3233
if let Ok(path) = path.strip_prefix(&self.framework_dir) {
33-
let mut components: Vec<_> = path
34+
let mut components: Vec<Cow<'_, str>> = path
3435
.components()
3536
.filter(|component| {
3637
component.as_os_str() != "Headers"
@@ -39,14 +40,14 @@ impl<'a> Context<'a> {
3940
.map(|component| component.as_os_str().to_str().expect("component to_str"))
4041
.map(|component| component.strip_suffix(".framework").unwrap_or(component))
4142
.map(|component| component.strip_suffix(".h").unwrap_or(component))
42-
.map(|s| s.to_string())
43+
.map(|s| s.to_string().into())
4344
.collect();
4445

4546
// Put items in umbrella header in `mod.rs`
4647
if let [.., innermost_framework_name, file_name] = &*components {
4748
let umbrella_header = self
4849
.libraries
49-
.get(innermost_framework_name)
50+
.get(&**innermost_framework_name)
5051
.and_then(|lib| lib.umbrella_header.as_deref())
5152
.unwrap_or(innermost_framework_name);
5253

@@ -57,11 +58,14 @@ impl<'a> Context<'a> {
5758

5859
return Some(Location::from_components(components));
5960
} else if let Ok(path) = path.strip_prefix(&self.include_dir) {
60-
if path.starts_with("objc") || path == Path::new("MacTypes.h") {
61-
return Some(Location::from_components(vec!["System".to_string()]));
61+
if path.starts_with("objc") {
62+
return Some(Location::from_components(vec!["objc2".into()]));
63+
}
64+
if path == Path::new("MacTypes.h") {
65+
return Some(Location::from_components(vec!["System".into()]));
6266
}
6367
if path.starts_with("sys") {
64-
return Some(Location::from_components(vec!["libc".to_string()]));
68+
return Some(Location::from_components(vec!["libc".into()]));
6569
}
6670
}
6771
}

crates/header-translator/src/default_cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ license = "MIT"
2121
workspace = true
2222

2323
[dependencies]
24-
objc2 = { path = "../../crates/objc2", version = "0.5.1", default-features = false }
2524

2625
[package.metadata.docs.rs]
2726
default-target = "UNSET"
@@ -33,5 +32,5 @@ targets = [
3332
default = ["std"]
3433

3534
# Currently not possible to turn off, put here for forwards compatibility.
36-
std = ["alloc", "objc2/std"]
37-
alloc = ["objc2/alloc"]
35+
std = ["alloc"]
36+
alloc = []

crates/header-translator/src/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ impl Expr {
203203
Self::Signed(_) => {}
204204
Self::Unsigned(_) => {}
205205
Self::Float(_) => {}
206-
Self::MacroInvocation { evaluated, .. } => {
206+
Self::MacroInvocation { evaluated, id } => {
207207
if evaluated.is_none() {
208-
// features.add_item(&id);
208+
items.push(id.clone());
209209
}
210210
}
211211
Self::Enum { id, .. } => {
@@ -214,7 +214,7 @@ impl Expr {
214214
Self::Const(id) => {
215215
items.push(id.clone());
216216
}
217-
Self::Var { id, ty, .. } => {
217+
Self::Var { id, ty } => {
218218
items.push(id.clone());
219219
items.extend(ty.required_items());
220220
}

0 commit comments

Comments
 (0)