]> git.proxmox.com Git - rustc.git/blame - src/bootstrap/build/channel.rs
Imported Upstream version 1.9.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
54a0048b 11use std::env;
7453a54e
SL
12use std::fs::{self, File};
13use std::io::prelude::*;
7453a54e
SL
14use std::process::Command;
15
16use build_helper::output;
54a0048b 17use md5;
7453a54e
SL
18
19use build::Build;
7453a54e
SL
20
21pub fn collect(build: &mut Build) {
22 let mut main_mk = String::new();
23 t!(t!(File::open(build.src.join("mk/main.mk"))).read_to_string(&mut main_mk));
24 let mut release_num = "";
25 let mut prerelease_version = "";
26 for line in main_mk.lines() {
27 if line.starts_with("CFG_RELEASE_NUM") {
28 release_num = line.split('=').skip(1).next().unwrap().trim();
29 }
30 if line.starts_with("CFG_PRERELEASE_VERSION") {
31 prerelease_version = line.split('=').skip(1).next().unwrap().trim();
32 }
33 }
34
35 // FIXME: this is duplicating makefile logic
36 match &build.config.channel[..] {
37 "stable" => {
38 build.release = release_num.to_string();
54a0048b 39 build.package_vers = build.release.clone();
7453a54e
SL
40 build.unstable_features = false;
41 }
42 "beta" => {
43 build.release = format!("{}-beta{}", release_num,
44 prerelease_version);
54a0048b 45 build.package_vers = "beta".to_string();
7453a54e
SL
46 build.unstable_features = false;
47 }
48 "nightly" => {
49 build.release = format!("{}-nightly", release_num);
54a0048b 50 build.package_vers = "nightly".to_string();
7453a54e
SL
51 build.unstable_features = true;
52 }
53 _ => {
54 build.release = format!("{}-dev", release_num);
54a0048b 55 build.package_vers = build.release.clone();
7453a54e
SL
56 build.unstable_features = true;
57 }
58 }
59 build.version = build.release.clone();
60
61 if fs::metadata(build.src.join(".git")).is_ok() {
62 let ver_date = output(Command::new("git").current_dir(&build.src)
63 .arg("log").arg("-1")
64 .arg("--date=short")
65 .arg("--pretty=format:%cd"));
66 let ver_hash = output(Command::new("git").current_dir(&build.src)
67 .arg("rev-parse").arg("HEAD"));
68 let short_ver_hash = output(Command::new("git")
69 .current_dir(&build.src)
70 .arg("rev-parse")
71 .arg("--short=9")
72 .arg("HEAD"));
73 let ver_date = ver_date.trim().to_string();
74 let ver_hash = ver_hash.trim().to_string();
75 let short_ver_hash = short_ver_hash.trim().to_string();
76 build.version.push_str(&format!(" ({} {})", short_ver_hash,
77 ver_date));
78 build.ver_date = Some(ver_date.to_string());
79 build.ver_hash = Some(ver_hash);
80 build.short_ver_hash = Some(short_ver_hash);
81 }
82
54a0048b
SL
83 let key = md5::compute(build.release.as_bytes());
84 build.bootstrap_key = format!("{:02x}{:02x}{:02x}{:02x}",
85 key[0], key[1], key[2], key[3]);
86 env::set_var("RUSTC_BOOTSTRAP_KEY", &build.bootstrap_key);
7453a54e 87}