Skip to content

Commit 28065a5

Browse files
Update to toml 0.4
1 parent 7d4df95 commit 28065a5

File tree

9 files changed

+69
-81
lines changed

9 files changed

+69
-81
lines changed

src/Cargo.lock

+4-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/Cargo.toml

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ build_helper = { path = "../build_helper" }
3333
cmake = "0.1.23"
3434
filetime = "0.1"
3535
num_cpus = "1.0"
36-
toml = "0.1"
3736
getopts = "0.2"
38-
rustc-serialize = "0.3"
3937
gcc = "0.3.50"
4038
libc = "0.2"
41-
serde = "1.0"
42-
serde_json = "1.0"
43-
serde_derive = "1.0"
39+
serde = "1.0.8"
40+
serde_derive = "1.0.8"
41+
serde_json = "1.0.2"
42+
toml = "0.4"

src/bootstrap/builder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use cache::{Cache, Key};
2525
use check;
2626
use flags::Subcommand;
2727
use doc;
28+
use tool;
2829

2930
pub use Compiler;
3031

@@ -144,7 +145,10 @@ impl<'a> Builder<'a> {
144145
let builder = &builder;
145146
match builder.kind {
146147
Kind::Build => check!(builder, paths, compile::Std, compile::Test, compile::Rustc,
147-
compile::StartupObjects),
148+
compile::StartupObjects, tool::BuildManifest, tool::Rustbook, tool::ErrorIndex,
149+
tool::UnstableBookGen, tool::Tidy, tool::Linkchecker, tool::CargoTest,
150+
tool::Compiletest, tool::RemoteTestServer, tool::RemoteTestClient,
151+
tool::RustInstaller, tool::Cargo, tool::Rls),
148152
Kind::Test => check!(builder, paths, check::Tidy, check::Bootstrap, check::Compiletest,
149153
check::Krate, check::KrateLibrustc, check::Linkcheck, check::Cargotest,
150154
check::Cargo, check::Docs, check::ErrorIndex, check::Distcheck),

src/bootstrap/config.rs

+33-31
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ use std::path::PathBuf;
2121
use std::process;
2222

2323
use num_cpus;
24-
use rustc_serialize::Decodable;
25-
use toml::{Parser, Decoder, Value};
24+
use toml;
2625
use util::{exe, push_exe_path};
2726

2827
/// Global configuration for the entire build and/or bootstrap.
@@ -138,7 +137,9 @@ pub struct Target {
138137
/// This structure uses `Decodable` to automatically decode a TOML configuration
139138
/// file into this format, and then this is traversed and written into the above
140139
/// `Config` structure.
141-
#[derive(RustcDecodable, Default)]
140+
#[derive(Deserialize, Default)]
141+
#[serde(deny_unknown_fields)]
142+
#[serde(rename_all = "kebab-case")]
142143
struct TomlConfig {
143144
build: Option<Build>,
144145
install: Option<Install>,
@@ -149,10 +150,14 @@ struct TomlConfig {
149150
}
150151

151152
/// TOML representation of various global build decisions.
152-
#[derive(RustcDecodable, Default, Clone)]
153+
#[derive(Deserialize, Default, Clone)]
154+
#[serde(deny_unknown_fields)]
155+
#[serde(rename_all = "kebab-case")]
153156
struct Build {
154157
build: Option<String>,
158+
#[serde(default)]
155159
host: Vec<String>,
160+
#[serde(default)]
156161
target: Vec<String>,
157162
cargo: Option<String>,
158163
rustc: Option<String>,
@@ -174,7 +179,9 @@ struct Build {
174179
}
175180

176181
/// TOML representation of various global install decisions.
177-
#[derive(RustcDecodable, Default, Clone)]
182+
#[derive(Deserialize, Default, Clone)]
183+
#[serde(deny_unknown_fields)]
184+
#[serde(rename_all = "kebab-case")]
178185
struct Install {
179186
prefix: Option<String>,
180187
sysconfdir: Option<String>,
@@ -185,7 +192,9 @@ struct Install {
185192
}
186193

187194
/// TOML representation of how the LLVM build is configured.
188-
#[derive(RustcDecodable, Default)]
195+
#[derive(Deserialize, Default)]
196+
#[serde(deny_unknown_fields)]
197+
#[serde(rename_all = "kebab-case")]
189198
struct Llvm {
190199
ccache: Option<StringOrBool>,
191200
ninja: Option<bool>,
@@ -200,15 +209,18 @@ struct Llvm {
200209
clean_rebuild: Option<bool>,
201210
}
202211

203-
#[derive(RustcDecodable, Default, Clone)]
212+
#[derive(Deserialize, Default, Clone)]
213+
#[serde(deny_unknown_fields)]
214+
#[serde(rename_all = "kebab-case")]
204215
struct Dist {
205216
sign_folder: Option<String>,
206217
gpg_password_file: Option<String>,
207218
upload_addr: Option<String>,
208219
src_tarball: Option<bool>,
209220
}
210221

211-
#[derive(RustcDecodable)]
222+
#[derive(Deserialize)]
223+
#[serde(untagged)]
212224
enum StringOrBool {
213225
String(String),
214226
Bool(bool),
@@ -221,7 +233,9 @@ impl Default for StringOrBool {
221233
}
222234

223235
/// TOML representation of how the Rust build is configured.
224-
#[derive(RustcDecodable, Default)]
236+
#[derive(Deserialize, Default)]
237+
#[serde(deny_unknown_fields)]
238+
#[serde(rename_all = "kebab-case")]
225239
struct Rust {
226240
optimize: Option<bool>,
227241
codegen_units: Option<u32>,
@@ -243,7 +257,9 @@ struct Rust {
243257
}
244258

245259
/// TOML representation of how each build target is configured.
246-
#[derive(RustcDecodable, Default)]
260+
#[derive(Deserialize, Default)]
261+
#[serde(deny_unknown_fields)]
262+
#[serde(rename_all = "kebab-case")]
247263
struct TomlTarget {
248264
llvm_config: Option<String>,
249265
jemalloc: Option<String>,
@@ -273,27 +289,13 @@ impl Config {
273289

274290
let toml = file.map(|file| {
275291
let mut f = t!(File::open(&file));
276-
let mut toml = String::new();
277-
t!(f.read_to_string(&mut toml));
278-
let mut p = Parser::new(&toml);
279-
let table = match p.parse() {
280-
Some(table) => table,
281-
None => {
282-
println!("failed to parse TOML configuration '{}':", file.to_str().unwrap());
283-
for err in p.errors.iter() {
284-
let (loline, locol) = p.to_linecol(err.lo);
285-
let (hiline, hicol) = p.to_linecol(err.hi);
286-
println!("{}:{}-{}:{}: {}", loline, locol, hiline,
287-
hicol, err.desc);
288-
}
289-
process::exit(2);
290-
}
291-
};
292-
let mut d = Decoder::new(Value::Table(table));
293-
match Decodable::decode(&mut d) {
294-
Ok(cfg) => cfg,
295-
Err(e) => {
296-
println!("failed to decode TOML: {}", e);
292+
let mut contents = String::new();
293+
t!(f.read_to_string(&mut contents));
294+
match toml::from_str(&contents) {
295+
Ok(table) => table,
296+
Err(err) => {
297+
println!("failed to parse TOML configuration '{}': {}",
298+
file.display(), err);
297299
process::exit(2);
298300
}
299301
}

src/bootstrap/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ extern crate filetime;
128128
extern crate gcc;
129129
extern crate getopts;
130130
extern crate num_cpus;
131-
extern crate rustc_serialize;
132131
extern crate toml;
133132

134133
#[cfg(unix)]

src/bootstrap/metadata.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ use std::process::Command;
1313
use std::path::PathBuf;
1414

1515
use build_helper::output;
16-
use rustc_serialize::json;
16+
use serde_json;
1717

1818
use {Build, Crate};
1919

20-
#[derive(RustcDecodable)]
20+
#[derive(Deserialize)]
2121
struct Output {
2222
packages: Vec<Package>,
2323
resolve: Resolve,
2424
}
2525

26-
#[derive(RustcDecodable)]
26+
#[derive(Deserialize)]
2727
struct Package {
2828
id: String,
2929
name: String,
@@ -32,12 +32,12 @@ struct Package {
3232
manifest_path: String,
3333
}
3434

35-
#[derive(RustcDecodable)]
35+
#[derive(Deserialize)]
3636
struct Resolve {
3737
nodes: Vec<ResolveNode>,
3838
}
3939

40-
#[derive(RustcDecodable)]
40+
#[derive(Deserialize)]
4141
struct ResolveNode {
4242
id: String,
4343
dependencies: Vec<String>,
@@ -61,7 +61,7 @@ fn build_krate(build: &mut Build, krate: &str) {
6161
.arg("--format-version").arg("1")
6262
.arg("--manifest-path").arg(build.src.join(krate).join("Cargo.toml"));
6363
let output = output(&mut cargo);
64-
let output: Output = json::decode(&output).unwrap();
64+
let output: Output = serde_json::from_str(&output).unwrap();
6565
let mut id2name = HashMap::new();
6666
for package in output.packages {
6767
if package.source.is_none() {

src/bootstrap/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ tool!(
238238
// .dep(|s| s.name("maybe-clean-tools"))
239239
// .dep(|s| s.name("libstd-tool"))
240240
// .run(move |s| compile::tool(build, s.stage, s.target, "build-manifest"));
241-
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Libstd;
241+
BuildManifest, "src/tools/build-manifest", "build-manifest", Mode::Librustc;
242242
// rules.build("tool-remote-test-server", "src/tools/remote-test-server")
243243
// .dep(|s| s.name("maybe-clean-tools"))
244244
// .dep(|s| s.name("libstd-tool"))

src/tools/build-manifest/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ version = "0.1.0"
44
authors = ["Alex Crichton <[email protected]>"]
55

66
[dependencies]
7-
toml = "0.1"
8-
rustc-serialize = "0.3"
7+
toml = "0.4"
8+
serde = "1.0"
9+
serde_derive = "1.0"

src/tools/build-manifest/src/main.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
// except according to those terms.
1010

1111
extern crate toml;
12-
extern crate rustc_serialize;
12+
#[macro_use]
13+
extern crate serde_derive;
14+
extern crate serde;
1315

1416
use std::collections::BTreeMap;
1517
use std::env;
@@ -99,19 +101,21 @@ static MINGW: &'static [&'static str] = &[
99101
"x86_64-pc-windows-gnu",
100102
];
101103

104+
#[derive(Serialize)]
105+
#[serde(rename_all = "kebab-case")]
102106
struct Manifest {
103107
manifest_version: String,
104108
date: String,
105109
pkg: BTreeMap<String, Package>,
106110
}
107111

108-
#[derive(RustcEncodable)]
112+
#[derive(Serialize)]
109113
struct Package {
110114
version: String,
111115
target: BTreeMap<String, Target>,
112116
}
113117

114-
#[derive(RustcEncodable)]
118+
#[derive(Serialize)]
115119
struct Target {
116120
available: bool,
117121
url: Option<String>,
@@ -136,7 +140,7 @@ impl Target {
136140
}
137141
}
138142

139-
#[derive(RustcEncodable)]
143+
#[derive(Serialize)]
140144
struct Component {
141145
pkg: String,
142146
target: String,
@@ -199,28 +203,16 @@ impl Builder {
199203
self.rls_version = self.version("rls", "x86_64-unknown-linux-gnu");
200204

201205
self.digest_and_sign();
202-
let Manifest { manifest_version, date, pkg } = self.build_manifest();
203-
204-
// Unfortunately we can't use derive(RustcEncodable) here because the
205-
// version field is called `manifest-version`, not `manifest_version`.
206-
// In lieu of that just create the table directly here with a `BTreeMap`
207-
// and wrap it up in a `Value::Table`.
208-
let mut manifest = BTreeMap::new();
209-
manifest.insert("manifest-version".to_string(),
210-
toml::Value::String(manifest_version));
211-
manifest.insert("date".to_string(), toml::Value::String(date.clone()));
212-
manifest.insert("pkg".to_string(), toml::encode(&pkg));
213-
let manifest = toml::Value::Table(manifest).to_string();
214-
206+
let manifest = self.build_manifest();
215207
let filename = format!("channel-rust-{}.toml", self.rust_release);
216-
self.write_manifest(&manifest, &filename);
208+
self.write_manifest(&toml::to_string(&manifest).unwrap(), &filename);
217209

218210
let filename = format!("channel-rust-{}-date.txt", self.rust_release);
219-
self.write_date_stamp(&date, &filename);
211+
self.write_date_stamp(&manifest.date, &filename);
220212

221213
if self.rust_release != "beta" && self.rust_release != "nightly" {
222-
self.write_manifest(&manifest, "channel-rust-stable.toml");
223-
self.write_date_stamp(&date, "channel-rust-stable-date.txt");
214+
self.write_manifest(&toml::to_string(&manifest).unwrap(), "channel-rust-stable.toml");
215+
self.write_date_stamp(&manifest.date, "channel-rust-stable-date.txt");
224216
}
225217
}
226218

0 commit comments

Comments
 (0)