]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/build/channel.rs
Imported Upstream version 1.11.0+dfsg1
[rustc.git] / src / bootstrap / build / 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
7453a54e
SL
18use std::fs::{self, File};
19use std::io::prelude::*;
7453a54e
SL
20use std::process::Command;
21
22use build_helper::output;
54a0048b 23use md5;
7453a54e
SL
24
25use build::Build;
7453a54e
SL
26
27pub fn collect(build: &mut Build) {
a7813a04
XL
28 // Currently the canonical source for the release number (e.g. 1.10.0) and
29 // the prerelease version (e.g. `.1`) is in `mk/main.mk`. We "parse" that
30 // here to learn about those numbers.
7453a54e
SL
31 let mut main_mk = String::new();
32 t!(t!(File::open(build.src.join("mk/main.mk"))).read_to_string(&mut main_mk));
33 let mut release_num = "";
34 let mut prerelease_version = "";
35 for line in main_mk.lines() {
36 if line.starts_with("CFG_RELEASE_NUM") {
37 release_num = line.split('=').skip(1).next().unwrap().trim();
38 }
39 if line.starts_with("CFG_PRERELEASE_VERSION") {
40 prerelease_version = line.split('=').skip(1).next().unwrap().trim();
41 }
42 }
43
a7813a04
XL
44 // Depending on the channel, passed in `./configure --release-channel`,
45 // determine various properties of the build.
7453a54e
SL
46 match &build.config.channel[..] {
47 "stable" => {
48 build.release = release_num.to_string();
54a0048b 49 build.package_vers = build.release.clone();
7453a54e
SL
50 build.unstable_features = false;
51 }
52 "beta" => {
53 build.release = format!("{}-beta{}", release_num,
54 prerelease_version);
54a0048b 55 build.package_vers = "beta".to_string();
7453a54e
SL
56 build.unstable_features = false;
57 }
58 "nightly" => {
59 build.release = format!("{}-nightly", release_num);
54a0048b 60 build.package_vers = "nightly".to_string();
7453a54e
SL
61 build.unstable_features = true;
62 }
63 _ => {
64 build.release = format!("{}-dev", release_num);
54a0048b 65 build.package_vers = build.release.clone();
7453a54e
SL
66 build.unstable_features = true;
67 }
68 }
69 build.version = build.release.clone();
70
a7813a04
XL
71 // If we have a git directory, add in some various SHA information of what
72 // commit this compiler was compiled from.
7453a54e
SL
73 if fs::metadata(build.src.join(".git")).is_ok() {
74 let ver_date = output(Command::new("git").current_dir(&build.src)
75 .arg("log").arg("-1")
76 .arg("--date=short")
77 .arg("--pretty=format:%cd"));
78 let ver_hash = output(Command::new("git").current_dir(&build.src)
79 .arg("rev-parse").arg("HEAD"));
80 let short_ver_hash = output(Command::new("git")
81 .current_dir(&build.src)
82 .arg("rev-parse")
83 .arg("--short=9")
84 .arg("HEAD"));
85 let ver_date = ver_date.trim().to_string();
86 let ver_hash = ver_hash.trim().to_string();
87 let short_ver_hash = short_ver_hash.trim().to_string();
88 build.version.push_str(&format!(" ({} {})", short_ver_hash,
89 ver_date));
90 build.ver_date = Some(ver_date.to_string());
91 build.ver_hash = Some(ver_hash);
92 build.short_ver_hash = Some(short_ver_hash);
93 }
94
a7813a04
XL
95 // Calculate this compiler's bootstrap key, which is currently defined as
96 // the first 8 characters of the md5 of the release string.
54a0048b
SL
97 let key = md5::compute(build.release.as_bytes());
98 build.bootstrap_key = format!("{:02x}{:02x}{:02x}{:02x}",
99 key[0], key[1], key[2], key[3]);
a7813a04
XL
100
101 // Slurp up the stage0 bootstrap key as we're bootstrapping from an
102 // otherwise stable compiler.
103 let mut s = String::new();
104 t!(t!(File::open(build.src.join("src/stage0.txt"))).read_to_string(&mut s));
105 if let Some(line) = s.lines().find(|l| l.starts_with("rustc_key")) {
106 if let Some(key) = line.split(": ").nth(1) {
107 build.bootstrap_key_stage0 = key.to_string();
108 }
109 }
7453a54e 110}