Add an option to reinstall sbf-tool binaries by cargo-build-sbf (#29410)
This commit is contained in:
parent
f05eb4a022
commit
33946f5007
|
@ -27,6 +27,7 @@ struct Config<'a> {
|
||||||
sbf_tools_version: &'a str,
|
sbf_tools_version: &'a str,
|
||||||
dump: bool,
|
dump: bool,
|
||||||
features: Vec<String>,
|
features: Vec<String>,
|
||||||
|
force_tools_install: bool,
|
||||||
generate_child_script_on_failure: bool,
|
generate_child_script_on_failure: bool,
|
||||||
no_default_features: bool,
|
no_default_features: bool,
|
||||||
offline: bool,
|
offline: bool,
|
||||||
|
@ -53,6 +54,7 @@ impl Default for Config<'_> {
|
||||||
sbf_tools_version: "(unknown)",
|
sbf_tools_version: "(unknown)",
|
||||||
dump: false,
|
dump: false,
|
||||||
features: vec![],
|
features: vec![],
|
||||||
|
force_tools_install: false,
|
||||||
generate_child_script_on_failure: false,
|
generate_child_script_on_failure: false,
|
||||||
no_default_features: false,
|
no_default_features: false,
|
||||||
offline: false,
|
offline: false,
|
||||||
|
@ -130,6 +132,18 @@ fn install_if_missing(
|
||||||
download_file_name: &str,
|
download_file_name: &str,
|
||||||
target_path: &Path,
|
target_path: &Path,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
|
if config.force_tools_install {
|
||||||
|
if target_path.is_dir() {
|
||||||
|
debug!("Remove directory {:?}", target_path);
|
||||||
|
fs::remove_dir_all(target_path).map_err(|err| err.to_string())?;
|
||||||
|
}
|
||||||
|
let source_base = config.sbf_sdk.join("dependencies");
|
||||||
|
if source_base.exists() {
|
||||||
|
let source_path = source_base.join(package);
|
||||||
|
debug!("Remove file {:?}", source_path);
|
||||||
|
fs::remove_file(source_path).map_err(|err| err.to_string())?;
|
||||||
|
}
|
||||||
|
}
|
||||||
// Check whether the target path is an empty directory. This can
|
// Check whether the target path is an empty directory. This can
|
||||||
// happen if package download failed on previous run of
|
// happen if package download failed on previous run of
|
||||||
// cargo-build-sbf. Remove the target_path directory in this
|
// cargo-build-sbf. Remove the target_path directory in this
|
||||||
|
@ -141,6 +155,7 @@ fn install_if_missing(
|
||||||
.next()
|
.next()
|
||||||
.is_none()
|
.is_none()
|
||||||
{
|
{
|
||||||
|
debug!("Remove directory {:?}", target_path);
|
||||||
fs::remove_dir(target_path).map_err(|err| err.to_string())?;
|
fs::remove_dir(target_path).map_err(|err| err.to_string())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,6 +168,7 @@ fn install_if_missing(
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
if target_path.exists() {
|
if target_path.exists() {
|
||||||
|
debug!("Remove file {:?}", target_path);
|
||||||
fs::remove_file(target_path).map_err(|err| err.to_string())?;
|
fs::remove_file(target_path).map_err(|err| err.to_string())?;
|
||||||
}
|
}
|
||||||
fs::create_dir_all(target_path).map_err(|err| err.to_string())?;
|
fs::create_dir_all(target_path).map_err(|err| err.to_string())?;
|
||||||
|
@ -886,6 +902,12 @@ fn main() {
|
||||||
.multiple_values(true)
|
.multiple_values(true)
|
||||||
.help("Space-separated list of features to activate"),
|
.help("Space-separated list of features to activate"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("force_tools_install")
|
||||||
|
.long("force-tools-install")
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Download and install sbf-tools even when existing tools are located"),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("generate_child_script_on_failure")
|
Arg::new("generate_child_script_on_failure")
|
||||||
.long("generate-child-script-on-failure")
|
.long("generate-child-script-on-failure")
|
||||||
|
@ -970,6 +992,7 @@ fn main() {
|
||||||
sbf_tools_version,
|
sbf_tools_version,
|
||||||
dump: matches.is_present("dump"),
|
dump: matches.is_present("dump"),
|
||||||
features: matches.values_of_t("features").ok().unwrap_or_default(),
|
features: matches.values_of_t("features").ok().unwrap_or_default(),
|
||||||
|
force_tools_install: matches.is_present("force_tools_install"),
|
||||||
generate_child_script_on_failure: matches.is_present("generate_child_script_on_failure"),
|
generate_child_script_on_failure: matches.is_present("generate_child_script_on_failure"),
|
||||||
no_default_features: matches.is_present("no_default_features"),
|
no_default_features: matches.is_present("no_default_features"),
|
||||||
remap_cwd: !matches.is_present("remap_cwd"),
|
remap_cwd: !matches.is_present("remap_cwd"),
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
use {
|
use {
|
||||||
predicates::prelude::*,
|
predicates::prelude::*,
|
||||||
std::{env, fs},
|
std::{
|
||||||
|
env, fs,
|
||||||
|
sync::atomic::{AtomicBool, Ordering},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serial_test;
|
extern crate serial_test;
|
||||||
|
|
||||||
|
static SBF_TOOLS_INSTALL: AtomicBool = AtomicBool::new(true);
|
||||||
fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
|
fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
|
||||||
let cwd = env::current_dir().expect("Unable to get current working directory");
|
let cwd = env::current_dir().expect("Unable to get current working directory");
|
||||||
let toml = cwd
|
let toml = cwd
|
||||||
|
@ -15,6 +19,9 @@ fn run_cargo_build(crate_name: &str, extra_args: &[&str], fail: bool) {
|
||||||
.join("Cargo.toml");
|
.join("Cargo.toml");
|
||||||
let toml = format!("{}", toml.display());
|
let toml = format!("{}", toml.display());
|
||||||
let mut args = vec!["-v", "--sbf-sdk", "../sbf", "--manifest-path", &toml];
|
let mut args = vec!["-v", "--sbf-sdk", "../sbf", "--manifest-path", &toml];
|
||||||
|
if SBF_TOOLS_INSTALL.fetch_and(false, Ordering::SeqCst) {
|
||||||
|
args.push("--force-tools-install");
|
||||||
|
}
|
||||||
for arg in extra_args {
|
for arg in extra_args {
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue