Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distribute Rustfmt #45903

Merged
merged 2 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ impl<'a> Builder<'a> {
doc::Reference, doc::Rustdoc, doc::CargoBook),
Kind::Dist => describe!(dist::Docs, dist::Mingw, dist::Rustc, dist::DebuggerScripts,
dist::Std, dist::Analysis, dist::Src, dist::PlainSourceTarball, dist::Cargo,
dist::Rls, dist::Extended, dist::HashSign, dist::DontDistWithMiriEnabled),
dist::Rls, dist::Rustfmt, dist::Extended, dist::HashSign,
dist::DontDistWithMiriEnabled),
Kind::Install => describe!(install::Docs, install::Std, install::Cargo, install::Rls,
install::Analysis, install::Src, install::Rustc),
}
Expand Down
89 changes: 89 additions & 0 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub fn pkgname(build: &Build, component: &str) -> String {
format!("{}-{}", component, build.cargo_package_vers())
} else if component == "rls" {
format!("{}-{}", component, build.rls_package_vers())
} else if component == "rustfmt" {
format!("{}-{}", component, build.rustfmt_package_vers())
} else {
assert!(component.starts_with("rust"));
format!("{}-{}", component, build.rust_package_vers())
Expand Down Expand Up @@ -1112,6 +1114,92 @@ impl Step for Rls {
}


#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Rustfmt {
pub stage: u32,
pub target: Interned<String>,
}

impl Step for Rustfmt {
type Output = Option<PathBuf>;
const ONLY_BUILD_TARGETS: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun) -> ShouldRun {
run.path("rustfmt")
}

fn make_run(run: RunConfig) {
run.builder.ensure(Rustfmt {
stage: run.builder.top_stage,
target: run.target,
});
}

fn run(self, builder: &Builder) -> Option<PathBuf> {
let build = builder.build;
let stage = self.stage;
let target = self.target;
assert!(build.config.extended);

if !builder.config.toolstate.rustfmt.testing() {
println!("skipping Dist Rustfmt stage{} ({})", stage, target);
return None
}

println!("Dist Rustfmt stage{} ({})", stage, target);
let src = build.src.join("src/tools/rustfmt");
let release_num = build.release_num("rustfmt");
let name = pkgname(build, "rustfmt");
let version = build.rustfmt_info.version(build, &release_num);

let tmp = tmpdir(build);
let image = tmp.join("rustfmt-image");
drop(fs::remove_dir_all(&image));
t!(fs::create_dir_all(&image));

// Prepare the image directory
// We expect RLS to build, because we've exited this step above if tool
// state for RLS isn't testing.
let rustfmt = builder.ensure(tool::Rustfmt {
compiler: builder.compiler(stage, build.build),
target
}).expect("Rustfmt to build: toolstate is testing");
install(&rustfmt, &image.join("bin"), 0o755);
let doc = image.join("share/doc/rustfmt");
install(&src.join("README.md"), &doc, 0o644);
install(&src.join("LICENSE-MIT"), &doc, 0o644);
install(&src.join("LICENSE-APACHE"), &doc, 0o644);

// Prepare the overlay
let overlay = tmp.join("rustfmt-overlay");
drop(fs::remove_dir_all(&overlay));
t!(fs::create_dir_all(&overlay));
install(&src.join("README.md"), &overlay, 0o644);
install(&src.join("LICENSE-MIT"), &overlay, 0o644);
install(&src.join("LICENSE-APACHE"), &overlay, 0o644);
t!(t!(File::create(overlay.join("version"))).write_all(version.as_bytes()));

// Generate the installer tarball
let mut cmd = rust_installer(builder);
cmd.arg("generate")
.arg("--product-name=Rust")
.arg("--rel-manifest-dir=rustlib")
.arg("--success-message=rustfmt-ready-to-fmt.")
.arg("--image-dir").arg(&image)
.arg("--work-dir").arg(&tmpdir(build))
.arg("--output-dir").arg(&distdir(build))
.arg("--non-installed-overlay").arg(&overlay)
.arg(format!("--package-name={}-{}", name, target))
.arg("--legacy-manifest-dirs=rustlib,cargo")
.arg("--component-name=rustfmt-preview");

build.run(&mut cmd);
Some(distdir(build).join(format!("{}-{}.tar.gz", name, target)))
}
}


#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct DontDistWithMiriEnabled;

