summaryrefslogtreecommitdiff
path: root/src/bootstrap/run.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/run.rs')
-rw-r--r--src/bootstrap/run.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/bootstrap/run.rs b/src/bootstrap/run.rs
index cb15d9a6325..ec01f744b82 100644
--- a/src/bootstrap/run.rs
+++ b/src/bootstrap/run.rs
@@ -1,9 +1,12 @@
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;
+use crate::flags::get_completion;
use crate::test;
use crate::tool::{self, SourceType, Tool};
use crate::util::output;
@@ -253,3 +256,56 @@ impl Step for GenerateCopyright {
dest
}
}
+
+#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
+pub struct GenerateWindowsSys;
+
+impl Step for GenerateWindowsSys {
+ type Output = ();
+ const ONLY_HOSTS: bool = true;
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ run.path("src/tools/generate-windows-sys")
+ }
+
+ fn make_run(run: RunConfig<'_>) {
+ run.builder.ensure(GenerateWindowsSys);
+ }
+
+ fn run(self, builder: &Builder<'_>) {
+ let mut cmd = builder.tool_cmd(Tool::GenerateWindowsSys);
+ cmd.arg(&builder.src);
+ builder.run(&mut cmd);
+ }
+}
+
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
+pub struct GenerateCompletions;
+
+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");
+ }
+ }
+
+ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
+ run.alias("generate-completions")
+ }
+
+ fn make_run(run: RunConfig<'_>) {
+ run.builder.ensure(GenerateCompletions);
+ }
+}