Skip to content

Commit fc3194e

Browse files
committed
Allow running framework tests on macOS 14
1 parent a63e4ef commit fc3194e

File tree

6 files changed

+66
-19
lines changed

6 files changed

+66
-19
lines changed

crates/header-translator/src/availability.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ impl Availability {
339339
if let Some(macos) = self.introduced.macos {
340340
// Disable test if introduced later than my current OS.
341341
// TODO: Use `available!` macro here.
342-
if 14 < macos.x {
342+
if HOST_MACOS < macos.x {
343343
return false;
344344
}
345345
}
@@ -374,3 +374,10 @@ impl fmt::Display for Availability {
374374
Ok(())
375375
}
376376
}
377+
378+
pub const HOST_MACOS: u32 = if option_env!("CI").is_some() {
379+
9999
380+
} else {
381+
// @madsmtm's development machine's current OS version.
382+
14
383+
};

crates/header-translator/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod stmt;
3232
mod thread_safety;
3333
mod unexposed_attr;
3434

35+
pub use self::availability::HOST_MACOS;
3536
pub use self::cfgs::PlatformCfg;
3637
pub use self::config::{load_config, load_skipped, Config, LibraryConfig};
3738
pub use self::context::{Context, MacroEntity, MacroLocation};

crates/header-translator/src/library.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ impl Library {
193193
let generated_dir = crate_dir.join("src").join("generated");
194194
let test_path = test_crate_dir.join("tests").join(&self.data.framework);
195195
let emission_location = Location::from_library(&self.link_name);
196+
let emit_tests = self
197+
.data
198+
.macos
199+
.as_ref()
200+
.map(|macos| macos.major <= (crate::HOST_MACOS as u64))
201+
.unwrap_or(true);
196202

197203
// Output `src/generated/*`.
198204
self.module.output(
@@ -201,6 +207,7 @@ impl Library {
201207
config,
202208
&emission_location,
203209
self.top_level_prefix(),
210+
emit_tests,
204211
)?;
205212

206213
if !self.data.custom_lib_rs {

crates/header-translator/src/main.rs

Lines changed: 7 additions & 1 deletion
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, VERSION,
20+
LibraryConfig, Location, MacroEntity, MacroLocation, PlatformCfg, Stmt, HOST_MACOS, VERSION,
2121
};
2222

2323
type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
@@ -812,6 +812,12 @@ fn update_test_metadata(workspace_dir: &Path, config: &Config) {
812812
// Write imports
813813
let mut s = String::new();
814814
for (_, lib) in config.to_parse() {
815+
if let Some(macos) = &lib.macos {
816+
if (HOST_MACOS as u64) < macos.major {
817+
// Skip library if not available on current host.
818+
continue;
819+
}
820+
}
815821
let platform_cfg = PlatformCfg::from_config_explicit(lib);
816822
if let Some(cfgs) = platform_cfg.cfgs() {
817823
writeln!(&mut s, "#[cfg({cfgs})]",).unwrap();

crates/header-translator/src/module.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ impl Module {
249249
config: &Config,
250250
emission_location: &Location,
251251
top_level_prefix: impl fmt::Display,
252+
emit_tests: bool,
252253
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
253254
if self.submodules.is_empty() && !emission_location.is_top_level() {
254255
// Only output a single file
@@ -257,14 +258,18 @@ impl Module {
257258
self.contents(config, emission_location, top_level_prefix)
258259
.to_string(),
259260
)?;
260-
fs::write(
261-
test_path.with_extension("rs"),
262-
self.tests(config).to_string(),
263-
)?;
261+
if emit_tests {
262+
fs::write(
263+
test_path.with_extension("rs"),
264+
self.tests(config).to_string(),
265+
)?;
266+
}
264267
} else {
265268
// Output an entire module
266269
fs::create_dir_all(path)?;
267-
fs::create_dir_all(test_path)?;
270+
if emit_tests {
271+
fs::create_dir_all(test_path)?;
272+
}
268273

269274
// TODO: Fix this
270275
let mut expected_files: Vec<OsString> = vec![];
@@ -278,6 +283,7 @@ impl Module {
278283
config,
279284
&emission_location.add_module(&name),
280285
"//! This file has been automatically generated by `objc2`'s `header-translator`.\n//! DO NOT EDIT\n",
286+
emit_tests,
281287
)?;
282288
if module.submodules.is_empty() {
283289
expected_files.push(format!("{name}.rs").into());
@@ -291,24 +297,28 @@ impl Module {
291297
self.contents(config, emission_location, top_level_prefix)
292298
.to_string(),
293299
)?;
294-
fs::write(test_path.join("mod.rs"), self.tests(config).to_string())?;
300+
if emit_tests {
301+
fs::write(test_path.join("mod.rs"), self.tests(config).to_string())?;
302+
}
295303
expected_files.push("mod.rs".into());
296304

297305
// Remove previously generated files
298-
for file in path.read_dir()?.chain(test_path.read_dir()?) {
299-
let file = file?;
300-
if expected_files.contains(&file.file_name()) {
301-
continue;
302-
}
303-
error!("removing previous file {:?}", file.path());
304-
if file.path().is_dir() {
305-
fs::remove_dir_all(file.path())?;
306-
} else {
307-
fs::remove_file(file.path())?;
306+
if let Ok(test_dir) = test_path.read_dir() {
307+
for file in path.read_dir()?.chain(test_dir) {
308+
let file = file?;
309+
if expected_files.contains(&file.file_name()) {
310+
continue;
311+
}
312+
error!("removing previous file {:?}", file.path());
313+
if file.path().is_dir() {
314+
fs::remove_dir_all(file.path())?;
315+
} else {
316+
fs::remove_file(file.path())?;
317+
}
308318
}
309319
}
310320

311-
if emission_location.is_top_level() {
321+
if emission_location.is_top_level() && emit_tests {
312322
let data = config.library(emission_location);
313323
let mut s = String::new();
314324
writeln!(&mut s, "#![cfg(feature = \"test-frameworks\")]")?;

crates/header-translator/src/stmt.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,6 +3219,11 @@ impl Stmt {
32193219
_ => return None,
32203220
};
32213221

3222+
// Availability is broken in MDLUtility.h for some reason?
3223+
if cls.name == "MDLUtility" {
3224+
return None;
3225+
}
3226+
32223227
Some(FormatterFn(move |f| {
32233228
write!(
32243229
f,
@@ -3278,6 +3283,17 @@ impl Stmt {
32783283
if ["Dispatch"].contains(&id.library_name()) {
32793284
return None;
32803285
}
3286+
// Some statics are missing / have wrong availability attributes.
3287+
if [
3288+
"CBUUIDCharacteristicObservationScheduleString",
3289+
"kMDItemXMPCredit",
3290+
"kMDItemXMPDigitalSourceType",
3291+
"HKDataTypeIdentifierStateOfMind",
3292+
]
3293+
.contains(&&*id.name)
3294+
{
3295+
return None;
3296+
}
32813297
if !availability.is_available_host() {
32823298
return None;
32833299
}

0 commit comments

Comments
 (0)