Expand Down Expand Up @@ -1606,6 +1694,7 @@ impl Step for HashSign {
cmd.arg(build.rust_package_vers());
cmd.arg(build.package_vers(&build.release_num("cargo")));
cmd.arg(build.package_vers(&build.release_num("rls")));
cmd.arg(build.package_vers(&build.release_num("rustfmt")));
cmd.arg(addr);

t!(fs::create_dir_all(distdir(build)));
Expand Down
8 changes: 8 additions & 0 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub struct Build {
rust_info: channel::GitInfo,
cargo_info: channel::GitInfo,
rls_info: channel::GitInfo,
rustfmt_info: channel::GitInfo,
local_rebuild: bool,
fail_fast: bool,
verbosity: usize,
Expand Down Expand Up @@ -304,6 +305,7 @@ impl Build {
let rust_info = channel::GitInfo::new(&config, &src);
let cargo_info = channel::GitInfo::new(&config, &src.join("src/tools/cargo"));
let rls_info = channel::GitInfo::new(&config, &src.join("src/tools/rls"));
let rustfmt_info = channel::GitInfo::new(&config, &src.join("src/tools/rustfmt"));

Build {
initial_rustc: config.initial_rustc.clone(),
Expand All @@ -323,6 +325,7 @@ impl Build {
rust_info,
cargo_info,
rls_info,
rustfmt_info,
cc: HashMap::new(),
cxx: HashMap::new(),
ar: HashMap::new(),
Expand Down Expand Up @@ -814,6 +817,11 @@ impl Build {
self.package_vers(&self.release_num("rls"))
}

/// Returns the value of `package_vers` above for rustfmt
fn rustfmt_package_vers(&self) -> String {
self.package_vers(&self.release_num("rustfmt"))
}

/// Returns the `version` string associated with this compiler for Rust
/// itself.
///
Expand Down
30 changes: 30 additions & 0 deletions src/tools/build-manifest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,18 +168,24 @@ struct Builder {
rust_release: String,
cargo_release: String,
rls_release: String,
rustfmt_release: String,

input: PathBuf,
output: PathBuf,
gpg_passphrase: String,
digests: BTreeMap<String, String>,
s3_address: String,
date: String,

rust_version: Option<String>,
cargo_version: Option<String>,
rls_version: Option<String>,
rustfmt_version: Option<String>,

rust_git_commit_hash: Option<String>,
cargo_git_commit_hash: Option<String>,
rls_git_commit_hash: Option<String>,
rustfmt_git_commit_hash: Option<String>,
}

fn main() {
Expand All @@ -190,6 +196,7 @@ fn main() {
let rust_release = args.next().unwrap();
let cargo_release = args.next().unwrap();
let rls_release = args.next().unwrap();
let rustfmt_release = args.next().unwrap();
let s3_address = args.next().unwrap();
let mut passphrase = String::new();
t!(io::stdin().read_to_string(&mut passphrase));
Expand All @@ -198,18 +205,24 @@ fn main() {
rust_release,
cargo_release,
rls_release,
rustfmt_release,

input,
output,
gpg_passphrase: passphrase,
digests: BTreeMap::new(),
s3_address,
date,

rust_version: None,
cargo_version: None,
rls_version: None,
rustfmt_version: None,

rust_git_commit_hash: None,
cargo_git_commit_hash: None,
rls_git_commit_hash: None,
rustfmt_git_commit_hash: None,
}.build();
}

Expand All @@ -218,9 +231,12 @@ impl Builder {
self.rust_version = self.version("rust", "x86_64-unknown-linux-gnu");
self.cargo_version = self.version("cargo", "x86_64-unknown-linux-gnu");
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
self.rustfmt_version = self.version("rustfmt", "x86_64-unknown-linux-gnu");

self.rust_git_commit_hash = self.git_commit_hash("rust", "x86_64-unknown-linux-gnu");
self.cargo_git_commit_hash = self.git_commit_hash("cargo", "x86_64-unknown-linux-gnu");
self.rls_git_commit_hash = self.git_commit_hash("rls", "x86_64-unknown-linux-gnu");
self.rustfmt_git_commit_hash = self.git_commit_hash("rustfmt", "x86_64-unknown-linux-gnu");

self.digest_and_sign();
let manifest = self.build_manifest();
Expand Down Expand Up @@ -255,9 +271,11 @@ impl Builder {
self.package("rust-docs", &mut manifest.pkg, TARGETS);
self.package("rust-src", &mut manifest.pkg, &["*"]);
self.package("rls-preview", &mut manifest.pkg, HOSTS);
self.package("rustfmt-preview", &mut manifest.pkg, HOSTS);
self.package("rust-analysis", &mut manifest.pkg, TARGETS);

let rls_present = manifest.pkg.contains_key("rls-preview");
let rustfmt_present = manifest.pkg.contains_key("rustfmt-preview");

if rls_present {
manifest.renames.insert("rls".to_owned(), Rename { to: "rls-preview".to_owned() });
Expand Down Expand Up @@ -306,6 +324,12 @@ impl Builder {
target: host.to_string(),
});
}
if rustfmt_present {
extensions.push(Component {
pkg: "rustfmt-preview".to_string(),
target: host.to_string(),
});
}
extensions.push(Component {
pkg: "rust-analysis".to_string(),
target: host.to_string(),
Expand Down Expand Up @@ -391,6 +415,8 @@ impl Builder {
format!("cargo-{}-{}.tar.gz", self.cargo_release, target)
} else if component == "rls" || component == "rls-preview" {
format!("rls-{}-{}.tar.gz", self.rls_release, target)
} else if component == "rustfmt" || component == "rustfmt-preview" {
format!("rustfmt-{}-{}.tar.gz", self.rustfmt_release, target)
} else {
format!("{}-{}-{}.tar.gz", component, self.rust_release, target)
}
Expand All @@ -401,6 +427,8 @@ impl Builder {
&self.cargo_version
} else if component == "rls" || component == "rls-preview" {
&self.rls_version
} else if component == "rustfmt" || component == "rustfmt-preview" {
&self.rustfmt_version
} else {
&self.rust_version
}
Expand All @@ -411,6 +439,8 @@ impl Builder {
&self.cargo_git_commit_hash
} else if component == "rls" || component == "rls-preview" {
&self.rls_git_commit_hash
} else if component == "rustfmt" || component == "rustfmt-preview" {
&self.rustfmt_git_commit_hash
} else {
&self.rust_git_commit_hash
}
Expand Down