Skip to content

Commit 78b56c0

Browse files
committed
fixup! cargo build - mpy-files symlink
1 parent d6c6739 commit 78b56c0

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

core/embed/upymod/build.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ fn main() -> Result<()> {
295295
// Build frozen_mpy.c if frozen modules are enabled
296296
let mpy_frozen_c = mpy_builder.build_frozen_modules(&qstr_preprocessed)?;
297297
lib.add_source(mpy_frozen_c);
298+
299+
// Add symlink to __oot/src folder
300+
create_mpy_files_symlink()?;
298301
}
299302

300303
if cfg!(not(feature = "emulator")) {
@@ -363,6 +366,33 @@ fn define_scm_revision(lib: &mut CLibrary) -> Result<u8> {
363366
Ok(xor2)
364367
}
365368

369+
/// Creates a symlink to the __oot/src folder used
370+
/// when generating test coverage reports that need to process *.i files
371+
fn create_mpy_files_symlink() -> Result<()> {
372+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
373+
let symlink_path = out_dir.join("../../../mpy-files");
374+
let target_path = out_dir.join("__oot/src");
375+
376+
if symlink_path.exists() {
377+
std::fs::remove_file(&symlink_path).with_context(|| {
378+
format!(
379+
"Failed to remove existing symlink at {}",
380+
symlink_path.display()
381+
)
382+
})?;
383+
}
384+
385+
std::os::unix::fs::symlink(&target_path, &symlink_path).with_context(|| {
386+
format!(
387+
"Failed to create symlink from {} to {}",
388+
symlink_path.display(),
389+
target_path.display()
390+
)
391+
})?;
392+
393+
Ok(())
394+
}
395+
366396
struct MpyBuilder<'a> {
367397
lib: &'a CLibrary,
368398
crate_dir: PathBuf,

core/embed/xtask/src/artifacts.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ fn copy_if_newer(src: &Path, dst: &Path) -> Result<bool> {
1212
return Ok(false);
1313
}
1414

15+
if src.symlink_metadata()?.file_type().is_symlink() {
16+
let target = fs::read_link(src)?;
17+
if dst.exists() {
18+
fs::remove_file(dst)?;
19+
}
20+
std::os::unix::fs::symlink(target, dst)?;
21+
return Ok(true);
22+
}
23+
1524
if dst.exists() {
1625
let src_modified = src
1726
.metadata()
@@ -68,6 +77,9 @@ pub fn collect_artifacts(args: &BuildArgs, is_dependency: bool) -> Result<()> {
6877
profile.join(format!("{binary_name}.map")),
6978
format!("{name}.map"),
7079
));
80+
} else {
81+
let mpy_files = "mpy-files";
82+
artifacts.push((profile.join(mpy_files), mpy_files.to_string()));
7183
}
7284

7385
for (src, dst_name) in &artifacts {

0 commit comments

Comments
 (0)