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.
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.
11 //! Build configuration for Rust's release channels.
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.
19 use std::io::prelude::*;
20 use std::process::Command;
22 use build_helper::output;
26 pub fn collect(build: &mut Build) {
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.
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();
38 if line.starts_with("CFG_PRERELEASE_VERSION") {
39 prerelease_version = line.split('=').skip(1).next().unwrap().trim();
43 build.release_num = release_num.to_string();
44 build.prerelease_version = release_num.to_string();
46 // Depending on the channel, passed in `./configure --release-channel`,
47 // determine various properties of the build.
48 match &build.config.channel[..] {
50 build.release = release_num.to_string();
51 build.package_vers = build.release.clone();
52 build.unstable_features = false;
55 build.release = format!("{}-beta{}", release_num,
57 build.package_vers = "beta".to_string();
58 build.unstable_features = false;
61 build.release = format!("{}-nightly", release_num);
62 build.package_vers = "nightly".to_string();
63 build.unstable_features = true;
66 build.release = format!("{}-dev", release_num);
67 build.package_vers = build.release.clone();
68 build.unstable_features = true;
71 build.version = build.release.clone();
73 // If we have a git directory, add in some various SHA information of what
74 // commit this compiler was compiled from.
75 if build.src.join(".git").is_dir() {
76 let ver_date = output(Command::new("git").current_dir(&build.src)
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)
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,
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);