about summary refs log tree commit diff
path: root/src/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap')
-rw-r--r--src/bootstrap/Cargo.lock4
-rw-r--r--src/bootstrap/Cargo.toml2
-rw-r--r--src/bootstrap/run.rs32
-rw-r--r--src/bootstrap/test.rs3
4 files changed, 23 insertions, 18 deletions
diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock
index f5220e361b3..96a0eb75582 100644
--- a/src/bootstrap/Cargo.lock
+++ b/src/bootstrap/Cargo.lock
@@ -126,9 +126,9 @@ dependencies = [
 
 [[package]]
 name = "clap_complete"
-version = "4.2.2"
+version = "4.4.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "36774babb166352bb4f7b9cb16f781ffa3439d2a8f12cd31bea85a38c888fea3"
+checksum = "e3ae8ba90b9d8b007efe66e55e48fb936272f5ca00349b5b0e89877520d35ea7"
 dependencies = [
  "clap",
 ]
diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml
index 7e72e877104..006a992eb3c 100644
--- a/src/bootstrap/Cargo.toml
+++ b/src/bootstrap/Cargo.toml
@@ -36,7 +36,7 @@ test = false
 build_helper = { path = "../tools/build_helper" }
 cc = "1.0.69"
 clap = { version = "4.2.4", default-features = false, features = ["std", "usage", "help", "derive", "error-context"] }
-clap_complete = "4.2.2"
+clap_complete = "4.4.3"
 cmake = "0.1.38"
 filetime = "0.2"
 hex = "0.4"
diff --git a/src/bootstrap/run.rs b/src/bootstrap/run.rs
index 4082f5bb9b1..f253f5225a1 100644
--- a/src/bootstrap/run.rs
+++ b/src/bootstrap/run.rs
@@ -1,8 +1,6 @@
 use std::path::PathBuf;
 use std::process::Command;
 
-use clap_complete::shells;
-
 use crate::builder::{Builder, RunConfig, ShouldRun, Step};
 use crate::config::TargetSelection;
 use crate::dist::distdir;
@@ -268,23 +266,29 @@ impl Step for GenerateWindowsSys {
 #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
 pub struct GenerateCompletions;
 
+macro_rules! generate_completions {
+    ( $( ( $shell:ident, $filename:expr ) ),* ) => {
+        $(
+            if let Some(comp) = get_completion($shell, &$filename) {
+                std::fs::write(&$filename, comp).expect(&format!("writing {} completion", stringify!($shell)));
+            }
+        )*
+    };
+}
+
 impl Step for GenerateCompletions {
     type Output = ();
 
     /// Uses `clap_complete` to generate shell completions.
     fn run(self, builder: &Builder<'_>) {
-        // FIXME(clubby789): enable zsh when clap#4898 is fixed
-        let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
-            .map(|filename| builder.src.join("src/etc/completions").join(filename));
-        if let Some(comp) = get_completion(shells::Bash, &bash) {
-            std::fs::write(&bash, comp).expect("writing bash completion");
-        }
-        if let Some(comp) = get_completion(shells::Fish, &fish) {
-            std::fs::write(&fish, comp).expect("writing fish completion");
-        }
-        if let Some(comp) = get_completion(shells::PowerShell, &powershell) {
-            std::fs::write(&powershell, comp).expect("writing powershell completion");
-        }
+        use clap_complete::shells::{Bash, Fish, PowerShell, Zsh};
+
+        generate_completions!(
+            (Bash, builder.src.join("src/etc/completions/x.py.sh")),
+            (Zsh, builder.src.join("src/etc/completions/x.py.zsh")),
+            (Fish, builder.src.join("src/etc/completions/x.py.fish")),
+            (PowerShell, builder.src.join("src/etc/completions/x.py.ps1"))
+        );
     }
 
     fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index 0447d5652d9..fb8ec0355c2 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -1135,13 +1135,14 @@ help: to skip test's attempt to check tidiness, pass `--skip src/tools/tidy` to
         builder.ensure(ExpandYamlAnchors);
 
         builder.info("x.py completions check");
-        let [bash, fish, powershell] = ["x.py.sh", "x.py.fish", "x.py.ps1"]
+        let [bash, zsh, fish, powershell] = ["x.py.sh", "x.py.zsh", "x.py.fish", "x.py.ps1"]
             .map(|filename| builder.src.join("src/etc/completions").join(filename));
         if builder.config.cmd.bless() {
             builder.ensure(crate::run::GenerateCompletions);
         } else if crate::flags::get_completion(shells::Bash, &bash).is_some()
             || crate::flags::get_completion(shells::Fish, &fish).is_some()
             || crate::flags::get_completion(shells::PowerShell, &powershell).is_some()
+            || crate::flags::get_completion(shells::Zsh, &zsh).is_some()
         {
             eprintln!(
                 "x.py completions were changed; run `x.py run generate-completions` to update them"