2015-11-20 00:20:12 +01:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
//! Build configuration for Rust's release channels.
|
|
|
|
//!
|
|
|
|
//! Implements the stable/beta/nightly channel distinctions by setting various
|
|
|
|
//! flags like the `unstable_features`, calculating variables like `release` and
|
|
|
|
//! `package_vers`, and otherwise indicating to the compiler what it should
|
|
|
|
//! print out as part of its version information.
|
|
|
|
|
2015-11-20 00:20:12 +01:00
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::prelude::*;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
use build_helper::output;
|
2016-04-12 02:09:55 +02:00
|
|
|
use md5;
|
2015-11-20 00:20:12 +01:00
|
|
|
|
|
|
|
use build::Build;
|
|
|
|
|
|
|
|
pub fn collect(build: &mut Build) {
|
2016-05-03 00:16:15 +02:00
|
|
|
// Currently the canonical source for the release number (e.g. 1.10.0) and
|
|
|
|
// the prerelease version (e.g. `.1`) is in `mk/main.mk`. We "parse" that
|
|
|
|
// here to learn about those numbers.
|
2015-11-20 00:20:12 +01:00
|
|
|
let mut main_mk = String::new();
|
|
|
|
t!(t!(File::open(build.src.join("mk/main.mk"))).read_to_string(&mut main_mk));
|
|
|
|
let mut release_num = "";
|
|
|
|
let mut prerelease_version = "";
|
|
|
|
for line in main_mk.lines() {
|
|
|
|
if line.starts_with("CFG_RELEASE_NUM") {
|
|
|
|
release_num = line.split('=').skip(1).next().unwrap().trim();
|
|
|
|
}
|
|
|
|
if line.starts_with("CFG_PRERELEASE_VERSION") {
|
|
|
|
prerelease_version = line.split('=').skip(1).next().unwrap().trim();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
// Depending on the channel, passed in `./configure --release-channel`,
|
|
|
|
// determine various properties of the build.
|
2015-11-20 00:20:12 +01:00
|
|
|
match &build.config.channel[..] {
|
|
|
|
"stable" => {
|
|
|
|
build.release = release_num.to_string();
|
2016-03-14 00:52:19 +01:00
|
|
|
build.package_vers = build.release.clone();
|
2015-11-20 00:20:12 +01:00
|
|
|
build.unstable_features = false;
|
|
|
|
}
|
|
|
|
"beta" => {
|
|
|
|
build.release = format!("{}-beta{}", release_num,
|
|
|
|
prerelease_version);
|
2016-03-14 00:52:19 +01:00
|
|
|
build.package_vers = "beta".to_string();
|
2015-11-20 00:20:12 +01:00
|
|
|
build.unstable_features = false;
|
|
|
|
}
|
|
|
|
"nightly" => {
|
|
|
|
build.release = format!("{}-nightly", release_num);
|
2016-03-14 00:52:19 +01:00
|
|
|
build.package_vers = "nightly".to_string();
|
2015-11-20 00:20:12 +01:00
|
|
|
build.unstable_features = true;
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
build.release = format!("{}-dev", release_num);
|
2016-03-14 00:52:19 +01:00
|
|
|
build.package_vers = build.release.clone();
|
2015-11-20 00:20:12 +01:00
|
|
|
build.unstable_features = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
build.version = build.release.clone();
|
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
// If we have a git directory, add in some various SHA information of what
|
|
|
|
// commit this compiler was compiled from.
|
2015-11-20 00:20:12 +01:00
|
|
|
if fs::metadata(build.src.join(".git")).is_ok() {
|
|
|
|
let ver_date = output(Command::new("git").current_dir(&build.src)
|
|
|
|
.arg("log").arg("-1")
|
|
|
|
.arg("--date=short")
|
|
|
|
.arg("--pretty=format:%cd"));
|
|
|
|
let ver_hash = output(Command::new("git").current_dir(&build.src)
|
|
|
|
.arg("rev-parse").arg("HEAD"));
|
|
|
|
let short_ver_hash = output(Command::new("git")
|
|
|
|
.current_dir(&build.src)
|
|
|
|
.arg("rev-parse")
|
|
|
|
.arg("--short=9")
|
|
|
|
.arg("HEAD"));
|
|
|
|
let ver_date = ver_date.trim().to_string();
|
|
|
|
let ver_hash = ver_hash.trim().to_string();
|
|
|
|
let short_ver_hash = short_ver_hash.trim().to_string();
|
|
|
|
build.version.push_str(&format!(" ({} {})", short_ver_hash,
|
|
|
|
ver_date));
|
|
|
|
build.ver_date = Some(ver_date.to_string());
|
|
|
|
build.ver_hash = Some(ver_hash);
|
|
|
|
build.short_ver_hash = Some(short_ver_hash);
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
// Calculate this compiler's bootstrap key, which is currently defined as
|
|
|
|
// the first 8 characters of the md5 of the release string.
|
2016-04-12 02:09:55 +02:00
|
|
|
let key = md5::compute(build.release.as_bytes());
|
|
|
|
build.bootstrap_key = format!("{:02x}{:02x}{:02x}{:02x}",
|
|
|
|
key[0], key[1], key[2], key[3]);
|
2016-04-13 20:18:35 +02:00
|
|
|
|
2016-05-03 00:16:15 +02:00
|
|
|
// Slurp up the stage0 bootstrap key as we're bootstrapping from an
|
|
|
|
// otherwise stable compiler.
|
2016-04-13 20:18:35 +02:00
|
|
|
let mut s = String::new();
|
|
|
|
t!(t!(File::open(build.src.join("src/stage0.txt"))).read_to_string(&mut s));
|
|
|
|
if let Some(line) = s.lines().find(|l| l.starts_with("rustc_key")) {
|
|
|
|
if let Some(key) = line.split(": ").nth(1) {
|
|
|
|
build.bootstrap_key_stage0 = key.to_string();
|
|
|
|
}
|
|
|
|
}
|
2015-11-20 00:20:12 +01:00
|
|
|
}
|