Skip to content

Commit 6f99f90

Browse files
authored
Merge pull request #818 from dtolnay-contrib/topfmt
2 parents 806ce3e + e80cef1 commit 6f99f90

File tree

4 files changed

+51
-21
lines changed

4 files changed

+51
-21
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,16 @@ jobs:
182182
~/.cargo/git
183183
ui/target
184184
key: "${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2"
185-
- name: Format
185+
- name: Format server
186186
uses: actions-rs/cargo@v1
187187
with:
188188
command: fmt
189-
args: "--manifest-path ui/Cargo.toml --all -- --check"
189+
args: "--manifest-path ui/Cargo.toml --all --check"
190+
- name: Format top-crates
191+
uses: actions-rs/cargo@v1
192+
with:
193+
command: fmt
194+
args: "--manifest-path top-crates/Cargo.toml --check"
190195
- name: Build backend
191196
run: |-
192197
mkdir -p ui/target; docker run --rm -v $PWD/ui:/ui -v ~/.cargo/git:/home/rust/.cargo/git -v ~/.cargo/registry:/home/rust/.cargo/registry --workdir /ui ekidd/rust-musl-builder:stable bash -c $'

ci/workflows.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,17 @@ workflows:
279279
ui/target
280280
key: ${{ runner.os }}-cargo-${{ hashFiles('ui/**/Cargo.lock') }}-2
281281

282-
- name: "Format"
282+
- name: "Format server"
283283
uses: actions-rs/cargo@v1
284284
with:
285285
command: fmt
286-
args: --manifest-path ui/Cargo.toml --all -- --check
286+
args: --manifest-path ui/Cargo.toml --all --check
287+
288+
- name: "Format top-crates"
289+
uses: actions-rs/cargo@v1
290+
with:
291+
command: fmt
292+
args: --manifest-path top-crates/Cargo.toml --check
287293

288294
- name: "Build backend"
289295
run: >-

top-crates/src/lib.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use itertools::Itertools;
1616
use serde::{Deserialize, Serialize};
1717
use std::{
1818
collections::{BTreeMap, BTreeSet, HashSet},
19-
io::Read, task::Poll,
19+
io::Read,
20+
task::Poll,
2021
};
2122

