Skip to content

Commit

Permalink
CLI generate-struct-layouts fix (#19954)
Browse files Browse the repository at this point in the history
Depending on the platform, "write" function may fail if the full
directory path does not exist. So we have to create it before.

## Description 

According to this doc https://doc.rust-lang.org/std/fs/fn.write.html
"write" function may fail if the full directory path does not exist. And
it does on macOS with an error "No such file or directory (os error 2)".
I added a create_dir_all call before, to create dir first.

## Test plan 

build --generate-struct-layouts flag must work on all platforms. It did
not work on macOS Sequoia

---

## Release notes

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: Fixed an issue on the `sui move` command regarding writing
into a non existing directory.
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
YaroslavNekryach authored Oct 22, 2024
1 parent f1dd33b commit 7e01df8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions crates/sui-move/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,12 @@ impl Build {
if generate_struct_layouts {
let layout_str = serde_yaml::to_string(&pkg.generate_struct_layouts()).unwrap();
// store under <package_path>/build/<package_name>/layouts/struct_layouts.yaml
let layout_filename = rerooted_path
let dir_name = rerooted_path
.join("build")
.join(pkg.package.compiled_package_info.package_name.as_str())
.join(LAYOUTS_DIR)
.join(STRUCT_LAYOUTS_FILENAME);
.join(LAYOUTS_DIR);
let layout_filename = dir_name.join(STRUCT_LAYOUTS_FILENAME);
fs::create_dir_all(dir_name)?;
fs::write(layout_filename, layout_str)?
}

Expand Down

0 comments on commit 7e01df8

Please sign in to comment.