-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #946 from multiversx/meta3
sc-meta improvements
- Loading branch information
Showing
16 changed files
with
412 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
mod pretty_print; | ||
mod relevant_directory; | ||
mod version_req; | ||
|
||
pub use pretty_print::*; | ||
pub use relevant_directory::*; | ||
pub use version_req::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
use super::RelevantDirectory; | ||
use std::{ | ||
collections::BTreeMap, | ||
path::{Component, Path}, | ||
}; | ||
|
||
const PIPE_L: &str = " └─"; | ||
const PIPE_T: &str = " ├─"; | ||
const INDENT_PIPE: &str = " │ "; | ||
const INDENT_SPACE: &str = " "; | ||
|
||
struct PrettyPrintTreeNode { | ||
name: String, | ||
dir: Option<RelevantDirectory>, | ||
children: BTreeMap<String, PrettyPrintTreeNode>, | ||
} | ||
|
||
impl PrettyPrintTreeNode { | ||
fn new(name: String) -> Self { | ||
PrettyPrintTreeNode { | ||
name, | ||
dir: None, | ||
children: BTreeMap::new(), | ||
} | ||
} | ||
|
||
fn add_path(&mut self, path: &Path, dir: &RelevantDirectory) { | ||
let components: Vec<Component> = path | ||
.components() | ||
.filter(|component| component.as_os_str().to_string_lossy() != "/") | ||
.collect(); | ||
self.add_components(&components[..], dir); | ||
} | ||
|
||
fn add_components(&mut self, components: &[Component], dir: &RelevantDirectory) { | ||
if components.is_empty() { | ||
return; | ||
} | ||
|
||
let first = components[0].as_os_str().to_string_lossy().into_owned(); | ||
let child = self | ||
.children | ||
.entry(first.to_string()) | ||
.or_insert_with(|| PrettyPrintTreeNode::new(first)); | ||
|
||
let remaining_components = &components[1..]; | ||
if remaining_components.is_empty() { | ||
child.dir = Some(dir.clone()); | ||
} else { | ||
child.add_components(remaining_components, dir); | ||
} | ||
} | ||
|
||
fn coalesce_single_children(&mut self) { | ||
for child in self.children.values_mut() { | ||
child.coalesce_single_children(); | ||
} | ||
|
||
if self.children.len() == 1 { | ||
let only_child = self.children.first_entry().unwrap().remove(); | ||
self.name = format!("{}/{}", &self.name, &only_child.name); | ||
self.children = only_child.children; | ||
} | ||
} | ||
|
||
fn print<PrintName>(&self, prefix: &str, child_prefix: &str, print_name: &PrintName) | ||
where | ||
PrintName: Fn(&RelevantDirectory), | ||
{ | ||
let num_children = self.children.len(); | ||
print!("{prefix} {}", &self.name); | ||
if let Some(dir) = &self.dir { | ||
print_name(dir); | ||
} | ||
println!(); | ||
|
||
for (i, child) in self.children.values().enumerate() { | ||
let (l_pipe, vertical_pipe) = if i == num_children - 1 { | ||
(PIPE_L, INDENT_SPACE) | ||
} else { | ||
(PIPE_T, INDENT_PIPE) | ||
}; | ||
|
||
let next_prefix = format!("{child_prefix}{l_pipe}"); | ||
let next_child_prefix = format!("{child_prefix}{vertical_pipe}"); // or grandchild prefix | ||
child.print(next_prefix.as_str(), next_child_prefix.as_str(), print_name); | ||
} | ||
} | ||
} | ||
|
||
pub fn dir_pretty_print<'a, I, PrintName>(dir_iter: I, prefix: &str, print_name: &PrintName) | ||
where | ||
I: Iterator<Item = &'a RelevantDirectory>, | ||
PrintName: Fn(&RelevantDirectory), | ||
{ | ||
let mut root = PrettyPrintTreeNode::new("".to_string()); | ||
for dir in dir_iter { | ||
root.add_path(dir.path.as_ref(), dir); | ||
} | ||
root.coalesce_single_children(); | ||
|
||
root.print(prefix, prefix, print_name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use crate::{ | ||
cli_args::InfoArgs, | ||
folder_structure::{dir_pretty_print, RelevantDirectories}, | ||
sc_upgrade::{print_tree_dir_metadata, DEFAULT_LAST_VERSION}, | ||
}; | ||
|
||
pub fn call_info(args: &InfoArgs) { | ||
let path = if let Some(some_path) = &args.path { | ||
some_path.as_str() | ||
} else { | ||
"./" | ||
}; | ||
|
||
let dirs = RelevantDirectories::find_all(path, args.ignore.as_slice()); | ||
dir_pretty_print(dirs.iter(), "", &|dir| { | ||
print_tree_dir_metadata(dir, DEFAULT_LAST_VERSION) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
mod upgrade_0_31; | ||
mod upgrade_0_32; | ||
mod upgrade_0_39; | ||
mod upgrade_common; | ||
mod upgrade_print; | ||
mod upgrade_selector; | ||
mod upgrade_versions; | ||
|
||
pub use upgrade_print::print_tree_dir_metadata; | ||
pub use upgrade_selector::upgrade_sc; | ||
pub use upgrade_versions::DEFAULT_LAST_VERSION; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use super::upgrade_common::{replace_in_files, version_bump_in_cargo_toml}; | ||
use crate::folder_structure::RelevantDirectory; | ||
use ruplacer::Query; | ||
use std::path::Path; | ||
|
||
/// Migrate `0.30` to `0.31.0`, including the version bump. | ||
pub fn upgrade_to_31_0(dir: &RelevantDirectory) { | ||
v_0_31_replace_in_files(dir.path.as_ref()); | ||
|
||
let (from_version, to_version) = dir.upgrade_in_progress.unwrap(); | ||
version_bump_in_cargo_toml(&dir.path, from_version, to_version); | ||
} | ||
|
||
fn v_0_31_replace_in_files(sc_crate_path: &Path) { | ||
replace_in_files( | ||
sc_crate_path, | ||
"*rs", | ||
&[Query::substring("#[var_args]", "")][..], | ||
); | ||
} |
Oops, something went wrong.