]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/channel.rs
New upstream version 1.16.0+dfsg1
[rustc.git] / src / bootstrap / channel.rs
CommitLineData
7453a54e
SL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
a7813a04
XL
11//! Build configuration for Rust's release channels.
12//!
13//! Implements the stable/beta/nightly channel distinctions by setting various
14//! flags like the `unstable_features`, calculating variables like `release` and
15//! `package_vers`, and otherwise indicating to the compiler what it should
16//! print out as part of its version information.
17
476ff2be 18use std::fs::File;
7453a54e 19use std::io::prelude::*;
7453a54e
SL
20use std::process::Command;
21
22use build_helper::output;
23
5bcae85e 24use Build;
7453a54e
SL
25
26pub fn collect(build: &mut Build) {
a7813a04
XL
27 // Currently the canonical source for the release number (e.g. 1.10.0) and
28 // the prerelease version (e.g. `.1`) is in `mk/main.mk`. We "parse" that
29 // here to learn about those numbers.
7453a54e
SL
30 let mut main_mk = String::new();
31 t!(t!(File::open(build.src.join("mk/main.mk"))).read_to_string(&mut main_mk));
32 let mut release_num = "";
33 let mut prerelease_version = "";
34 for line in main_mk.lines() {
35 if line.starts_with("CFG_RELEASE_NUM") {
36 release_num = line.split('=').skip(1).next().unwrap().trim();
37 }
38 if line.starts_with("CFG_PRERELEASE_VERSION") {
39 prerelease_version = line.split('=').skip(1).next().unwrap().trim();
40 }
41 }
42
32a655c1
SL
43 build.release_num = release_num.to_string();
44 build.prerelease_version = release_num.to_string();
45
a7813a04
XL
46 // Depending on the channel, passed in `./configure --release-channel`,
47 // determine various properties of the build.
7453a54e
SL
48 match &build.config.channel[..] {
49 "stable" => {
50 build.release = release_num.to_string();
54a0048b 51 build.package_vers = build.release.clone();
7453a54e
SL
52 build.unstable_features = false;
53 }
54 "beta" => {
55 build.release = format!("{}-beta{}", release_num,
56 prerelease_version);
54a0048b 57 build.package_vers = "beta".to_string();
7453a54e
SL
58 build.unstable_features = false;
59 }
60 "nightly" => {
61 build.release = format!("{}-nightly", release_num);
54a0048b 62 build.package_vers = "nightly".to_string();
7453a54e
SL
63 build.unstable_features = true;
64 }
65 _ => {
66 build.release = format!("{}-dev", release_num);
54a0048b 67 build.package_vers = build.release.clone();
7453a54e
SL
68 build.unstable_features = true;
69 }
70 }
71 build.version = build.release.clone();
72
a7813a04
XL
73 // If we have a git directory, add in some various SHA information of what
74 // commit this compiler was compiled from.
476ff2be 75 if build.src.join(".git").is_dir() {
7453a54e
SL
76 let ver_date = output(Command::new("git").current_dir(&build.src)
77 .arg("log").arg("-1")
78 .arg("--date=short")
79 .arg("--pretty=format:%cd"));
80 let ver_hash = output(Command::new("git").current_dir(&build.src)
81 .arg("rev-parse").arg("HEAD"));
82 let short_ver_hash = output(Command::new("git")
83 .current_dir(&build.src)
84 .arg("rev-parse")
85 .arg("--short=9")
86 .arg("HEAD"));
87 let ver_date = ver_date.trim().to_string();
88 let ver_hash = ver_hash.trim().to_string();
89 let short_ver_hash = short_ver_hash.trim().to_string();
90 build.version.push_str(&format!(" ({} {})", short_ver_hash,
91 ver_date));
92 build.ver_date = Some(ver_date.to_string());
93 build.ver_hash = Some(ver_hash);
94 build.short_ver_hash = Some(short_ver_hash);
95 }
7453a54e 96}