From 56977aeff263d1fa2786c34f36006c4e4683ecf0 Mon Sep 17 00:00:00 2001 From: lerencao Date: Wed, 19 Jan 2022 14:43:59 +0800 Subject: [PATCH] move-cli: fix stdlib build (#3162) --- Cargo.lock | 1 + vm/stdlib/Cargo.toml | 2 +- vm/stdlib/src/lib.rs | 32 +++++++++++++++++++++----------- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cf61c30b4e..3c4ab3a69b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10288,6 +10288,7 @@ dependencies = [ "starcoin-move-compiler", "starcoin-natives", "starcoin-vm-types", + "tempdir", "walkdir", ] diff --git a/vm/stdlib/Cargo.toml b/vm/stdlib/Cargo.toml index 0ebcd78e36..f6a62eb64f 100644 --- a/vm/stdlib/Cargo.toml +++ b/vm/stdlib/Cargo.toml @@ -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" } diff --git a/vm/stdlib/src/lib.rs b/vm/stdlib/src/lib.rs index 34c0a3dcb8..d963c8cd48 100644 --- a/vm/stdlib/src/lib.rs +++ b/vm/stdlib/src/lib.rs @@ -16,6 +16,7 @@ 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}, @@ -23,6 +24,7 @@ use std::{ io::{Read, Write}, path::{Path, PathBuf}, }; + mod compat; pub use compat::*; pub use starcoin_move_compiler::utils::iterate_directory; @@ -160,16 +162,18 @@ pub fn restore_stdlib_in_dir(dir: &Path) -> anyhow::Result> { Ok(deps) } -pub(crate) fn stdlib_files() -> Vec { - 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::>() -} +// fn stdlib_files() -> Vec { +// 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::>() +// } pub fn build_stdlib() -> BTreeMap { - 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(); @@ -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()], @@ -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)]