|
1 | 1 | use diffy; |
2 | 2 | use std::env; |
3 | 3 | use std::fmt::Debug; |
4 | | -use std::io; |
| 4 | +use std::io::{self, Write}; |
5 | 5 | use std::path::{Path, PathBuf}; |
6 | | -use std::process::Command; |
| 6 | +use std::process::{Command, Stdio}; |
7 | 7 | use std::str::Utf8Error; |
8 | 8 | use tracing::info; |
9 | 9 | use walkdir::WalkDir; |
@@ -115,39 +115,46 @@ impl RustfmtRunner { |
115 | 115 | code: &'a str, |
116 | 116 | config: &Option<Vec<String>>, |
117 | 117 | ) -> Result<String, CheckDiffError> { |
118 | | - let config_arg: String = match config { |
119 | | - Some(configs) => { |
120 | | - let mut result = String::new(); |
121 | | - result.push(','); |
122 | | - for arg in configs.iter() { |
123 | | - result.push_str(arg.as_str()); |
124 | | - result.push(','); |
125 | | - } |
126 | | - result.pop(); |
127 | | - result |
128 | | - } |
129 | | - None => String::new(), |
130 | | - }; |
131 | | - let config = format!( |
132 | | - "error_on_line_overflow=false,error_on_unformatted=false{}", |
133 | | - config_arg.as_str() |
134 | | - ); |
135 | | - |
136 | | - let output = Command::new(&self.binary_path) |
| 118 | + let config = create_config_arg(config); |
| 119 | + let mut command = Command::new(&self.binary_path) |
137 | 120 | .env("LD_LIBRARY_PATH", &self.ld_library_path) |
138 | 121 | .args([ |
139 | 122 | "--unstable-features", |
140 | 123 | "--skip-children", |
141 | 124 | "--emit=stdout", |
142 | 125 | config.as_str(), |
143 | | - code, |
144 | 126 | ]) |
145 | | - .output()?; |
| 127 | + .stdin(Stdio::piped()) |
| 128 | + .stdout(Stdio::piped()) |
| 129 | + .stderr(Stdio::piped()) |
| 130 | + .spawn()?; |
146 | 131 |
|
| 132 | + command.stdin.as_mut().unwrap().write_all(code.as_bytes())?; |
| 133 | + let output = command.wait_with_output()?; |
147 | 134 | Ok(std::str::from_utf8(&output.stdout)?.to_string()) |
148 | 135 | } |
149 | 136 | } |
150 | 137 |
|
| 138 | +fn create_config_arg(config: &Option<Vec<String>>) -> String { |
| 139 | + let config_arg: String = match config { |
| 140 | + Some(configs) => { |
| 141 | + let mut result = String::new(); |
| 142 | + result.push(','); |
| 143 | + for arg in configs.iter() { |
| 144 | + result.push_str(arg.as_str()); |
| 145 | + result.push(','); |
| 146 | + } |
| 147 | + result.pop(); |
| 148 | + result |
| 149 | + } |
| 150 | + None => String::new(), |
| 151 | + }; |
| 152 | + let config = format!( |
| 153 | + "error_on_line_overflow=false,error_on_unformatted=false{}", |
| 154 | + config_arg.as_str() |
| 155 | + ); |
| 156 | + config |
| 157 | +} |
151 | 158 | /// Clone a git repository |
152 | 159 | /// |
153 | 160 | /// Parameters: |
|
0 commit comments