Skip to content

Commit

Permalink
move-cli: fix stdlib build (#3162)
Browse files Browse the repository at this point in the history
  • Loading branch information
nanne007 committed Jan 19, 2022
1 parent 1edc6e5 commit 56977ae
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vm/stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clap = "2.33.3"
serde = { version = "1.0.130", default-features = false }
rayon = "1.5.1"
itertools = "0.10.3"

tempdir = { version = "0.3" }

[dev-dependencies]
move-unit-test = { git = "https://github.com/starcoinorg/diem", rev="6b1533f22b3075cc15ff68db21b5b84e6baa2955" }
Expand Down
32 changes: 21 additions & 11 deletions vm/stdlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ use starcoin_vm_types::bytecode_verifier::{dependencies, verify_module};
use starcoin_vm_types::file_format::CompiledModule;
pub use starcoin_vm_types::genesis_config::StdlibVersion;
use starcoin_vm_types::transaction::{Module, Package, ScriptFunction};
use std::env::temp_dir;
use std::str::FromStr;
use std::{
collections::{BTreeMap, HashMap},
fs::{self, File},
io::{Read, Write},
path::{Path, PathBuf},
};

mod compat;
pub use compat::*;
pub use starcoin_move_compiler::utils::iterate_directory;
Expand Down Expand Up @@ -160,16 +162,18 @@ pub fn restore_stdlib_in_dir(dir: &Path) -> anyhow::Result<Vec<String>> {
Ok(deps)
}

pub(crate) fn stdlib_files() -> Vec<String> {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push(STD_LIB_DIR);

let dirfiles = starcoin_move_compiler::utils::iterate_directory(&path);
starcoin_move_compiler::utils::filter_move_files(dirfiles).collect::<Vec<_>>()
}
// fn stdlib_files() -> Vec<String> {
// let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
// path.push(STD_LIB_DIR);
//
// let dirfiles = starcoin_move_compiler::utils::iterate_directory(&path);
// starcoin_move_compiler::utils::filter_move_files(dirfiles).collect::<Vec<_>>()
// }

pub fn build_stdlib() -> BTreeMap<String, CompiledModule> {
let (_, compiled_units) = Compiler::new(&stdlib_files(), &[])
let temp_path = tempdir::TempDir::new("stdlib").unwrap();
let stdlib_files = restore_stdlib_in_dir(temp_path.path()).unwrap();
let (_, compiled_units) = Compiler::new(&stdlib_files, &[])
.build_and_report()
.unwrap();
let mut modules = BTreeMap::new();
Expand Down Expand Up @@ -203,11 +207,15 @@ pub fn save_binary(path: &Path, binary: &[u8]) {
}

pub fn build_stdlib_doc() {
build_doc(STD_LIB_DOC_DIR, "", stdlib_files().as_slice(), "")
let temp_path = tempdir::TempDir::new("stdlib").unwrap();
let stdlib_files = restore_stdlib_in_dir(temp_path.path()).unwrap();
build_doc(STD_LIB_DOC_DIR, "", &stdlib_files, "")
}

pub fn build_script_abis() {
stdlib_files().par_iter().for_each(|file| {
let temp_path = tempdir::TempDir::new("stdlib").unwrap();
let stdlib_files = restore_stdlib_in_dir(temp_path.path()).unwrap();
stdlib_files.par_iter().for_each(|file| {
build_abi(
COMPILED_SCRIPTS_ABI_DIR,
&[file.clone()],
Expand Down Expand Up @@ -258,7 +266,9 @@ pub fn build_stdlib_error_code_map() {
fs::create_dir_all(&path).unwrap();
path.push(ERROR_DESC_FILENAME);
path.set_extension(ERROR_DESC_EXTENSION);
build_error_code_map(path.to_str().unwrap(), stdlib_files().as_slice(), "")
let temp_path = tempdir::TempDir::new("stdlib").unwrap();
let stdlib_files = restore_stdlib_in_dir(temp_path.path()).unwrap();
build_error_code_map(path.to_str().unwrap(), &stdlib_files, "")
}

#[allow(clippy::field_reassign_with_default)]
Expand Down

0 comments on commit 56977ae

Please sign in to comment.