Skip to content

Commit 808fdae

Browse files
chore: handling the case when --generate-only is passed to
`intrinsic-test`
1 parent d09ae82 commit 808fdae

File tree

1 file changed

+31
-22
lines changed
  • crates/intrinsic-test/src/arm

1 file changed

+31
-22
lines changed

crates/intrinsic-test/src/arm/mod.rs

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod intrinsic;
44
mod json_parser;
55
mod types;
66

7-
use std::fs::File;
7+
use std::fs;
88

99
use rayon::prelude::*;
1010

@@ -69,28 +69,31 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
6969

7070
let (chunk_size, chunk_count) = chunk_info(self.intrinsics.len());
7171

72-
let cpp_compiler = compile::build_cpp_compilation(&self.cli_options).unwrap();
72+
let cpp_compiler_wrapped = compile::build_cpp_compilation(&self.cli_options);
7373

7474
let notice = &build_notices("// ");
75+
fs::create_dir_all("c_programs").unwrap();
7576
self.intrinsics
7677
.par_chunks(chunk_size)
7778
.enumerate()
7879
.map(|(i, chunk)| {
7980
let c_filename = format!("c_programs/mod_{i}.cpp");
80-
let mut file = File::create(&c_filename).unwrap();
81+
let mut file = fs::File::create(&c_filename).unwrap();
8182
write_mod_cpp(&mut file, notice, c_target, platform_headers, chunk).unwrap();
8283

8384
// compile this cpp file into a .o file
84-
let output = cpp_compiler
85-
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
86-
assert!(output.status.success(), "{output:?}");
85+
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
86+
let output = cpp_compiler
87+
.compile_object_file(&format!("mod_{i}.cpp"), &format!("mod_{i}.o"))?;
88+
assert!(output.status.success(), "{output:?}");
89+
}
8790

8891
Ok(())
8992
})
9093
.collect::<Result<(), std::io::Error>>()
9194
.unwrap();
9295

93-
let mut file = File::create("c_programs/main.cpp").unwrap();
96+
let mut file = fs::File::create("c_programs/main.cpp").unwrap();
9497
write_main_cpp(
9598
&mut file,
9699
c_target,
@@ -100,20 +103,22 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
100103
.unwrap();
101104

102105
// compile this cpp file into a .o file
103-
info!("compiling main.cpp");
104-
let output = cpp_compiler
105-
.compile_object_file("main.cpp", "intrinsic-test-programs.o")
106-
.unwrap();
107-
assert!(output.status.success(), "{output:?}");
108-
109-
let object_files = (0..chunk_count)
110-
.map(|i| format!("mod_{i}.o"))
111-
.chain(["intrinsic-test-programs.o".to_owned()]);
112-
113-
let output = cpp_compiler
114-
.link_executable(object_files, "intrinsic-test-programs")
115-
.unwrap();
116-
assert!(output.status.success(), "{output:?}");
106+
if let Some(cpp_compiler) = cpp_compiler_wrapped.as_ref() {
107+
info!("compiling main.cpp");
108+
let output = cpp_compiler
109+
.compile_object_file("main.cpp", "intrinsic-test-programs.o")
110+
.unwrap();
111+
assert!(output.status.success(), "{output:?}");
112+
113+
let object_files = (0..chunk_count)
114+
.map(|i| format!("mod_{i}.o"))
115+
.chain(["intrinsic-test-programs.o".to_owned()]);
116+
117+
let output = cpp_compiler
118+
.link_executable(object_files, "intrinsic-test-programs")
119+
.unwrap();
120+
assert!(output.status.success(), "{output:?}");
121+
}
117122

118123
true
119124
}
@@ -172,7 +177,11 @@ impl SupportedArchitectureTest for ArmArchitectureTest {
172177
.collect::<Result<(), std::io::Error>>()
173178
.unwrap();
174179

175-
compile_rust_programs(toolchain, target, linker)
180+
if self.cli_options.toolchain.is_some() {
181+
compile_rust_programs(toolchain, target, linker)
182+
} else {
183+
true
184+
}
176185
}
177186

178187
fn compare_outputs(&self) -> bool {

0 commit comments

Comments
 (0)