|
6 | 6 | use std::env; |
7 | 7 | use std::str; |
8 | 8 | use std::fs; |
9 | | -use std::io::{self, Write}; |
| 9 | +use std::io; |
10 | 10 | use std::path::{Path, PathBuf}; |
11 | 11 | use std::process::Command; |
12 | | -use std::time::{SystemTime, Instant}; |
| 12 | +use std::time::Instant; |
13 | 13 |
|
14 | 14 | use build_helper::t; |
15 | 15 |
|
@@ -254,90 +254,20 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> { |
254 | 254 | } |
255 | 255 | } |
256 | 256 |
|
257 | | -/// An RAII structure that indicates all output until this instance is dropped |
258 | | -/// is part of the same group. |
259 | | -/// |
260 | | -/// On Travis CI, these output will be folded by default, together with the |
261 | | -/// elapsed time in this block. This reduces noise from unnecessary logs, |
262 | | -/// allowing developers to quickly identify the error. |
263 | | -/// |
264 | | -/// Travis CI supports folding by printing `travis_fold:start:<name>` and |
265 | | -/// `travis_fold:end:<name>` around the block. Time elapsed is recognized |
266 | | -/// similarly with `travis_time:[start|end]:<name>`. These are undocumented, but |
267 | | -/// can easily be deduced from source code of the [Travis build commands]. |
268 | | -/// |
269 | | -/// [Travis build commands]: |
270 | | -/// https://github.com/travis-ci/travis-build/blob/f603c0089/lib/travis/build/templates/header.sh |
271 | | -pub struct OutputFolder { |
272 | | - name: String, |
273 | | - start_time: SystemTime, // we need SystemTime to get the UNIX timestamp. |
274 | | -} |
275 | | - |
276 | | -impl OutputFolder { |
277 | | - /// Creates a new output folder with the given group name. |
278 | | - pub fn new(name: String) -> OutputFolder { |
279 | | - // "\r" moves the cursor to the beginning of the line, and "\x1b[0K" is |
280 | | - // the ANSI escape code to clear from the cursor to end of line. |
281 | | - // Travis seems to have trouble when _not_ using "\r\x1b[0K", that will |
282 | | - // randomly put lines to the top of the webpage. |
283 | | - print!("travis_fold:start:{0}\r\x1b[0Ktravis_time:start:{0}\r\x1b[0K", name); |
284 | | - OutputFolder { |
285 | | - name, |
286 | | - start_time: SystemTime::now(), |
287 | | - } |
288 | | - } |
289 | | -} |
290 | | - |
291 | | -impl Drop for OutputFolder { |
292 | | - fn drop(&mut self) { |
293 | | - use std::time::*; |
294 | | - use std::u64; |
295 | | - |
296 | | - fn to_nanos(duration: Result<Duration, SystemTimeError>) -> u64 { |
297 | | - match duration { |
298 | | - Ok(d) => d.as_secs() * 1_000_000_000 + d.subsec_nanos() as u64, |
299 | | - Err(_) => u64::MAX, |
300 | | - } |
301 | | - } |
302 | | - |
303 | | - let end_time = SystemTime::now(); |
304 | | - let duration = end_time.duration_since(self.start_time); |
305 | | - let start = self.start_time.duration_since(UNIX_EPOCH); |
306 | | - let finish = end_time.duration_since(UNIX_EPOCH); |
307 | | - println!( |
308 | | - "travis_fold:end:{0}\r\x1b[0K\n\ |
309 | | - travis_time:end:{0}:start={1},finish={2},duration={3}\r\x1b[0K", |
310 | | - self.name, |
311 | | - to_nanos(start), |
312 | | - to_nanos(finish), |
313 | | - to_nanos(duration) |
314 | | - ); |
315 | | - io::stdout().flush().unwrap(); |
316 | | - } |
317 | | -} |
318 | | - |
319 | 257 | /// The CI environment rustbuild is running in. This mainly affects how the logs |
320 | 258 | /// are printed. |
321 | 259 | #[derive(Copy, Clone, PartialEq, Eq, Debug)] |
322 | 260 | pub enum CiEnv { |
323 | 261 | /// Not a CI environment. |
324 | 262 | None, |
325 | | - /// The Travis CI environment, for Linux (including Docker) and macOS builds. |
326 | | - Travis, |
327 | | - /// The AppVeyor environment, for Windows builds. |
328 | | - AppVeyor, |
329 | 263 | /// The Azure Pipelines environment, for Linux (including Docker), Windows, and macOS builds. |
330 | 264 | AzurePipelines, |
331 | 265 | } |
332 | 266 |
|
333 | 267 | impl CiEnv { |
334 | 268 | /// Obtains the current CI environment. |
335 | 269 | pub fn current() -> CiEnv { |
336 | | - if env::var("TRAVIS").ok().map_or(false, |e| &*e == "true") { |
337 | | - CiEnv::Travis |
338 | | - } else if env::var("APPVEYOR").ok().map_or(false, |e| &*e == "True") { |
339 | | - CiEnv::AppVeyor |
340 | | - } else if env::var("TF_BUILD").ok().map_or(false, |e| &*e == "True") { |
| 270 | + if env::var("TF_BUILD").ok().map_or(false, |e| &*e == "True") { |
341 | 271 | CiEnv::AzurePipelines |
342 | 272 | } else { |
343 | 273 | CiEnv::None |
|
0 commit comments