Skip to content

Commit 6e930dd

Browse files
committed
Remove global variables from top-crates
1 parent 85bac78 commit 6e930dd

File tree

4 files changed

+21
-29
lines changed

4 files changed

+21
-29
lines changed

top-crates/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

top-crates/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ edition = "2018"
77
[dependencies]
88
cargo = "0.54.0"
99
itertools = "0.10.0"
10-
lazy_static = "1.0.0"
1110
reqwest = { version = "0.11.0", features = ["blocking"] }
1211
serde = "1.0.1"
1312
serde_derive = "1.0.1"

top-crates/src/lib.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ use cargo::{
1313
util::Config,
1414
};
1515
use itertools::Itertools;
16-
use lazy_static::lazy_static;
1716
use serde::{Deserialize, Serialize};
1817
use std::{
1918
collections::{BTreeMap, BTreeSet, HashSet},
20-
fs::File,
2119
io::Read,
2220
};
2321

@@ -52,12 +50,12 @@ pub struct CrateInformation {
5250
}
5351

5452
/// Hand-curated changes to the crate list
55-
#[derive(Debug, Deserialize)]
56-
struct Modifications {
53+
#[derive(Debug, Default, Deserialize)]
54+
pub struct Modifications {
5755
#[serde(default)]
58-
exclusions: Vec<String>,
56+
pub exclusions: Vec<String>,
5957
#[serde(default)]
60-
additions: BTreeSet<String>,
58+
pub additions: BTreeSet<String>,
6159
}
6260

6361
#[derive(Debug, Serialize, Clone)]
@@ -90,19 +88,6 @@ impl Modifications {
9088
}
9189
}
9290

93-
lazy_static! {
94-
static ref MODIFICATIONS: Modifications = {
95-
let mut f = File::open("crate-modifications.toml")
96-
.expect("unable to open crate modifications file");
97-
98-
let mut d = Vec::new();
99-
f.read_to_end(&mut d)
100-
.expect("unable to read crate modifications file");
101-
102-
toml::from_slice(&d).expect("unable to parse crate modifications file")
103-
};
104-
}
105-
10691
fn simple_get(url: &str) -> reqwest::Result<reqwest::blocking::Response> {
10792
reqwest::blocking::ClientBuilder::new()
10893
.user_agent("Rust Playground - Top Crates Utility")
@@ -148,9 +133,9 @@ impl TopCrates {
148133
}
149134

150135
/// Add crates that have been hand-picked
151-
fn add_curated_crates(&mut self) {
136+
fn add_curated_crates(&mut self, modifications: &Modifications) {
152137
self.crates.extend({
153-
MODIFICATIONS
138+
modifications
154139
.additions
155140
.iter()
156141
.cloned()
@@ -234,7 +219,7 @@ fn playground_metadata_features(pkg: &Package) -> Option<(Vec<String>, bool)> {
234219
}
235220
}
236221

237-
pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformation>) {
222+
pub fn generate_info(modifications: &Modifications) -> (BTreeMap<String, DependencySpec>, Vec<CrateInformation>) {
238223
// Setup to interact with cargo.
239224
let config = Config::default().expect("Unable to create default Cargo config");
240225
let _lock = config.acquire_package_cache_lock();
@@ -244,13 +229,13 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
244229

245230
let mut top = TopCrates::download();
246231
top.add_rust_cookbook_crates();
247-
top.add_curated_crates();
232+
top.add_curated_crates(modifications);
248233

249234
// Find the newest (non-prerelease, non-yanked) versions of all
250235
// the interesting crates.
251236
let mut summaries = Vec::new();
252237
for Crate { name } in &top.crates {
253-
if MODIFICATIONS.excluded(name) {
238+
if modifications.excluded(name) {
254239
continue;
255240
}
256241

@@ -326,7 +311,7 @@ pub fn generate_info() -> (BTreeMap<String, DependencySpec>, Vec<CrateInformatio
326311
let package_ids: Vec<_> = resolve
327312
.iter()
328313
.filter(|pkg| valid_for_our_platform.contains(pkg))
329-
.filter(|pkg| !MODIFICATIONS.excluded(pkg.name().as_str()))
314+
.filter(|pkg| !modifications.excluded(pkg.name().as_str()))
330315
.collect();
331316

332317
let mut sources = SourceMap::new();

top-crates/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use serde::Serialize;
55
use std::{
66
collections::BTreeMap,
77
fs::File,
8-
io::Write,
8+
io::{Read, Write},
99
path::{Path, PathBuf},
1010
};
1111

@@ -43,7 +43,16 @@ struct Profiles {
4343
}
4444

4545
fn main() {
46-
let (dependencies, infos) = rust_playground_top_crates::generate_info();
46+
let mut f = File::open("crate-modifications.toml")
47+
.expect("unable to open crate modifications file");
48+
49+
let mut d = Vec::new();
50+
f.read_to_end(&mut d)
51+
.expect("unable to read crate modifications file");
52+
53+
let modifications: Modifications = toml::from_slice(&d).expect("unable to parse crate modifications file");
54+
55+
let (dependencies, infos) = rust_playground_top_crates::generate_info(&modifications);
4756

4857
// Construct playground's Cargo.toml.
4958
let manifest = TomlManifest {

0 commit comments

Comments
 (0)