diff --git a/crates/xtask/Dockerfile b/crates/xtask/Dockerfile index 4206a5505c..b003f36c88 100644 --- a/crates/xtask/Dockerfile +++ b/crates/xtask/Dockerfile @@ -7,5 +7,5 @@ WORKDIR /usr/src/app COPY . . -RUN cargo build --profile ephemeral-build -RUN cargo xtask init \ No newline at end of file +RUN cargo xtask init --update-ide false +RUN cargo xtask build \ No newline at end of file diff --git a/crates/xtask/src/main.rs b/crates/xtask/src/main.rs index f1cff14ab2..2cc1b701d6 100644 --- a/crates/xtask/src/main.rs +++ b/crates/xtask/src/main.rs @@ -259,8 +259,12 @@ impl App { Xtasks::Macros { macro_name } => { cmd.arg("macros").arg(macro_name.as_ref()); } - Xtasks::Init => { - cmd.arg("init"); + Xtasks::Init { dont_update_ide } => { + let arg = cmd.arg("init"); + + if dont_update_ide { + arg.arg("--dont-update-ide"); + } } Xtasks::Build => { cmd.arg("build"); @@ -486,7 +490,11 @@ enum Xtasks { macro_name: Macro, }, /// Performs first time local-development environment setup - Init, + Init { + /// Prevents updating the IDE settings, defaults to false + #[clap(long, default_value = "false")] + dont_update_ide: bool, + }, /// Build the main workspace only Build, /// Build the main workspace, apply all prefferred lints @@ -583,7 +591,7 @@ impl Xtasks { Xtasks::Docs { open, no_rust_docs } => Self::docs(app_settings, open, no_rust_docs), Xtasks::Test { name, package } => Self::test(app_settings, package, name), Xtasks::CiCheck => Self::cicd(app_settings), - Xtasks::Init => Self::init(app_settings), + Xtasks::Init { dont_update_ide } => Self::init(app_settings, dont_update_ide), Xtasks::Macros { macro_name } => match macro_name { Macro::ScriptTests => { let mut settings = app_settings.clone(); @@ -1290,7 +1298,7 @@ impl Xtasks { Ok(()) } - fn init(app_settings: GlobalArgs) -> Result<()> { + fn init(app_settings: GlobalArgs, dont_update_ide: bool) -> Result<()> { // install cargo mdbook Self::run_system_command( &app_settings, @@ -1350,34 +1358,38 @@ impl Xtasks { // create .vscode settings // read from templates at compile time - let vscode_settings = include_str!("../templates/settings.json.tera"); - let mut tera = tera::Tera::default(); - let mut context = tera::Context::new(); - let workspace_dir = Self::workspace_dir(&app_settings)?; - let json_workspace_dir = serde_json::to_string(&workspace_dir)?; // make sure this works as a json string - context.insert("dir", &json_workspace_dir.trim_matches('\"')); - - let templated_settings = tera.render_str(vscode_settings, &context)?; - let templated_settings_json = Self::read_json_with_comments(templated_settings.as_bytes()) - .with_context(|| "reading templated vscode settings")?; - let vscode_dir = Self::relative_workspace_dir(&app_settings, ".vscode")?; - std::fs::create_dir_all(&vscode_dir)?; - let vscode_settings_path = vscode_dir.join("settings.json"); - - // if the file already exists, merge the settings otherwise create it - info!( - "Merging vscode settings at {:?}. With overrides generated by template.", - vscode_settings_path - ); - if vscode_settings_path.exists() { - let existing_settings = std::fs::read_to_string(&vscode_settings_path)?; - let mut existing_settings = Self::read_json_with_comments(existing_settings.as_bytes()) - .with_context(|| "reading existing vscode settings file")?; - Self::merge_json(templated_settings_json, &mut existing_settings); - let merged_settings = serde_json::to_string_pretty(&existing_settings)?; - std::fs::write(&vscode_settings_path, merged_settings)?; - } else { - std::fs::write(&vscode_settings_path, templated_settings)?; + if !dont_update_ide { + let vscode_settings = include_str!("../templates/settings.json.tera"); + let mut tera = tera::Tera::default(); + let mut context = tera::Context::new(); + let workspace_dir = Self::workspace_dir(&app_settings)?; + let json_workspace_dir = serde_json::to_string(&workspace_dir)?; // make sure this works as a json string + context.insert("dir", &json_workspace_dir.trim_matches('\"')); + + let templated_settings = tera.render_str(vscode_settings, &context)?; + let templated_settings_json = + Self::read_json_with_comments(templated_settings.as_bytes()) + .with_context(|| "reading templated vscode settings")?; + let vscode_dir = Self::relative_workspace_dir(&app_settings, ".vscode")?; + std::fs::create_dir_all(&vscode_dir)?; + let vscode_settings_path = vscode_dir.join("settings.json"); + + // if the file already exists, merge the settings otherwise create it + info!( + "Merging vscode settings at {:?}. With overrides generated by template.", + vscode_settings_path + ); + if vscode_settings_path.exists() { + let existing_settings = std::fs::read_to_string(&vscode_settings_path)?; + let mut existing_settings = + Self::read_json_with_comments(existing_settings.as_bytes()) + .with_context(|| "reading existing vscode settings file")?; + Self::merge_json(templated_settings_json, &mut existing_settings); + let merged_settings = serde_json::to_string_pretty(&existing_settings)?; + std::fs::write(&vscode_settings_path, merged_settings)?; + } else { + std::fs::write(&vscode_settings_path, templated_settings)?; + } } Ok(())