2223
const PLAYGROUND_TARGET_PLATFORM: &str = "x86_64-unknown-linux-gnu";
@@ -92,10 +93,13 @@ fn simple_get(url: &str) -> reqwest::Result<reqwest::blocking::Response> {
9293
impl TopCrates {
9394
/// List top 100 crates by number of downloads on crates.io.
9495
fn download() -> TopCrates {
95-
let resp =
96-
simple_get("https://crates.io/api/v1/crates?page=1&per_page=100&sort=downloads")
97-
.expect("Could not fetch top crates");
98-
assert!(resp.status().is_success(), "Could not download top crates; HTTP status was {}", resp.status());
96+
let resp = simple_get("https://crates.io/api/v1/crates?page=1&per_page=100&sort=downloads")
97+
.expect("Could not fetch top crates");
98+
assert!(
99+
resp.status().is_success(),
100+
"Could not download top crates; HTTP status was {}",
101+
resp.status(),
102+
);
99103

100104
serde_json::from_reader(resp).expect("Invalid JSON")
101105
}
@@ -105,7 +109,11 @@ impl TopCrates {
105109
"https://raw.githubusercontent.com/rust-lang-nursery/rust-cookbook/master/Cargo.toml",
106110
)
107111
.expect("Could not fetch cookbook manifest");
108-
assert!(resp.status().is_success(), "Could not download cookbook; HTTP status was {}", resp.status());
112+
assert!(
113+
resp.status().is_success(),
114+
"Could not download cookbook; HTTP status was {}",
115+
resp.status(),
116+
);
109117

110118
let mut content = String::new();
111119
resp.read_to_string(&mut content)
@@ -212,14 +220,19 @@ fn playground_metadata_features(pkg: &Package) -> Option<(Vec<String>, bool)> {
212220
}
213221
}
214222

215-
pub fn generate_info(modifications: &Modifications) -> (BTreeMap<String, DependencySpec>, Vec<CrateInformation>) {
223+
pub fn generate_info(
224+
modifications: &Modifications,
225+
) -> (BTreeMap<String, DependencySpec>, Vec<CrateInformation>) {
216226
// Setup to interact with cargo.
217227
let config = Config::default().expect("Unable to create default Cargo config");
218228
let _lock = config.acquire_package_cache_lock();
219229
let crates_io = SourceId::crates_io(&config).expect("Unable to create crates.io source ID");
220-
let mut source = RegistrySource::remote(crates_io, &HashSet::new(), &config).expect("Unable to create registry source");
230+
let mut source = RegistrySource::remote(crates_io, &HashSet::new(), &config)
231+
.expect("Unable to create registry source");
221232
source.invalidate_cache();
222-
source.block_until_ready().expect("Unable to wait for registry to be ready");
233+
source
234+
.block_until_ready()
235+
.expect("Unable to wait for registry to be ready");
223236

224237
let mut top = TopCrates::download();
225238
top.add_rust_cookbook_crates();
@@ -272,11 +285,15 @@ pub fn generate_info(modifications: &Modifications) -> (BTreeMap<String, Depende
272285
.expect("Unable to resolve dependencies");
273286

274287
// Find crates incompatible with the playground's platform
275-
let mut valid_for_our_platform: BTreeSet<_> = summaries.iter().map(|(s, _)| s.package_id()).collect();
288+
let mut valid_for_our_platform: BTreeSet<_> =
289+
summaries.iter().map(|(s, _)| s.package_id()).collect();
276290

277-
let ct = CompileTarget::new(PLAYGROUND_TARGET_PLATFORM).expect("Unable to create a CompileTarget");
291+
let ct =
292+
CompileTarget::new(PLAYGROUND_TARGET_PLATFORM).expect("Unable to create a CompileTarget");
278293
let ck = CompileKind::Target(ct);
279-
let rustc = config.load_global_rustc(None).expect("Unable to load the global rustc");
294+
let rustc = config
295+
.load_global_rustc(None)
296+
.expect("Unable to load the global rustc");
280297

281298
let ti = TargetInfo::new(&config, &[ck], &rustc, ck).expect("Unable to create a TargetInfo");
282299
let cc = ti.cfg();
@@ -288,9 +305,10 @@ pub fn generate_info(modifications: &Modifications) -> (BTreeMap<String, Depende
288305

289306
for package_id in to_visit {
290307
for (dep_pkg, deps) in resolve.deps(package_id) {
291-
292308
let for_this_platform = deps.iter().any(|dep| {
293-
dep.platform().map_or(true, |platform| platform.matches(PLAYGROUND_TARGET_PLATFORM, cc))
309+
dep.platform().map_or(true, |platform| {
310+
platform.matches(PLAYGROUND_TARGET_PLATFORM, cc)
311+
})
294312
});
295313

296314
if for_this_platform {

top-crates/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ struct Profiles {
4343
}
4444

4545
fn main() {
46-
let mut f = File::open("crate-modifications.toml")
47-
.expect("unable to open crate modifications file");
46+
let mut f =
47+
File::open("crate-modifications.toml").expect("unable to open crate modifications file");
4848

4949
let mut d = Vec::new();
5050
f.read_to_end(&mut d)
5151
.expect("unable to read crate modifications file");
5252

53-
let modifications: Modifications = toml::from_slice(&d).expect("unable to parse crate modifications file");
53+
let modifications: Modifications =
54+
toml::from_slice(&d).expect("unable to parse crate modifications file");
5455

5556
let (dependencies, infos) = rust_playground_top_crates::generate_info(&modifications);
5657

0 commit comments

Comments
 (0)