Skip to content

Separate rustfmt into multiple crates #2419

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

Merged
merged 9 commits into from
Feb 11, 2018
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
99 changes: 84 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 9 additions & 58 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,58 +1,9 @@
[package]

name = "rustfmt-nightly"
version = "0.3.8"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
build = "build.rs"
categories = ["development-tools"]

[lib]
doctest = false

[[bin]]
name = "rustfmt"

[[bin]]
name = "cargo-fmt"

[[bin]]
name = "rustfmt-format-diff"

[[bin]]
name = "git-rustfmt"

[features]
default = ["cargo-fmt", "rustfmt-format-diff"]
cargo-fmt = []
rustfmt-format-diff = []

[dependencies]
toml = "0.4"
serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
unicode-segmentation = "1.0.0"
regex = "0.2"
term = "0.4"
diff = "0.1"
log = "0.3"
env_logger = "0.4"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.4"
rustc-ap-syntax = "29.0.0"
rustc-ap-rustc_errors = "29.0.0"

[dev-dependencies]
lazy_static = "1.0.0"

[target.'cfg(unix)'.dependencies]
libc = "0.2.11"

[target.'cfg(windows)'.dependencies]
kernel32-sys = "0.2.2"
winapi = "0.2.7"
[workspace]
members = [
"cargo-fmt",
"git-rustfmt",
"rustfmt-bin",
"rustfmt-config",
"rustfmt-core",
"rustfmt-format-diff",
]
3 changes: 0 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ install:
# ???
build: false

# Build rustfmt, run the executables as
test_script:
- cargo build --verbose
- cargo run --bin rustfmt -- --help
- cargo run --bin cargo-fmt -- --help
- cargo test
17 changes: 17 additions & 0 deletions cargo-fmt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "cargo-fmt"
version = "0.4.0"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Cargo frontend for rustfmt"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]

[[bin]]
name = "cargo-fmt"

[dependencies]
cargo_metadata = "0.4"
getopts = "0.2"
serde_json = "1.0"
File renamed without changes.
19 changes: 19 additions & 0 deletions git-rustfmt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "git-rustfmt"
version = "0.4.0"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Run rustfmt against git diff"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
categories = ["development-tools"]

[[bin]]
name = "git-rustfmt"

[dependencies]
env_logger = "0.4"
getopts = "0.2"
log = "0.3"
rustfmt-config = { path = "../rustfmt-config" }
rustfmt-core = { path = "../rustfmt-core" }
14 changes: 12 additions & 2 deletions src/bin/git-rustfmt.rs → git-rustfmt/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// Copyright 2018 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.

extern crate env_logger;
extern crate getopts;
#[macro_use]
extern crate log;
extern crate rustfmt_nightly as rustfmt;
extern crate rustfmt_config as config;
extern crate rustfmt_core as rustfmt;

use std::env;
use std::path::{Path, PathBuf};
Expand All @@ -12,7 +23,6 @@ use std::str::FromStr;
use getopts::{Matches, Options};

use rustfmt::{run, Input};
use rustfmt::config;

fn prune_files(files: Vec<&str>) -> Vec<&str> {
let prefixes: Vec<_> = files
Expand Down
20 changes: 20 additions & 0 deletions rustfmt-bin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "rustfmt-bin"
version = "0.4.0"
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
description = "Tool to find and fix Rust formatting issues"
repository = "https://github.com/rust-lang-nursery/rustfmt"
readme = "README.md"
license = "Apache-2.0/MIT"
build = "build.rs"
categories = ["development-tools"]

[[bin]]
name = "rustfmt"
path = "src/main.rs"

[dependencies]
env_logger = "0.4"
getopts = "0.2"
rustfmt-config = { path = "../rustfmt-config" }
rustfmt-core = { path = "../rustfmt-core" }
49 changes: 49 additions & 0 deletions rustfmt-bin/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright 2017 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.

use std::env;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Command;

fn main() {
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());

File::create(out_dir.join("commit-info.txt"))
.unwrap()
.write_all(commit_info().as_bytes())
.unwrap();
}

// Try to get hash and date of the last commit on a best effort basis. If anything goes wrong
// (git not installed or if this is not a git repository) just return an empty string.
fn commit_info() -> String {
match (commit_hash(), commit_date()) {
(Some(hash), Some(date)) => format!(" ({} {})", hash.trim_right(), date),
_ => String::new(),
}
}

fn commit_hash() -> Option<String> {
Command::new("git")
.args(&["rev-parse", "--short", "HEAD"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}

fn commit_date() -> Option<String> {
Command::new("git")
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
.output()
.ok()
.and_then(|r| String::from_utf8(r.stdout).ok())
}
Loading