Skip to content

Commit f0b5884

Browse files
committed
Use Cargo workspace dependencies for framework crates
1 parent fc7cb2d commit f0b5884

File tree

179 files changed

+988
-779
lines changed

Some content is hidden

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

179 files changed

+988
-779
lines changed

Cargo.toml

+194-10
Large diffs are not rendered by default.

crates/header-translator/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@ pub(crate) fn to_snake_case(input: impl AsRef<str>) -> String {
104104
}
105105
}
106106

107+
/// The version of the framework crates.
107108
pub const VERSION: &str = "0.3.0";

crates/header-translator/src/library.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -365,22 +365,7 @@ see that for related crates.", self.data.krate)?;
365365
for (krate, required_features) in self.dependencies(config) {
366366
let library = config.library_from_crate(krate);
367367
let required = self.data.required_crates.contains(krate);
368-
let mut table = match (library.is_library, self.data.is_library) {
369-
(true, _) => InlineTable::from_iter([("workspace", Value::from(true))]),
370-
(false, true) => InlineTable::from_iter([
371-
(
372-
"path",
373-
Value::from(format!("../../framework-crates/{krate}")),
374-
),
375-
("version", Value::from(VERSION)),
376-
("default-features", Value::from(false)),
377-
]),
378-
(false, false) => InlineTable::from_iter([
379-
("path", Value::from(format!("../{krate}"))),
380-
("version", Value::from(VERSION)),
381-
("default-features", Value::from(false)),
382-
]),
383-
};
368+
let mut table = InlineTable::from_iter([("workspace", Value::from(true))]);
384369
if !required {
385370
table.insert("optional", Value::from(true));
386371
}

crates/header-translator/src/main.rs

+54-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tracing_tree::HierarchicalLayer;
1717

1818
use header_translator::{
1919
global_analysis, load_config, load_skipped, run_cargo_fmt, Config, Context, EntryExt, Library,
20-
LibraryConfig, Location, MacroEntity, MacroLocation, PlatformCfg, Stmt,
20+
LibraryConfig, Location, MacroEntity, MacroLocation, PlatformCfg, Stmt, VERSION,
2121
};
2222

2323
type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -114,6 +114,8 @@ fn main() -> Result<(), BoxError> {
114114
let tempdir = workspace_dir.join("target").join("header-translator");
115115
fs::create_dir_all(&tempdir)?;
116116

117+
update_root_cargo_toml(workspace_dir, &config);
118+
117119
let mut found = false;
118120
for (name, data) in config.to_parse() {
119121
if let Some(framework) = &framework {
@@ -140,6 +142,55 @@ fn main() -> Result<(), BoxError> {
140142
Ok(())
141143
}
142144

145+
fn update_root_cargo_toml(workspace_dir: &Path, config: &Config) {
146+
let _span = info_span!("updating root Cargo.toml").entered();
147+
148+
// Make library be imported by test crate
149+
let mut f = std::fs::OpenOptions::new()
150+
.read(true)
151+
.write(true)
152+
.open(workspace_dir.join("Cargo.toml"))
153+
.unwrap();
154+
let mut cargo_toml: toml_edit::DocumentMut = io::read_to_string(&f)
155+
.unwrap()
156+
.parse()
157+
.expect("invalid test toml");
158+
159+
let dependencies = cargo_toml["workspace"]["dependencies"]
160+
.as_table_mut()
161+
.unwrap();
162+
163+
// Delete all framework crate entries.
164+
dependencies.retain(|key, _| !key.starts_with("objc2-"));
165+
166+
// And add them again.
167+
for (i, (_, lib)) in config.to_parse().enumerate() {
168+
if lib.is_library {
169+
continue;
170+
}
171+
let table = toml_edit::InlineTable::from_iter([
172+
(
173+
"path",
174+
toml_edit::Value::from(format!("framework-crates/{}", lib.krate)),
175+
),
176+
("version", toml_edit::Value::from(VERSION)),
177+
("default-features", toml_edit::Value::from(false)),
178+
]);
179+
dependencies[&lib.krate] = table.into();
180+
if i == 0 {
181+
dependencies
182+
.key_mut(&lib.krate)
183+
.unwrap()
184+
.leaf_decor_mut()
185+
.set_prefix("\n##\n## AUTO-GENERATED BELOW\n##\n\n")
186+
}
187+
}
188+
189+
f.set_len(0).unwrap();
190+
f.seek(io::SeekFrom::Start(0)).unwrap();
191+
f.write_all(cargo_toml.to_string().as_bytes()).unwrap();
192+
}
193+
143194
fn parse_library(
144195
index: &Index<'_>,
145196
config: &Config,
@@ -850,21 +901,9 @@ fn update_test_metadata(workspace_dir: &Path, config: &Config) {
850901
cargo_toml["dependencies"].as_table_mut().unwrap()
851902
};
852903

853-
let path = if lib.is_library {
854-
format!("../{}", lib.krate)
855-
} else {
856-
format!("../../framework-crates/{}", lib.krate)
857-
};
858-
859904
dependencies[&lib.krate] = toml_edit::InlineTable::from_iter([
860-
(
861-
"path",
862-
toml_edit::Value::String(toml_edit::Formatted::new(path)),
863-
),
864-
(
865-
"optional",
866-
toml_edit::Value::Boolean(toml_edit::Formatted::new(true)),
867-
),
905+
("workspace", toml_edit::Value::from(true)),
906+
("optional", toml_edit::Value::from(true)),
868907
])
869908
.into();
870909
}

0 commit comments

Comments
 (0)